1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.api.ldap.model.schema.parsers;
21
22
23 import java.util.List;
24
25 import org.apache.directory.api.ldap.model.schema.AttributeType;
26 import org.apache.directory.api.ldap.model.schema.LdapSyntax;
27 import org.apache.directory.api.ldap.model.schema.MatchingRule;
28 import org.apache.directory.api.ldap.model.schema.ObjectClass;
29 import org.apache.directory.api.ldap.model.schema.SchemaObject;
30
31
32
33
34
35
36
37 public final class ParserDescriptionUtils
38 {
39
40
41
42 private ParserDescriptionUtils()
43 {
44 }
45
46
47
48
49
50
51
52
53
54 public static boolean objectClassesMatch( ObjectClass oc0, ObjectClass oc1 )
55 {
56
57 if ( !descriptionsMatch( oc0, oc1 ) )
58 {
59 return false;
60 }
61
62
63 if ( oc0.getType() != oc1.getType() )
64 {
65 return false;
66 }
67
68
69 if ( oc0.getSuperiorOids().size() != oc1.getSuperiorOids().size() )
70 {
71 return false;
72 }
73
74
75 for ( int i = 0; i < oc0.getSuperiorOids().size(); i++ )
76 {
77 if ( !oc0.getSuperiorOids().get( i ).equals( oc1.getSuperiorOids().get( i ) ) )
78 {
79 return false;
80 }
81 }
82
83
84 for ( int i = 0; i < oc0.getMustAttributeTypeOids().size(); i++ )
85 {
86 if ( !oc0.getMustAttributeTypeOids().get( i ).equals( oc1.getMustAttributeTypeOids().get( i ) ) )
87 {
88 return false;
89 }
90 }
91
92
93 for ( int i = 0; i < oc0.getMayAttributeTypeOids().size(); i++ )
94 {
95 if ( !oc0.getMayAttributeTypeOids().get( i ).equals( oc1.getMayAttributeTypeOids().get( i ) ) )
96 {
97 return false;
98 }
99 }
100
101 return true;
102 }
103
104
105
106
107
108
109
110
111
112 public static boolean attributeTypesMatch( AttributeType at0, AttributeType at1 )
113 {
114
115 if ( !descriptionsMatch( at0, at1 ) )
116 {
117 return false;
118 }
119
120
121 if ( !at0.getSuperiorOid().equals( at1.getSuperiorOid() ) )
122 {
123 return false;
124 }
125
126
127 if ( !at0.getEqualityOid().equals( at1.getEqualityOid() ) )
128 {
129 return false;
130 }
131
132
133 if ( !at0.getSubstringOid().equals( at1.getSubstringOid() ) )
134 {
135 return false;
136 }
137
138
139 if ( !at0.getOrderingOid().equals( at1.getOrderingOid() ) )
140 {
141 return false;
142 }
143
144
145 if ( !at0.getSyntaxOid().equals( at1.getSyntaxOid() ) )
146 {
147 return false;
148 }
149
150
151 if ( at0.getSyntaxLength() != at1.getSyntaxLength() )
152 {
153 return false;
154 }
155
156
157 if ( at0.isSingleValued() != at1.isSingleValued() )
158 {
159 return false;
160 }
161
162
163 if ( at0.isCollective() != at1.isCollective() )
164 {
165 return false;
166 }
167
168
169 if ( at0.isUserModifiable() != at1.isUserModifiable() )
170 {
171 return false;
172 }
173
174
175 if ( at0.getUsage() != at1.getUsage() )
176 {
177 return false;
178 }
179
180 return true;
181 }
182
183
184
185
186
187
188
189
190
191 public static boolean matchingRulesMatch( MatchingRule matchingRule0, MatchingRule matchingRule1 )
192 {
193
194 if ( !descriptionsMatch( matchingRule0, matchingRule1 ) )
195 {
196 return false;
197 }
198
199
200 if ( !matchingRule0.getSyntaxOid().equals( matchingRule1.getSyntaxOid() ) )
201 {
202 return false;
203 }
204
205 return true;
206 }
207
208
209
210
211
212
213
214
215
216 public static boolean syntaxesMatch( LdapSyntax ldapSyntax0, LdapSyntax ldapSyntax1 )
217 {
218 return descriptionsMatch( ldapSyntax0, ldapSyntax1 );
219 }
220
221
222
223
224
225
226
227
228
229
230
231
232 public static boolean descriptionsMatch( SchemaObject so0, SchemaObject so1 )
233 {
234
235 if ( !so0.getOid().equals( so1.getOid() ) )
236 {
237 return false;
238 }
239
240
241 if ( ( ( so0 instanceof LdapSyntax ) || ( so1 instanceof LdapSyntax ) ) && so0.isObsolete() != so1.isObsolete() )
242 {
243 return false;
244 }
245
246
247 if ( !so0.getDescription().equals( so1.getDescription() ) )
248 {
249 return false;
250 }
251
252
253 if ( !aliasNamesMatch( so0, so1 ) )
254 {
255 return false;
256 }
257
258
259 if ( !extensionsMatch( so0, so1 ) )
260 {
261 return false;
262 }
263
264 return true;
265 }
266
267
268
269
270
271
272
273
274
275
276
277 public static boolean extensionsMatch( SchemaObject lsd0, SchemaObject lsd1 )
278 {
279
280 if ( lsd0.getExtensions().size() != lsd1.getExtensions().size() )
281 {
282 return false;
283 }
284
285
286 for ( String key : lsd0.getExtensions().keySet() )
287 {
288 List<String> values0 = lsd0.getExtensions().get( key );
289 List<String> values1 = lsd1.getExtensions().get( key );
290
291
292 if ( values1 == null )
293 {
294 return false;
295 }
296
297 for ( int i = 0; i < values0.size(); i++ )
298 {
299 if ( !values0.get( i ).equals( values1.get( i ) ) )
300 {
301 return false;
302 }
303 }
304 }
305
306 return true;
307 }
308
309
310
311
312
313
314
315
316
317
318 public static boolean aliasNamesMatch( SchemaObject so0, SchemaObject so1 )
319 {
320
321 if ( so0.getNames().size() != so1.getNames().size() )
322 {
323 return false;
324 }
325
326
327 for ( int i = 0; i < so0.getNames().size(); i++ )
328 {
329 if ( !so0.getNames().get( i ).equals( so1.getNames().get( i ) ) )
330 {
331 return false;
332 }
333 }
334
335 return true;
336 }
337 }