001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one
003     *  or more contributor license agreements.  See the NOTICE file
004     *  distributed with this work for additional information
005     *  regarding copyright ownership.  The ASF licenses this file
006     *  to you under the Apache License, Version 2.0 (the
007     *  "License"); you may not use this file except in compliance
008     *  with the License.  You may obtain a copy of the License at
009     *  
010     *    http://www.apache.org/licenses/LICENSE-2.0
011     *  
012     *  Unless required by applicable law or agreed to in writing,
013     *  software distributed under the License is distributed on an
014     *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     *  KIND, either express or implied.  See the License for the
016     *  specific language governing permissions and limitations
017     *  under the License. 
018     *  
019     */
020    package org.apache.directory.server.schema.bootstrap;
021    
022    
023    import java.util.Comparator;
024    
025    import javax.naming.NamingException;
026    
027    import jdbm.helper.StringComparator;
028    
029    import org.apache.commons.collections.comparators.ComparableComparator;
030    import org.apache.directory.server.constants.MetaSchemaConstants;
031    import org.apache.directory.server.schema.registries.Registries;
032    import org.apache.directory.server.schema.registries.SyntaxRegistry;
033    import org.apache.directory.shared.ldap.NotImplementedException;
034    import org.apache.directory.shared.ldap.constants.SchemaConstants;
035    import org.apache.directory.shared.ldap.schema.MatchingRule;
036    import org.apache.directory.shared.ldap.schema.Normalizer;
037    import org.apache.directory.shared.ldap.schema.Syntax;
038    import org.apache.directory.shared.ldap.schema.comparators.ObjectIdentifierComparator;
039    import org.apache.directory.shared.ldap.schema.normalizers.DeepTrimToLowerNormalizer;
040    import org.apache.directory.shared.ldap.schema.normalizers.NoOpNormalizer;
041    import org.apache.directory.shared.ldap.schema.normalizers.ObjectIdentifierNormalizer;
042    
043    
044    /**
045     * A producer of MatchingRule objects for the apachemeta schema.
046     * Modified by hand from generated code
047     *
048     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
049     * @version $Rev$
050     */
051    public class ApachemetaMatchingRuleProducer extends AbstractBootstrapProducer
052    {
053        
054        
055        public ApachemetaMatchingRuleProducer()
056        {
057            super( ProducerTypeEnum.MATCHING_RULE_PRODUCER );
058        }
059    
060    
061        // ------------------------------------------------------------------------
062        // BootstrapProducer Methods
063        // ------------------------------------------------------------------------
064    
065    
066        /**
067         * @see BootstrapProducer#produce(Registries, ProducerCallback)
068         */
069        public void produce( Registries registries, ProducerCallback cb )
070            throws NamingException
071        {
072            MatchingRule matchingRule = null;
073            
074            matchingRule = new NameOrNumericIdMatch( registries.getOidRegistry(), MetaSchemaConstants.SCHEMA_NAME );
075            cb.schemaObjectProduced( this, matchingRule.getOid(), matchingRule );
076            
077            matchingRule = new ObjectClassTypeMatch();
078            cb.schemaObjectProduced( this, matchingRule.getOid(), matchingRule );
079            
080            matchingRule = new NumericOidMatch( registries.getSyntaxRegistry() );
081            cb.schemaObjectProduced( this, matchingRule.getOid(), matchingRule );
082            
083            matchingRule = new SupDITStructureRuleMatch( registries.getSyntaxRegistry() );
084            cb.schemaObjectProduced( this, matchingRule.getOid(), matchingRule );
085            
086            matchingRule = new RuleIdMatch( registries.getSyntaxRegistry() );
087            cb.schemaObjectProduced( this, matchingRule.getOid(), matchingRule );
088        }
089        
090        
091        public static class RuleIdMatch implements MatchingRule
092        {
093            private static final long serialVersionUID = 1L;
094            private static final String OID = "1.3.6.1.4.1.18060.0.4.0.1.4";
095            private final Syntax syntax;
096            private final String[] NAMES = new String[] { "ruleIdMatch" };
097            
098            
099            RuleIdMatch( SyntaxRegistry registry ) throws NamingException
100            {
101                syntax = registry.lookup( SchemaConstants.IA5_STRING_SYNTAX );
102            }
103            
104            public Comparator getComparator() throws NamingException
105            {
106                return new ComparableComparator();
107            }
108            
109            public Normalizer getNormalizer() throws NamingException
110            {
111                return new DeepTrimToLowerNormalizer();
112            }
113    
114            public Syntax getSyntax() throws NamingException
115            {
116                return syntax;
117            }
118    
119            public String getDescription()
120            {
121                return "Rule identifier of this DIT structure rule";
122            }
123    
124            public String getName()
125            {
126                return NAMES[0];
127            }
128    
129            public String[] getNamesRef()
130            {
131                return NAMES;
132            }
133    
134            public String getOid()
135            {
136                return OID;
137            }
138    
139            public boolean isObsolete()
140            {
141                return false;
142            }
143    
144            public String getSchema()
145            {
146                return MetaSchemaConstants.SCHEMA_NAME;
147            }
148    
149            public void setSchema( String schemaName )
150            {
151                throw new NotImplementedException();
152            }
153        }
154        
155        
156        public static class SupDITStructureRuleMatch implements MatchingRule
157        {
158            private static final String OID = "1.3.6.1.4.1.18060.0.4.0.1.3";
159            private static final long serialVersionUID = 1L;
160            String[] NAMES = new String[] { "supDITStructureRuleMatch" };
161            Syntax syntax;
162            
163            
164            public SupDITStructureRuleMatch( SyntaxRegistry registry ) throws NamingException
165            {
166                this.syntax = registry.lookup( SchemaConstants.DIT_STRUCTURE_RULE_SYNTAX );
167            }
168            
169            
170            public Comparator getComparator() throws NamingException
171            {
172                return new StringComparator();
173            }
174    
175            public Normalizer getNormalizer() throws NamingException
176            {
177                return new DeepTrimToLowerNormalizer();
178            }
179    
180            public Syntax getSyntax() throws NamingException
181            {
182                return syntax;
183            }
184    
185            public String getDescription()
186            {
187                return "A matching rule matching dit structure rule attributes";
188            }
189    
190            public String getName()
191            {
192                return NAMES[0];
193            }
194    
195            public String[] getNamesRef()
196            {
197                return NAMES;
198            }
199    
200            public String getOid()
201            {
202                return OID;
203            }
204    
205            public boolean isObsolete()
206            {
207                return false;
208            }
209    
210            public String getSchema()
211            {
212                return MetaSchemaConstants.SCHEMA_NAME;
213            }
214    
215            public void setSchema( String schemaName )
216            {
217                throw new NotImplementedException();
218            }
219        }
220        
221        
222        public static class NumericOidMatch implements MatchingRule
223        {
224            private static final String OID = "1.3.6.1.4.1.18060.0.4.0.1.2";
225    
226            private static final long serialVersionUID = 1L;
227    
228            final String[] NAMES = new String[] { "numericOidMatch" };
229            Syntax syntax;
230            
231            public NumericOidMatch( SyntaxRegistry registry ) throws NamingException
232            {
233                this.syntax = registry.lookup( SchemaConstants.OID_SYNTAX );
234            }
235            
236            public Comparator getComparator() throws NamingException
237            {
238                return new ObjectIdentifierComparator();
239            }
240    
241            public Normalizer getNormalizer() throws NamingException
242            {
243                return new ObjectIdentifierNormalizer();
244            }
245    
246            public Syntax getSyntax() throws NamingException
247            {
248                return syntax;
249            }
250    
251            public String getDescription()
252            {
253                return "a matching rule for numeric oids";
254            }
255    
256            public String getName()
257            {
258                return NAMES[0];
259            }
260    
261            public String[] getNamesRef()
262            {
263                return NAMES;
264            }
265    
266            public String getOid()
267            {
268                return OID;
269            }
270    
271            public boolean isObsolete()
272            {
273                return false;
274            }
275    
276            public String getSchema()
277            {
278                return MetaSchemaConstants.SCHEMA_NAME;
279            }
280    
281            public void setSchema( String schemaName )
282            {
283                throw new NotImplementedException();
284            }
285        }
286    
287        
288        public static class ObjectClassTypeMatch implements MatchingRule
289        {
290            private static final long serialVersionUID = 1L;
291            public static final Comparator COMPARATOR = new ApachemetaComparatorProducer.ObjectClassTypeComparator(); 
292            public static final Normalizer NORMALIZER = new NoOpNormalizer();
293            public static final Syntax SYNTAX = new ApachemetaSyntaxProducer.ObjectClassTypeSyntax();
294            public static final String OID = "1.3.6.1.4.1.18060.0.4.0.1.1";
295            
296            private static final String[] NAMES = new String[] { "objectClassTypeMatch" };
297            
298            public Comparator getComparator() throws NamingException
299            {
300                return COMPARATOR;
301            }
302    
303            
304            public Normalizer getNormalizer() throws NamingException
305            {
306                return NORMALIZER;
307            }
308    
309            public Syntax getSyntax() throws NamingException
310            {
311                return SYNTAX;
312            }
313    
314            public String getDescription()
315            {
316                return "objectClassTypeMatch: for mathing AUXILIARY, STRUCTURAL, ABSTRACT";
317            }
318    
319            public String getName()
320            {
321                return NAMES[0];
322            }
323    
324            public String[] getNamesRef()
325            {
326                return NAMES;
327            }
328    
329            public String getOid()
330            {
331                return OID;
332            }
333    
334            public boolean isObsolete()
335            {
336                return false;
337            }
338    
339            public String getSchema()
340            {
341                return MetaSchemaConstants.SCHEMA_NAME;
342            }
343    
344            public void setSchema( String schemaName )
345            {
346                throw new NotImplementedException();
347            }
348        }
349    }