1 20 21 package org.apache.directory.ldapstudio.browser.core.model.schema; 22 23 24 import java.util.ArrayList ; 25 import java.util.Arrays ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Set ; 30 31 32 public class ObjectClassDescription extends SchemaPart2 33 { 34 35 private static final long serialVersionUID = 2324990817612632432L; 36 37 public static final String EXTENSIBLEOBJECT_OBJECTCLASSNAME = "extensibleObject"; 38 39 public static final String OBSOLETE = "Obsolete"; 40 41 public static final String ABSTRACT = "Abstract"; 42 43 public static final String STRUCTURAL = "Structural"; 44 45 public static final String AUXILIARY = "Auxiliary"; 46 47 public static final String OC_ALIAS = "alias"; 48 49 public static final String OC_REFERRAL = "referral"; 50 51 public static final String OC_SUBENTRY = "subentry"; 52 53 public static final String OC_COUNTRY = "country"; 54 55 public static final String OC_LOCALITY = "locality"; 56 57 public static final String OC_DCOBJECT = "dcObject"; 58 59 public static final String OC_DOMAIN = "domain"; 60 61 public static final String OC_GROUPOFNAMES = "groupOfNames"; 62 63 public static final String OC_GROUPOFUNIQUENAMES = "groupOfUniqueNames"; 64 65 public static final String OC_POSIXGROUP = "posixGroup"; 66 67 public static final String OC_PERSON = "person"; 68 69 public static final String OC_ORGANIZATIONALPERSON = "organizationalPerson"; 70 71 public static final String OC_INETORGPERSON = "inetOrgPerson"; 72 73 public static final String OC_RESIDENTIALPERSON = "residentialPerson"; 74 75 public static final String OC_PILOTPERSON = "pilotPerson"; 76 77 public static final String OC_NEWPILOTPERSON = "newPilotPerson"; 78 79 public static final String OC_ACCOUNT = "account"; 80 81 public static final String OC_ORGANIZATIONALROLE = "organizationalRole"; 82 83 public static final String OC_ORGANIZATION = "organization"; 84 85 public static final String OC_ORGANIZATIONALUNIT = "organizationalUnit"; 86 87 public static final String OC_PILOTORGANIZATION = "pilotOrganization"; 88 89 public static final String OC_DMD = "dmd"; 90 91 public static final String OC_APPLICATIONPROCESS = "applicationProcess"; 92 93 public static final String OC_APPLICATIONENTITY = "applicationEntity"; 94 95 public static final String OC_ = "organizationalUnit"; 96 97 private boolean isAbstract; 98 99 private boolean isStructural; 100 101 private boolean isAuxiliary; 102 103 private String [] superiorObjectClassDescriptionNames; 104 105 private String [] mustAttributeTypeDescriptionNames; 106 107 private String [] 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 [0]; 117 this.mustAttributeTypeDescriptionNames = new String [0]; 118 this.mayAttributeTypeDescriptionNames = new String [0]; 119 } 120 121 122 public int compareTo( Object o ) 123 { 124 if ( o instanceof ObjectClassDescription ) 125 { 126 return this.toString().compareTo( o.toString() ); 127 } 128 else 129 { 130 throw new ClassCastException ( "Object of type " + this.getClass().getName() + " required." ); 131 } 132 } 133 134 135 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 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 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 193 public String [] getMayAttributeTypeDescriptionNames() 194 { 195 return mayAttributeTypeDescriptionNames; 196 } 197 198 199 public void setMayAttributeTypeDescriptionNames( String [] mayAttributeTypeDescriptionNames ) 200 { 201 this.mayAttributeTypeDescriptionNames = mayAttributeTypeDescriptionNames; 202 } 203 204 205 210 public String [] getMayAttributeTypeDescriptionNamesTransitive() 211 { 212 Set maySet = new HashSet (); 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 [] mays = ( String [] ) maySet.toArray( new String [maySet.size()] ); 226 Arrays.sort( mays ); 227 return mays; 228 } 229 230 231 235 public String [] getMustAttributeTypeDescriptionNames() 236 { 237 return mustAttributeTypeDescriptionNames; 238 } 239 240 241 public void setMustAttributeTypeDescriptionNames( String [] mustAttributeTypeDescriptionNames ) 242 { 243 this.mustAttributeTypeDescriptionNames = mustAttributeTypeDescriptionNames; 244 } 245 246 247 252 public String [] getMustAttributeTypeDescriptionNamesTransitive() 253 { 254 Set maySet = new HashSet (); 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 [] musts = ( String [] ) maySet.toArray( new String [maySet.size()] ); 268 Arrays.sort( musts ); 269 return musts; 270 } 271 272 273 278 public String [] getSuperiorObjectClassDescriptionNames() 279 { 280 return superiorObjectClassDescriptionNames; 281 } 282 283 284 public void setSuperiorObjectClassDescriptionNames( String [] superiorObjectClassDescriptionNames ) 285 { 286 this.superiorObjectClassDescriptionNames = superiorObjectClassDescriptionNames; 287 } 288 289 290 294 public ObjectClassDescription[] getSuperiorObjectClassDescriptions() 295 { 296 String [] 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 310 public ObjectClassDescription[] getSubObjectClassDescriptions() 311 { 312 Set subOCDSet = new HashSet (); 313 for ( Iterator it = this.getSchema().getOcdMapByName().values().iterator(); it.hasNext(); ) 314 { 315 ObjectClassDescription ocd = ( ObjectClassDescription ) it.next(); 316 Set 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 supList = new ArrayList (); 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 |