KickJava   Java API By Example, From Geeks To Geeks.

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


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.ArrayList JavaDoc;
25 import java.util.Arrays JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Set JavaDoc;
30
31
32 public class ObjectClassDescription extends SchemaPart2
33 {
34
35     private static final long serialVersionUID = 2324990817612632432L;
36
37     public static final String JavaDoc EXTENSIBLEOBJECT_OBJECTCLASSNAME = "extensibleObject";
38
39     public static final String JavaDoc OBSOLETE = "Obsolete";
40
41     public static final String JavaDoc ABSTRACT = "Abstract";
42
43     public static final String JavaDoc STRUCTURAL = "Structural";
44
45     public static final String JavaDoc AUXILIARY = "Auxiliary";
46
47     public static final String JavaDoc OC_ALIAS = "alias";
48
49     public static final String JavaDoc OC_REFERRAL = "referral";
50
51     public static final String JavaDoc OC_SUBENTRY = "subentry";
52
53     public static final String JavaDoc OC_COUNTRY = "country";
54
55     public static final String JavaDoc OC_LOCALITY = "locality";
56
57     public static final String JavaDoc OC_DCOBJECT = "dcObject";
58
59     public static final String JavaDoc OC_DOMAIN = "domain";
60
61     public static final String JavaDoc OC_GROUPOFNAMES = "groupOfNames";
62
63     public static final String JavaDoc OC_GROUPOFUNIQUENAMES = "groupOfUniqueNames";
64
65     public static final String JavaDoc OC_POSIXGROUP = "posixGroup";
66
67     public static final String JavaDoc OC_PERSON = "person";
68
69     public static final String JavaDoc OC_ORGANIZATIONALPERSON = "organizationalPerson";
70
71     public static final String JavaDoc OC_INETORGPERSON = "inetOrgPerson";
72
73     public static final String JavaDoc OC_RESIDENTIALPERSON = "residentialPerson";
74
75     public static final String JavaDoc OC_PILOTPERSON = "pilotPerson";
76
77     public static final String JavaDoc OC_NEWPILOTPERSON = "newPilotPerson";
78
79     public static final String JavaDoc OC_ACCOUNT = "account";
80
81     public static final String JavaDoc OC_ORGANIZATIONALROLE = "organizationalRole";
82
83     public static final String JavaDoc OC_ORGANIZATION = "organization";
84
85     public static final String JavaDoc OC_ORGANIZATIONALUNIT = "organizationalUnit";
86
87     public static final String JavaDoc OC_PILOTORGANIZATION = "pilotOrganization";
88
89     public static final String JavaDoc OC_DMD = "dmd";
90
91     public static final String JavaDoc OC_APPLICATIONPROCESS = "applicationProcess";
92
93     public static final String JavaDoc OC_APPLICATIONENTITY = "applicationEntity";
94
95     public static final String JavaDoc OC_ = "organizationalUnit";
96
97     private boolean isAbstract;
98
99     private boolean isStructural;
100
101     private boolean isAuxiliary;
102
103     private String JavaDoc[] superiorObjectClassDescriptionNames;
104
105     private String JavaDoc[] mustAttributeTypeDescriptionNames;
106
107     private String JavaDoc[] mayAttributeTypeDescriptionNames;
108
109
110     public ObjectClassDescription()
111     {
112         super();
113         this.isAbstract = false;
114         this.isStructural = true;
115         this.isAuxiliary = false;
116         this.superiorObjectClassDescriptionNames = new String JavaDoc[0];
117         this.mustAttributeTypeDescriptionNames = new String JavaDoc[0];
118         this.mayAttributeTypeDescriptionNames = new String JavaDoc[0];
119     }
120
121
122     public int compareTo( Object JavaDoc o )
123     {
124         if ( o instanceof ObjectClassDescription )
125         {
126             return this.toString().compareTo( o.toString() );
127         }
128         else
129         {
130             throw new ClassCastException JavaDoc( "Object of type " + this.getClass().getName() + " required." );
131         }
132     }
133
134
135     /**
136      *
137      * @return the abstract flag
138      */

139     public boolean isAbstract()
140     {
141         return isAbstract;
142     }
143
144
145     public void setAbstract( boolean isAbstract )
146     {
147         this.isAbstract = isAbstract;
148         this.isAuxiliary = this.isAuxiliary && !this.isAbstract;
149         this.isStructural = this.isStructural && !this.isAbstract;
150     }
151
152
153     /**
154      *
155      * @return the auxiliary flag
156      */

157     public boolean isAuxiliary()
158     {
159         return isAuxiliary;
160     }
161
162
163     public void setAuxiliary( boolean isAuxiliary )
164     {
165         this.isAuxiliary = isAuxiliary;
166         this.isAbstract = this.isAbstract && !this.isAuxiliary;
167         this.isStructural = this.isStructural && !this.isAuxiliary;
168     }
169
170
171     /**
172      *
173      * @return the structural flag
174      */

175     public boolean isStructural()
176     {
177         return isStructural;
178     }
179
180
181     public void setStructural( boolean isStructural )
182     {
183         this.isStructural = isStructural;
184         this.isAbstract = this.isAbstract && !this.isStructural;
185         this.isAuxiliary = this.isAuxiliary && !this.isStructural;
186     }
187
188
189     /**
190      *
191      * @return the may attribute names, may be an empty array
192      */

193     public String JavaDoc[] getMayAttributeTypeDescriptionNames()
194     {
195         return mayAttributeTypeDescriptionNames;
196     }
197
198
199     public void setMayAttributeTypeDescriptionNames( String JavaDoc[] mayAttributeTypeDescriptionNames )
200     {
201         this.mayAttributeTypeDescriptionNames = mayAttributeTypeDescriptionNames;
202     }
203
204
205     /**
206      *
207      * @return the may attribute names of this and all superior object class
208      * definitions
209      */

210     public String JavaDoc[] getMayAttributeTypeDescriptionNamesTransitive()
211     {
212         Set JavaDoc maySet = new HashSet JavaDoc();
213         for ( int i = 0; i < this.mayAttributeTypeDescriptionNames.length; i++ )
214         {
215             maySet.add( this.mayAttributeTypeDescriptionNames[i] );
216         }
217         ObjectClassDescription[] supOCDs = this.getExistingSuperObjectClassDescription();
218         if ( supOCDs != null && supOCDs.length > 0 )
219         {
220             for ( int i = 0; i < supOCDs.length; i++ )
221             {
222                 maySet.addAll( Arrays.asList( supOCDs[i].getMayAttributeTypeDescriptionNamesTransitive() ) );
223             }
224         }
225         String JavaDoc[] mays = ( String JavaDoc[] ) maySet.toArray( new String JavaDoc[maySet.size()] );
226         Arrays.sort( mays );
227         return mays;
228     }
229
230
231     /**
232      *
233      * @return the must attribute names, may be an empty array
234      */

235     public String JavaDoc[] getMustAttributeTypeDescriptionNames()
236     {
237         return mustAttributeTypeDescriptionNames;
238     }
239
240
241     public void setMustAttributeTypeDescriptionNames( String JavaDoc[] mustAttributeTypeDescriptionNames )
242     {
243         this.mustAttributeTypeDescriptionNames = mustAttributeTypeDescriptionNames;
244     }
245
246
247     /**
248      *
249      * @return the must attribute names of this and all superior object
250      * class definitions
251      */

252     public String JavaDoc[] getMustAttributeTypeDescriptionNamesTransitive()
253     {
254         Set JavaDoc maySet = new HashSet JavaDoc();
255         for ( int i = 0; i < this.mustAttributeTypeDescriptionNames.length; i++ )
256         {
257             maySet.add( this.mustAttributeTypeDescriptionNames[i] );
258         }
259         ObjectClassDescription[] supOCDs = this.getExistingSuperObjectClassDescription();
260         if ( supOCDs != null && supOCDs.length > 0 )
261         {
262             for ( int i = 0; i < supOCDs.length; i++ )
263             {
264                 maySet.addAll( Arrays.asList( supOCDs[i].getMustAttributeTypeDescriptionNamesTransitive() ) );
265             }
266         }
267         String JavaDoc[] musts = ( String JavaDoc[] ) maySet.toArray( new String JavaDoc[maySet.size()] );
268         Arrays.sort( musts );
269         return musts;
270     }
271
272
273     /**
274      *
275      * @return the names of the superior (parent) object class names, may be
276      * an empty array
277      */

278     public String JavaDoc[] getSuperiorObjectClassDescriptionNames()
279     {
280         return superiorObjectClassDescriptionNames;
281     }
282
283
284     public void setSuperiorObjectClassDescriptionNames( String JavaDoc[] superiorObjectClassDescriptionNames )
285     {
286         this.superiorObjectClassDescriptionNames = superiorObjectClassDescriptionNames;
287     }
288
289     
290     /**
291      *
292      * @return all superior (parent) object class descriptions, may be an empty array
293      */

294     public ObjectClassDescription[] getSuperiorObjectClassDescriptions()
295     {
296         String JavaDoc[] names = getSuperiorObjectClassDescriptionNames();
297         ObjectClassDescription[] superiorOcds = new ObjectClassDescription[names.length];
298         for ( int i = 0; i < superiorOcds.length; i++ )
299         {
300             superiorOcds[i] = getSchema().getObjectClassDescription( names[i] );
301         }
302         return superiorOcds;
303     }
304
305     /**
306      *
307      * @return all object class description using this object class
308      * definition as superior
309      */

310     public ObjectClassDescription[] getSubObjectClassDescriptions()
311     {
312         Set JavaDoc subOCDSet = new HashSet JavaDoc();
313         for ( Iterator JavaDoc it = this.getSchema().getOcdMapByName().values().iterator(); it.hasNext(); )
314         {
315             ObjectClassDescription ocd = ( ObjectClassDescription ) it.next();
316             Set JavaDoc supNameSet = toLowerCaseSet( ocd.getSuperiorObjectClassDescriptionNames() );
317             if ( supNameSet.removeAll( this.getLowerCaseIdentifierSet() ) )
318             {
319                 subOCDSet.add( ocd );
320             }
321         }
322         ObjectClassDescription[] subOcds = ( ObjectClassDescription[] ) subOCDSet
323             .toArray( new ObjectClassDescription[0] );
324         Arrays.sort( subOcds );
325         return subOcds;
326     }
327
328
329     private ObjectClassDescription[] getExistingSuperObjectClassDescription()
330     {
331         List JavaDoc supList = new ArrayList JavaDoc();
332         for ( int i = 0; i < this.superiorObjectClassDescriptionNames.length; i++ )
333         {
334             if ( this.schema.hasObjectClassDescription( this.superiorObjectClassDescriptionNames[i] ) )
335             {
336                 supList.add( this.schema.getObjectClassDescription( this.superiorObjectClassDescriptionNames[i] ) );
337             }
338         }
339         ObjectClassDescription[] supOcds = ( ObjectClassDescription[] ) supList
340             .toArray( new ObjectClassDescription[supList.size()] );
341         Arrays.sort( supOcds );
342         return supOcds;
343     }
344
345 }
346
Popular Tags