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.util.Comparator;
24
25 import javax.naming.NamingException;
26
27 import org.apache.directory.server.schema.DnComparator;
28 import org.apache.directory.server.schema.NameAndOptionalUIDComparator;
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.ByteArrayComparator;
33 import org.apache.directory.shared.ldap.schema.CachingNormalizer;
34 import org.apache.directory.shared.ldap.schema.ComparableComparator;
35 import org.apache.directory.shared.ldap.schema.DeepTrimNormalizer;
36 import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
37 import org.apache.directory.shared.ldap.schema.NormalizingComparator;
38 import org.apache.directory.shared.ldap.schema.ObjectIdentifierComparator;
39
40
41 /**
42 * Document this class.
43 *
44 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
45 * @version $Rev: 638228 $
46 */
47 public class SystemComparatorProducer extends AbstractBootstrapProducer
48 {
49 public SystemComparatorProducer()
50 {
51 super( ProducerTypeEnum.COMPARATOR_PRODUCER );
52 }
53
54
55 public static class DeepTrimToLowerCachingNormalizingComparator extends NormalizingComparator
56 {
57 public DeepTrimToLowerCachingNormalizingComparator()
58 {
59 super( new CachingNormalizer( new DeepTrimToLowerNormalizer() ), new ComparableComparator() );
60 }
61 }
62
63
64 public static class DeepTrimCachingNormalizingComparator extends NormalizingComparator
65 {
66 public DeepTrimCachingNormalizingComparator()
67 {
68 super( new CachingNormalizer( new DeepTrimNormalizer() ), new ComparableComparator() );
69 }
70 }
71
72 /**
73 * This caching NormalizingComparator would be a good thing to have,
74 * sadly we can't use it as the registries are not available here ...
75 *
76 * TODO Inject the AttributeType registry into the caching normalizer.
77 */
78 public static class NameAndOptionalUIDCachingNormalizingComparator extends NormalizingComparator
79 {
80 public NameAndOptionalUIDCachingNormalizingComparator()
81 {
82 super( new CachingNormalizer( new NameAndOptionalUIDNormalizer() ), new NameAndOptionalUIDComparator() );
83 }
84 }
85
86 public void produce( Registries registries, ProducerCallback cb ) throws NamingException
87 {
88 Comparator comparator;
89
90 /*
91 * Straight out of RFC 2252: Section 8
92 * =======================================
93 ( 2.5.13.0 NAME 'objectIdentifierMatch'
94 SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )
95 */
96 comparator = new ObjectIdentifierComparator();
97 cb.schemaObjectProduced( this, "2.5.13.0", comparator );
98
99 /*
100 ( 2.5.13.1 NAME 'distinguishedNameMatch'
101 SYNTAX 1.3.6.1.4.1.1466.115.121.1.12 )
102 */
103 comparator = new DnComparator( registries.getAttributeTypeRegistry() );
104 cb.schemaObjectProduced( this, "2.5.13.1", comparator );
105
106 /*
107 ( 2.5.13.2 NAME 'caseIgnoreMatch'
108 SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
109 */
110 comparator = new DeepTrimToLowerCachingNormalizingComparator();
111 cb.schemaObjectProduced( this, "2.5.13.2", comparator );
112
113 /*
114 ( 2.5.13.3 NAME 'caseIgnoreOrderingMatch'
115 SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
116 */
117 comparator = new DeepTrimToLowerCachingNormalizingComparator();
118 cb.schemaObjectProduced( this, "2.5.13.3", comparator );
119
120 /*
121 ( 2.5.13.4 NAME 'caseIgnoreSubstringsMatch'
122 SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )
123 */
124 comparator = new DeepTrimToLowerCachingNormalizingComparator();
125 cb.schemaObjectProduced( this, "2.5.13.4", comparator );
126
127 /*
128 ( 2.5.13.6 NAME 'caseExactOrderingMatch'
129 SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
130 */
131 comparator = new ComparableComparator();
132 cb.schemaObjectProduced( this, "2.5.13.6", comparator );
133
134 /*
135 ( 2.5.13.8 NAME 'numericStringMatch'
136 SYNTAX 1.3.6.1.4.1.1466.115.121.1.36 )
137 */
138 comparator = new ComparableComparator();
139 cb.schemaObjectProduced( this, "2.5.13.8", comparator );
140
141 /*
142 ( 2.5.13.10 NAME 'numericStringSubstringsMatch'
143 SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )
144 */
145 comparator = new ComparableComparator();
146 cb.schemaObjectProduced( this, "2.5.13.10", comparator );
147
148 /*
149 ( 2.5.13.11 NAME 'caseIgnoreListMatch'
150 SYNTAX 1.3.6.1.4.1.1466.115.121.1.41 )
151 */
152 comparator = new DeepTrimToLowerCachingNormalizingComparator();
153 cb.schemaObjectProduced( this, "2.5.13.11", comparator );
154
155 /*
156 ( 2.5.13.14 NAME 'integerMatch'
157 SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )
158 */
159 comparator = new ComparableComparator();
160 cb.schemaObjectProduced( this, "2.5.13.14", comparator );
161
162 /*
163 ( 2.5.13.14 NAME 'integerOrderingMatch'
164 SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )
165 */
166 comparator = new ComparableComparator();
167 cb.schemaObjectProduced( this, "2.5.13.15", comparator );
168
169 /*
170 ( 2.5.13.16 NAME 'bitStringMatch'
171 SYNTAX 1.3.6.1.4.1.1466.115.121.1.6 )
172 */
173 comparator = new ComparableComparator();
174 cb.schemaObjectProduced( this, "2.5.13.16", comparator );
175
176 /*
177 ( 2.5.13.17 NAME 'octetStringMatch'
178 SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
179 */
180 comparator = new ByteArrayComparator();
181 cb.schemaObjectProduced( this, "2.5.13.17", comparator );
182
183 /*
184 ( 2.5.13.18 NAME 'octetStringOrderingMatch'
185 SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
186 */
187 comparator = new ByteArrayComparator();
188 cb.schemaObjectProduced( this, "2.5.13.18", comparator );
189
190 /*
191 ( 2.5.13.20 NAME 'telephoneNumberMatch'
192 SYNTAX 1.3.6.1.4.1.1466.115.121.1.50 )
193 */
194 comparator = new ComparableComparator();
195 cb.schemaObjectProduced( this, "2.5.13.20", comparator );
196
197 /*
198 ( 2.5.13.21 NAME 'telephoneNumberSubstringsMatch'
199 SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )
200 */
201 comparator = new ComparableComparator();
202 cb.schemaObjectProduced( this, "2.5.13.21", comparator );
203
204 /*
205 ( 2.5.13.22 NAME 'presentationAddressMatch'
206 SYNTAX 1.3.6.1.4.1.1466.115.121.1.43 )
207 */
208 comparator = new ComparableComparator();
209 cb.schemaObjectProduced( this, "2.5.13.22", comparator );
210
211 /*
212 ( 2.5.13.23 NAME 'uniqueMemberMatch'
213 SYNTAX 1.3.6.1.4.1.1466.115.121.1.34 )
214 */
215 comparator = new NameAndOptionalUIDComparator();
216 cb.schemaObjectProduced( this, "2.5.13.23", comparator );
217
218 /*
219 ( 2.5.13.24 NAME 'protocolInformationMatch'
220 SYNTAX 1.3.6.1.4.1.1466.115.121.1.42 )
221 */
222 comparator = new ComparableComparator();
223 cb.schemaObjectProduced( this, "2.5.13.24", comparator );
224
225 /*
226 ( 2.5.13.27 NAME 'generalizedTimeMatch'
227 SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )
228 */
229 comparator = new ComparableComparator();
230 cb.schemaObjectProduced( this, "2.5.13.27", comparator );
231
232 /*
233 ( 2.5.13.28 NAME 'generalizedTimeOrderingMatch'
234 SYNTAX 1.3.6.1.4.1.1466.115.121.1.24 )
235 */
236 comparator = new ComparableComparator();
237 cb.schemaObjectProduced( this, "2.5.13.28", comparator );
238
239 /*
240 ( 2.5.13.29 NAME 'integerFirstComponentMatch'
241 SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 )
242 */
243 comparator = new ComparableComparator();
244 cb.schemaObjectProduced( this, "2.5.13.29", comparator );
245
246 /*
247 ( 2.5.13.30 NAME 'objectIdentifierFirstComponentMatch'
248 SYNTAX 1.3.6.1.4.1.1466.115.121.1.38 )
249 */
250 comparator = new ComparableComparator();
251 cb.schemaObjectProduced( this, "2.5.13.30", comparator );
252
253 /*
254 * Straight out of RFC 3698: Section 2.6
255 * http://www.faqs.org/rfcs/rfc3698.html
256 * =======================================
257 * ( 2.5.13.31 NAME 'directoryStringFirstComponentMatch'
258 * SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
259 */
260 comparator = new ComparableComparator();
261 cb.schemaObjectProduced( this, "2.5.13.31", comparator );
262
263 /*
264 ( 1.3.6.1.4.1.1466.109.114.1 NAME 'caseExactIA5Match'
265 SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
266 */
267 comparator = new DeepTrimCachingNormalizingComparator();
268 cb.schemaObjectProduced( this, "1.3.6.1.4.1.1466.109.114.1", comparator );
269
270 /*
271 ( 1.3.6.1.4.1.1466.109.114.2 NAME 'caseIgnoreIA5Match'
272 SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 )
273 */
274 comparator = new DeepTrimToLowerCachingNormalizingComparator();
275 cb.schemaObjectProduced( this, "1.3.6.1.4.1.1466.109.114.2", comparator );
276
277 /*
278 * MatchingRules from section 2 of http://www.faqs.org/rfcs/rfc3698.html
279 * for Additional MatchingRules
280
281 ( 2.5.13.13 NAME 'booleanMatch'
282 SYNTAX 1.3.6.1.4.1.1466.115.121.1.7 )
283
284 */
285
286 comparator = new ComparableComparator();
287 cb.schemaObjectProduced( this, "2.5.13.13", comparator );
288
289 /*
290 * Straight out of RFC 2798 for InetOrgPerson: Section 9.3.3
291 * =========================================================
292
293 ( 2.5.13.5 NAME 'caseExactMatch'
294 SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 )
295
296 ( 2.5.13.7 NAME 'caseExactSubstringsMatch'
297 SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )
298
299 ( 2.5.13.12 NAME 'caseIgnoreListSubstringsMatch'
300 SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )
301
302 */
303
304 comparator = new DeepTrimCachingNormalizingComparator();
305 cb.schemaObjectProduced( this, "2.5.13.5", comparator );
306
307 comparator = new DeepTrimCachingNormalizingComparator();
308 cb.schemaObjectProduced( this, "2.5.13.7", comparator );
309
310 comparator = new DeepTrimToLowerCachingNormalizingComparator();
311 cb.schemaObjectProduced( this, "2.5.13.12", comparator );
312
313 /*
314 * Straight out of RFC 2798 for InetOrgPerson: Section 9.3.4
315 * =========================================================
316
317 ( 1.3.6.1.4.1.1466.109.114.3 NAME 'caseIgnoreIA5SubstringsMatch'
318 SYNTAX 1.3.6.1.4.1.1466.115.121.1.58 )
319 */
320
321 comparator = new DeepTrimToLowerCachingNormalizingComparator();
322 cb.schemaObjectProduced( this, "1.3.6.1.4.1.1466.109.114.3", comparator );
323 }
324 }