View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.schema.bootstrap;
21  
22  
23  import java.lang.reflect.InvocationTargetException;
24  import java.lang.reflect.Method;
25  
26  import javax.naming.NamingException;
27  
28  import org.apache.directory.server.schema.DnNormalizer;
29  import org.apache.directory.server.schema.NameAndOptionalUIDNormalizer;
30  import org.apache.directory.server.schema.bootstrap.ProducerTypeEnum;
31  import org.apache.directory.server.schema.registries.Registries;
32  import org.apache.directory.shared.ldap.schema.CachingNormalizer;
33  import org.apache.directory.shared.ldap.schema.DeepTrimNormalizer;
34  import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
35  import org.apache.directory.shared.ldap.schema.NoOpNormalizer;
36  import org.apache.directory.shared.ldap.schema.Normalizer;
37  import org.apache.directory.shared.ldap.schema.ObjectIdentifierNormalizer;
38  
39  
40  /**
41   * A bootstrap producer which creates and announces newly created Normalizers
42   * for various matchingRules in the core schema.
43   *
44   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
45   * @version $Rev: 569436 $
46   */
47  public class SystemNormalizerProducer extends AbstractBootstrapProducer
48  {
49      public SystemNormalizerProducer()
50      {
51          super( ProducerTypeEnum.NORMALIZER_PRODUCER );
52      }
53  
54      
55      public static class CachingDeepTrimToLowerNormalizer extends CachingNormalizer
56      {
57          private static final long serialVersionUID = 1L;
58  
59          public CachingDeepTrimToLowerNormalizer()
60          {
61              super( new DeepTrimToLowerNormalizer() );
62          }
63      }
64      
65      
66      public static class CachingDeepTrimNormalizer extends CachingNormalizer
67      {
68          private static final long serialVersionUID = 1L;
69  
70          public CachingDeepTrimNormalizer()
71          {
72              super( new DeepTrimNormalizer() );
73          }
74      }
75      
76      
77      public static class CachingDnNormalizer extends CachingNormalizer
78      {
79          private static final long serialVersionUID = 1L;
80  
81          /** Used for looking up the setRegistries(Registries) method */
82          private final static Class[] parameterTypes = new Class[] { Registries.class };
83  
84          
85          public CachingDnNormalizer()
86          {
87              super( new DnNormalizer() );
88          }
89  
90          
91          public void setRegistries( Registries registries ) throws NamingException
92          {
93              injectRegistries( super.normalizer, registries );
94          }
95          
96          
97          private void injectRegistries( Object obj, Registries registries ) throws NamingException
98          {
99              String className = obj.getClass().getName();
100             
101             try
102             {
103                 Method method = obj.getClass().getMethod( "setRegistries", parameterTypes );
104                 
105                 if ( method == null )
106                 {
107                     return;
108                 }
109                 
110                 Object[] args = new Object[] { registries };
111                 method.invoke( obj, args );
112             }
113             catch ( SecurityException e )
114             {
115                 NamingException ne = new NamingException( "SyntaxChecker class "+ className 
116                     + " could not have the Registries dependency injected." );
117                 ne.setRootCause( e );
118                 throw ne;
119             }
120             catch ( NoSuchMethodException e )
121             {
122                 // this is ok since not every object may have setRegistries()
123             }
124             catch ( IllegalArgumentException e )
125             {
126                 NamingException ne = new NamingException( "SyntaxChecker class "+ className 
127                     + " could not have the Registries dependency injected." );
128                 ne.setRootCause( e );
129                 throw ne;
130             }
131             catch ( IllegalAccessException e )
132             {
133                 NamingException ne = new NamingException( "SyntaxChecker class "+ className 
134                     + " could not have the Registries dependency injected." );
135                 ne.setRootCause( e );
136                 throw ne;
137             }
138             catch ( InvocationTargetException e )
139             {
140                 NamingException ne = new NamingException( "SyntaxChecker class "+ className 
141                     + " could not have the Registries dependency injected." );
142                 ne.setRootCause( e );
143                 throw ne;
144             }
145         }
146     }
147     
148 
149     public void produce( Registries registries, ProducerCallback cb ) throws NamingException
150     {
151         Normalizer normalizer;
152 
153         /*
154          * Straight out of RFC 2252: Section 8
155          * =======================================
156 
157          ( 2.5.13.1 NAME 'distinguishedNameMatch'
158          SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )
159          */
160         normalizer = new CachingDnNormalizer();
161         ( ( CachingDnNormalizer ) normalizer ).setRegistries( registries );
162         cb.schemaObjectProduced( this, "2.5.13.1", normalizer );
163 
164         /*
165          ( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match'
166          SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
167          */
168         normalizer = new CachingDeepTrimToLowerNormalizer();
169         cb.schemaObjectProduced( this, "1.3.6.1.4.1.1466.109.114.2", normalizer );
170 
171         /*
172          ( 2.5.13.11 NAME 'caseIgnoreListMatch'
173          SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )
174          */
175         normalizer = new CachingDeepTrimToLowerNormalizer();
176         cb.schemaObjectProduced( this, "2.5.13.11", normalizer );
177 
178         /*
179          ( 2.5.13.2 NAME 'caseIgnoreMatch'
180          SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
181          */
182         normalizer = new CachingDeepTrimToLowerNormalizer();
183         cb.schemaObjectProduced( this, "2.5.13.2", normalizer );
184 
185         /*
186          ( 2.5.13.3 NAME 'caseIgnoreOrderingMatch'
187          SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
188          */
189         normalizer = new CachingDeepTrimToLowerNormalizer();
190         cb.schemaObjectProduced( this, "2.5.13.3", normalizer );
191 
192         /*
193          ( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch'
194          SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )
195          */
196         normalizer = new CachingDeepTrimToLowerNormalizer();
197         cb.schemaObjectProduced( this, "2.5.13.4", normalizer );
198 
199         /*
200          ( 2.5.13.6 NAME 'caseExactOrderingMatch'
201          SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
202          */
203         normalizer = new NoOpNormalizer();
204         cb.schemaObjectProduced( this, "2.5.13.6", normalizer );
205 
206         /*
207          ( 2.5.13.0 NAME 'objectIdentifierMatch'
208          SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )
209          */
210         normalizer = new ObjectIdentifierNormalizer();
211         cb.schemaObjectProduced( this, "2.5.13.0", normalizer );
212 
213         /*
214          ( 2.5.13.8 NAME 'numericStringMatch'
215          SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )
216          */
217         normalizer = new NoOpNormalizer();
218         cb.schemaObjectProduced( this, "2.5.13.8", normalizer );
219 
220         /*
221          ( 2.5.13.10 NAME 'numericStringSubstringsMatch'
222          SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )
223          */
224         normalizer = new NoOpNormalizer();
225         cb.schemaObjectProduced( this, "2.5.13.10", normalizer );
226 
227         /*
228          ( 2.5.13.14 NAME 'integerMatch'
229          SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )
230          */
231         normalizer = new NoOpNormalizer();
232         cb.schemaObjectProduced( this, "2.5.13.14", normalizer );
233 
234         /*
235          ( 2.5.13.14 NAME 'integerOrderingMatch'
236          SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )
237          */
238         normalizer = new NoOpNormalizer();
239         cb.schemaObjectProduced( this, "2.5.13.15", normalizer );
240 
241         /*
242          ( 2.5.13.16 NAME 'bitStringMatch'
243          SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )
244          */
245         normalizer = new NoOpNormalizer();
246         cb.schemaObjectProduced( this, "2.5.13.16", normalizer );
247 
248         /*
249          ( 2.5.13.17 NAME 'octetStringMatch'
250          SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
251          */
252         normalizer = new NoOpNormalizer();
253         cb.schemaObjectProduced( this, "2.5.13.17", normalizer );
254 
255         /*
256          ( 2.5.13.18 NAME 'octetStringOrderingMatch'
257          SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
258          */
259         normalizer = new NoOpNormalizer();
260         cb.schemaObjectProduced( this, "2.5.13.18", normalizer );
261 
262         /*
263          ( 2.5.13.20 NAME 'telephoneNumberMatch'
264          SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )
265          */
266         normalizer = new NoOpNormalizer();
267         cb.schemaObjectProduced( this, "2.5.13.20", normalizer );
268 
269         /*
270          ( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch'
271          SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )
272          */
273         normalizer = new NoOpNormalizer();
274         cb.schemaObjectProduced( this, "2.5.13.21", normalizer );
275 
276         /*
277          ( 2.5.13.22 NAME 'presentationAddressMatch'
278          SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )
279          */
280         normalizer = new NoOpNormalizer();
281         cb.schemaObjectProduced( this, "2.5.13.22", normalizer );
282 
283         /*
284          ( 2.5.13.23 NAME 'uniqueMemberMatch'
285          SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )
286          */
287         normalizer = new NameAndOptionalUIDNormalizer();
288         cb.schemaObjectProduced( this, "2.5.13.23", normalizer );
289 
290         /*
291          ( 2.5.13.24 NAME 'protocolInformationMatch'
292          SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )
293          */
294         normalizer = new CachingDeepTrimNormalizer();
295         cb.schemaObjectProduced( this, "2.5.13.24", normalizer );
296 
297         /*
298          ( 2.5.13.27 NAME 'generalizedTimeMatch'
299          SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )
300          */
301         normalizer = new CachingDeepTrimNormalizer();
302         cb.schemaObjectProduced( this, "2.5.13.27", normalizer );
303 
304         /*
305          ( 2.5.13.28 NAME 'generalizedTimeOrderingMatch'
306          SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )
307          */
308         normalizer = new CachingDeepTrimNormalizer();
309         cb.schemaObjectProduced( this, "2.5.13.28", normalizer );
310 
311         /*
312          ( 2.5.13.29 NAME 'integerFirstComponentMatch'
313          SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )
314          */
315         normalizer = new NoOpNormalizer();
316         cb.schemaObjectProduced( this, "2.5.13.29", normalizer );
317 
318         /*
319          ( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch'
320          SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )
321          */
322         normalizer = new NoOpNormalizer();
323         cb.schemaObjectProduced( this, "2.5.13.30", normalizer );
324 
325         /*
326          * Straight out of RFC 3698: Section 2.6
327          * http://www.faqs.org/rfcs/rfc3698.html
328          * =======================================
329          * ( 2.5.13.31 NAME 'directoryStringFirstComponentMatch'
330          *   SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
331          */
332         normalizer = new NoOpNormalizer();
333         cb.schemaObjectProduced( this, "2.5.13.31", normalizer );
334 
335         /*
336          ( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match'
337          SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
338          */
339         normalizer = new CachingDeepTrimNormalizer();
340         cb.schemaObjectProduced( this, "1.3.6.1.4.1.1466.109.114.1", normalizer );
341 
342         /*
343          * MatchingRules from section 2 of http://www.faqs.org/rfcs/rfc3698.html
344          * for Additional MatchingRules
345 
346          ( 2.5.13.13 NAME 'booleanMatch'
347          SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )
348 
349          */
350 
351         normalizer = new NoOpNormalizer();
352         cb.schemaObjectProduced( this, "2.5.13.13", normalizer );
353 
354         /*
355          * Straight out of RFC 2798 for InetOrgPerson: Section 9.3.3
356          * =========================================================
357 
358          ( 2.5.13.5 NAME 'caseExactMatch'
359          SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
360 
361          ( 2.5.13.7 NAME 'caseExactSubstringsMatch'
362          SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )
363 
364          ( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch'
365          SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )
366          */
367 
368         normalizer = new CachingDeepTrimNormalizer();
369         cb.schemaObjectProduced( this, "2.5.13.5", normalizer );
370 
371         normalizer = new CachingDeepTrimNormalizer();
372         cb.schemaObjectProduced( this, "2.5.13.7", normalizer );
373 
374         normalizer = new CachingDeepTrimToLowerNormalizer();
375         cb.schemaObjectProduced( this, "2.5.13.12", normalizer );
376 
377         /*
378          * Straight out of RFC 2798 for InetOrgPerson: Section 9.3.4
379          * =========================================================
380 
381          ( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch'
382          SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )
383          */
384 
385         normalizer = new CachingDeepTrimToLowerNormalizer();
386         cb.schemaObjectProduced( this, "1.3.6.1.4.1.1466.109.114.3", normalizer );
387     }
388 }