KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > model > schema > AttributeTypeDescription


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
21 package org.apache.directory.ldapstudio.browser.core.model.schema;
22
23
24 import java.util.Arrays JavaDoc;
25 import java.util.HashSet JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.Set JavaDoc;
28
29 import org.apache.directory.ldapstudio.browser.core.BrowserCorePlugin;
30
31
32 public class AttributeTypeDescription extends SchemaPart2
33 {
34
35     private static final long serialVersionUID = 8023296692770420698L;
36
37     public static final String JavaDoc ATTRIBUTE_USAGE_USER_APPLICATIONS = "userApplications";
38
39     public static final String JavaDoc ATTRIBUTE_USAGE_DISTRIBUTED_OPERATION = "distributedOperation";
40
41     public static final String JavaDoc ATTRIBUTE_USAGE_DIRECTORY_OPERATION = "directoryOperation";
42
43     public static final String JavaDoc ATTRIBUTE_USAGE_DSA_OPERATION = "dSAOperation";
44
45     private String JavaDoc superiorAttributeTypeDescriptionName;
46
47     private String JavaDoc equalityMatchingRuleDescriptionOID;
48
49     private String JavaDoc orderingMatchingRuleDescriptionOID;
50
51     private String JavaDoc substringMatchingRuleDescriptionOID;
52
53     private String JavaDoc syntaxDescriptionNumericOIDPlusLength;
54
55     private boolean isSingleValued;
56
57     private boolean isCollective;
58
59     private boolean isNoUserModification;
60
61     private String JavaDoc usage;
62
63
64     public AttributeTypeDescription()
65     {
66         super();
67         this.superiorAttributeTypeDescriptionName = null;
68         this.equalityMatchingRuleDescriptionOID = null;
69         this.orderingMatchingRuleDescriptionOID = null;
70         this.substringMatchingRuleDescriptionOID = null;
71         this.syntaxDescriptionNumericOIDPlusLength = null;
72         this.isSingleValued = false;
73         this.isCollective = false;
74         this.isNoUserModification = false;
75         this.usage = ATTRIBUTE_USAGE_USER_APPLICATIONS;
76     }
77
78
79     public int compareTo( Object JavaDoc o )
80     {
81         if ( o instanceof AttributeTypeDescription )
82         {
83             return this.toString().compareTo( o.toString() );
84         }
85         else
86         {
87             throw new ClassCastException JavaDoc( "Object of type " + this.getClass().getName() + " required." );
88         }
89     }
90
91
92     /**
93      *
94      * @return the equality matching rule OID, may be null
95      */

96     public String JavaDoc getEqualityMatchingRuleDescriptionOID()
97     {
98         return equalityMatchingRuleDescriptionOID;
99     }
100
101
102     public void setEqualityMatchingRuleDescriptionOID( String JavaDoc equalityMatchingRuleDescriptionOID )
103     {
104         this.equalityMatchingRuleDescriptionOID = equalityMatchingRuleDescriptionOID;
105     }
106
107
108     /**
109      *
110      * @return the equality matching rule description OID of this or the
111      * superior attribute type description, may be null
112      */

113     public String JavaDoc getEqualityMatchingRuleDescriptionOIDTransitive()
114     {
115         if ( this.equalityMatchingRuleDescriptionOID != null )
116         {
117             return this.equalityMatchingRuleDescriptionOID;
118         }
119         else if ( this.getExistingSuperiorAttributeTypeDescription() != null )
120         {
121             return this.getExistingSuperiorAttributeTypeDescription().getEqualityMatchingRuleDescriptionOIDTransitive();
122         }
123         else
124         {
125             return null;
126         }
127     }
128
129
130     /**
131      *
132      * @return the ordering matching rule OID, may be null
133      */

134     public String JavaDoc getOrderingMatchingRuleDescriptionOID()
135     {
136         return orderingMatchingRuleDescriptionOID;
137     }
138
139
140     public void setOrderingMatchingRuleDescriptionOID( String JavaDoc orderingMatchingRuleDescriptionOID )
141     {
142         this.orderingMatchingRuleDescriptionOID = orderingMatchingRuleDescriptionOID;
143     }
144
145
146     /**
147      *
148      * @return the ordering matching rule description OID of this or the
149      * superior attribute type description, may be null
150      */

151     public String JavaDoc getOrderingMatchingRuleDescriptionOIDTransitive()
152     {
153         if ( this.orderingMatchingRuleDescriptionOID != null )
154         {
155             return this.orderingMatchingRuleDescriptionOID;
156         }
157         else if ( this.getExistingSuperiorAttributeTypeDescription() != null )
158         {
159             return this.getExistingSuperiorAttributeTypeDescription().getOrderingMatchingRuleDescriptionOIDTransitive();
160         }
161         else
162         {
163             return null;
164         }
165     }
166
167
168     /**
169      *
170      * @return the substring matching rule OID, may be null
171      */

172     public String JavaDoc getSubstringMatchingRuleDescriptionOID()
173     {
174         return substringMatchingRuleDescriptionOID;
175     }
176
177
178     public void setSubstringMatchingRuleDescriptionOID( String JavaDoc substringMatchingRuleDescriptionOID )
179     {
180         this.substringMatchingRuleDescriptionOID = substringMatchingRuleDescriptionOID;
181     }
182
183
184     /**
185      *
186      * @return the substring matching rule description OID of this or the
187      * superior attribute type description, may be null
188      */

189     public String JavaDoc getSubstringMatchingRuleDescriptionOIDTransitive()
190     {
191         if ( this.substringMatchingRuleDescriptionOID != null )
192         {
193             return this.substringMatchingRuleDescriptionOID;
194         }
195         else if ( this.getExistingSuperiorAttributeTypeDescription() != null )
196         {
197             return this.getExistingSuperiorAttributeTypeDescription()
198                 .getSubstringMatchingRuleDescriptionOIDTransitive();
199         }
200         else
201         {
202             return null;
203         }
204     }
205
206
207     /**
208      *
209      * @return the name of the superior (parent) attribute type description
210      * or null
211      */

212     public String JavaDoc getSuperiorAttributeTypeDescriptionName()
213     {
214         return superiorAttributeTypeDescriptionName;
215     }
216
217
218     public void setSuperiorAttributeTypeDescriptionName( String JavaDoc superiorAttributeTypeDescriptionName )
219     {
220         this.superiorAttributeTypeDescriptionName = superiorAttributeTypeDescriptionName;
221     }
222
223
224     /**
225      *
226      * @return the syntax description OID, may be null
227      */

228     public String JavaDoc getSyntaxDescriptionNumericOIDPlusLength()
229     {
230         return syntaxDescriptionNumericOIDPlusLength;
231     }
232
233
234     public void setSyntaxDescriptionNumericOIDPlusLength( String JavaDoc syntaxDescriptionNumericOIDPlusLength )
235     {
236         this.syntaxDescriptionNumericOIDPlusLength = syntaxDescriptionNumericOIDPlusLength;
237     }
238
239
240     /**
241      *
242      * @return the syntax description OID of this or the superior attribute
243      * type description, may be null
244      */

245     public String JavaDoc getSyntaxDescriptionNumericOIDTransitive()
246     {
247         if ( this.syntaxDescriptionNumericOIDPlusLength != null )
248         {
249             if ( this.syntaxDescriptionNumericOIDPlusLength.endsWith( "}" )
250                 && this.syntaxDescriptionNumericOIDPlusLength.indexOf( "{" ) != -1 )
251             {
252                 String JavaDoc syntaxOid = this.syntaxDescriptionNumericOIDPlusLength.substring( 0,
253                     this.syntaxDescriptionNumericOIDPlusLength.indexOf( "{" ) );
254                 return syntaxOid;
255             }
256             else
257             {
258                 return this.syntaxDescriptionNumericOIDPlusLength;
259             }
260         }
261         else if ( this.getExistingSuperiorAttributeTypeDescription() != null )
262         {
263             return this.getExistingSuperiorAttributeTypeDescription().getSyntaxDescriptionNumericOIDTransitive();
264         }
265         else
266         {
267             return null;
268         }
269     }
270
271
272     /**
273      *
274      * @return the syntax length of this or the superior attribute type
275      * description, may be null
276      */

277     public String JavaDoc getSyntaxDescriptionLengthTransitive()
278     {
279         if ( this.syntaxDescriptionNumericOIDPlusLength != null
280             && this.syntaxDescriptionNumericOIDPlusLength.endsWith( "}" )
281             && this.syntaxDescriptionNumericOIDPlusLength.indexOf( "{" ) != -1 )
282         {
283             String JavaDoc length = this.syntaxDescriptionNumericOIDPlusLength.substring(
284                 this.syntaxDescriptionNumericOIDPlusLength.indexOf( "{" ) + 1,
285                 this.syntaxDescriptionNumericOIDPlusLength.indexOf( "}" ) );
286             return length;
287         }
288         else if ( this.getExistingSuperiorAttributeTypeDescription() != null )
289         {
290             return this.getExistingSuperiorAttributeTypeDescription().getSyntaxDescriptionLengthTransitive();
291         }
292         else
293         {
294             return null;
295         }
296     }
297
298
299     /**
300      *
301      * @return the usage, on of ATTRIBUTE_USAGE_...
302      */

303     public String JavaDoc getUsage()
304     {
305         return usage;
306     }
307
308
309     public void setUsage( String JavaDoc usage )
310     {
311         if ( usage == null )
312         {
313             this.usage = ATTRIBUTE_USAGE_USER_APPLICATIONS;
314         }
315         else
316         {
317             this.usage = usage;
318         }
319     }
320
321
322     /**
323      *
324      * @return the single-valued flag
325      */

326     public boolean isSingleValued()
327     {
328         return isSingleValued;
329     }
330
331
332     public void setSingleValued( boolean isSingleValued )
333     {
334         this.isSingleValued = isSingleValued;
335     }
336
337
338     /**
339      *
340      * @return the collective flag
341      */

342     public boolean isCollective()
343     {
344         return isCollective;
345     }
346
347
348     public void setCollective( boolean isCollective )
349     {
350         this.isCollective = isCollective;
351     }
352
353
354     /**
355      *
356      * @return the no-user-modification flag
357      */

358     public boolean isNoUserModification()
359     {
360         return isNoUserModification;
361     }
362
363
364     public void setNoUserModification( boolean isNoUserModification )
365     {
366         this.isNoUserModification = isNoUserModification;
367     }
368
369
370     /**
371      * Convenience method to !isBinary().
372      *
373      * @return true if this attribute type or its syntax is defined as
374      * string
375      */

376     public boolean isString()
377     {
378         return !isBinary();
379     }
380
381
382     /**
383      * Checks the pre-defined and user-defined binary attribute types. If
384      * this attribute name or OID is defned as binary true is returned. Then
385      * the syntax is checked, see LdadSyntaxDescription#isBinary().
386      *
387      * @return true if this attribute type or its syntax is defined as
388      * binary
389      */

390     public boolean isBinary()
391     {
392         // check user-defined binary attributes
393
Set JavaDoc binaryAttributeOidsAndNames = BrowserCorePlugin.getDefault().getCorePreferences()
394             .getBinaryAttributeOidsAndNames();
395         if ( binaryAttributeOidsAndNames.contains( this.numericOID ) )
396         {
397             return true;
398         }
399         for ( int i = 0; i < names.length; i++ )
400         {
401             if ( binaryAttributeOidsAndNames.contains( names[i] ) )
402             {
403                 return true;
404             }
405         }
406
407         // check syntax (includes user-defined binary syntaxes)
408
return this.getSyntaxDescription().isBinary();
409     }
410
411
412     /**
413      *
414      * @return the syntax description of this or the superior attribute type
415      * descripiton, may be the default or a dummy, never null
416      */

417     public LdapSyntaxDescription getSyntaxDescription()
418     {
419
420         String JavaDoc syntaxOid = this.getSyntaxDescriptionNumericOIDTransitive();
421         if ( syntaxOid != null )
422         {
423             return this.getSchema().getLdapSyntaxDescription( syntaxOid );
424         }
425         else
426         {
427             return LdapSyntaxDescription.DUMMY;
428         }
429     }
430
431
432     private AttributeTypeDescription getExistingSuperiorAttributeTypeDescription()
433     {
434         if ( this.superiorAttributeTypeDescriptionName != null
435             && this.schema.hasAttributeTypeDescription( this.superiorAttributeTypeDescriptionName ) )
436         {
437             return this.getSchema().getAttributeTypeDescription( this.superiorAttributeTypeDescriptionName );
438         }
439         else
440         {
441             return null;
442         }
443     }
444
445
446     /**
447      *
448      * @return all attribute type description using this attribute type
449      * description as superior
450      */

451     public AttributeTypeDescription[] getDerivedAttributeTypeDescriptions()
452     {
453         Set JavaDoc derivedATDSet = new HashSet JavaDoc();
454         for ( Iterator JavaDoc it = this.getSchema().getAtdMapByName().values().iterator(); it.hasNext(); )
455         {
456             AttributeTypeDescription atd = ( AttributeTypeDescription ) it.next();
457             String JavaDoc supName = atd.getSuperiorAttributeTypeDescriptionName();
458             if ( supName != null && this.getLowerCaseIdentifierSet().contains( supName.toLowerCase() ) )
459             {
460                 derivedATDSet.add( atd );
461             }
462         }
463         AttributeTypeDescription[] derivedAtds = ( AttributeTypeDescription[] ) derivedATDSet
464             .toArray( new AttributeTypeDescription[0] );
465         Arrays.sort( derivedAtds );
466         return derivedAtds;
467     }
468
469
470     /**
471      *
472      * @return all object class description using this attribute type
473      * description as must attribute
474      */

475     public ObjectClassDescription[] getUsedAsMust()
476     {
477         Set JavaDoc usedAsMustSet = new HashSet JavaDoc();
478         for ( Iterator JavaDoc it = this.getSchema().getOcdMapByName().values().iterator(); it.hasNext(); )
479         {
480             ObjectClassDescription ocd = ( ObjectClassDescription ) it.next();
481             Set JavaDoc mustSet = toLowerCaseSet( ocd.getMustAttributeTypeDescriptionNamesTransitive() );
482             if ( mustSet.removeAll( this.getLowerCaseIdentifierSet() ) )
483             {
484                 usedAsMustSet.add( ocd );
485             }
486         }
487         ObjectClassDescription[] ocds = ( ObjectClassDescription[] ) usedAsMustSet
488             .toArray( new ObjectClassDescription[0] );
489         Arrays.sort( ocds );
490         return ocds;
491     }
492
493
494     /**
495      *
496      * @return all object class description using this attribute type
497      * description as may attribute
498      */

499     public ObjectClassDescription[] getUsedAsMay()
500     {
501         Set JavaDoc usedAsMaySet = new HashSet JavaDoc();
502         for ( Iterator JavaDoc it = this.getSchema().getOcdMapByName().values().iterator(); it.hasNext(); )
503         {
504             ObjectClassDescription ocd = ( ObjectClassDescription ) it.next();
505             Set JavaDoc maySet = toLowerCaseSet( ocd.getMayAttributeTypeDescriptionNamesTransitive() );
506             if ( maySet.removeAll( this.getLowerCaseIdentifierSet() ) )
507             {
508                 usedAsMaySet.add( ocd );
509             }
510         }
511         ObjectClassDescription[] ocds = ( ObjectClassDescription[] ) usedAsMaySet
512             .toArray( new ObjectClassDescription[0] );
513         Arrays.sort( ocds );
514         return ocds;
515     }
516
517
518     /**
519      *
520      * @return all matching rule description names this attribute type
521      * description applies to according to the schemas matching rule
522      * use descriptions
523      */

524     public String JavaDoc[] getOtherMatchingRuleDescriptionNames()
525     {
526         Set JavaDoc otherMatchingRuleSet = new HashSet JavaDoc();
527         for ( Iterator JavaDoc it = this.getSchema().getMrudMapByName().values().iterator(); it.hasNext(); )
528         {
529             MatchingRuleUseDescription mrud = ( MatchingRuleUseDescription ) it.next();
530             Set JavaDoc atdSet = toLowerCaseSet( mrud.getAppliesAttributeTypeDescriptionOIDs() );
531             if ( atdSet.removeAll( this.getLowerCaseIdentifierSet() ) )
532             {
533                 otherMatchingRuleSet.addAll( Arrays.asList( mrud.getNames() ) );
534             }
535         }
536         String JavaDoc[] mrds = ( String JavaDoc[] ) otherMatchingRuleSet.toArray( new String JavaDoc[0] );
537         Arrays.sort( mrds );
538         return mrds;
539     }
540
541 }
542
Popular Tags