1 20 21 package org.apache.directory.ldapstudio.browser.core.model.schema; 22 23 24 import java.util.Arrays ; 25 import java.util.HashSet ; 26 import java.util.Iterator ; 27 import java.util.Set ; 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 ATTRIBUTE_USAGE_USER_APPLICATIONS = "userApplications"; 38 39 public static final String ATTRIBUTE_USAGE_DISTRIBUTED_OPERATION = "distributedOperation"; 40 41 public static final String ATTRIBUTE_USAGE_DIRECTORY_OPERATION = "directoryOperation"; 42 43 public static final String ATTRIBUTE_USAGE_DSA_OPERATION = "dSAOperation"; 44 45 private String superiorAttributeTypeDescriptionName; 46 47 private String equalityMatchingRuleDescriptionOID; 48 49 private String orderingMatchingRuleDescriptionOID; 50 51 private String substringMatchingRuleDescriptionOID; 52 53 private String syntaxDescriptionNumericOIDPlusLength; 54 55 private boolean isSingleValued; 56 57 private boolean isCollective; 58 59 private boolean isNoUserModification; 60 61 private String 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 o ) 80 { 81 if ( o instanceof AttributeTypeDescription ) 82 { 83 return this.toString().compareTo( o.toString() ); 84 } 85 else 86 { 87 throw new ClassCastException ( "Object of type " + this.getClass().getName() + " required." ); 88 } 89 } 90 91 92 96 public String getEqualityMatchingRuleDescriptionOID() 97 { 98 return equalityMatchingRuleDescriptionOID; 99 } 100 101 102 public void setEqualityMatchingRuleDescriptionOID( String equalityMatchingRuleDescriptionOID ) 103 { 104 this.equalityMatchingRuleDescriptionOID = equalityMatchingRuleDescriptionOID; 105 } 106 107 108 113 public String 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 134 public String getOrderingMatchingRuleDescriptionOID() 135 { 136 return orderingMatchingRuleDescriptionOID; 137 } 138 139 140 public void setOrderingMatchingRuleDescriptionOID( String orderingMatchingRuleDescriptionOID ) 141 { 142 this.orderingMatchingRuleDescriptionOID = orderingMatchingRuleDescriptionOID; 143 } 144 145 146 151 public String 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 172 public String getSubstringMatchingRuleDescriptionOID() 173 { 174 return substringMatchingRuleDescriptionOID; 175 } 176 177 178 public void setSubstringMatchingRuleDescriptionOID( String substringMatchingRuleDescriptionOID ) 179 { 180 this.substringMatchingRuleDescriptionOID = substringMatchingRuleDescriptionOID; 181 } 182 183 184 189 public String 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 212 public String getSuperiorAttributeTypeDescriptionName() 213 { 214 return superiorAttributeTypeDescriptionName; 215 } 216 217 218 public void setSuperiorAttributeTypeDescriptionName( String superiorAttributeTypeDescriptionName ) 219 { 220 this.superiorAttributeTypeDescriptionName = superiorAttributeTypeDescriptionName; 221 } 222 223 224 228 public String getSyntaxDescriptionNumericOIDPlusLength() 229 { 230 return syntaxDescriptionNumericOIDPlusLength; 231 } 232 233 234 public void setSyntaxDescriptionNumericOIDPlusLength( String syntaxDescriptionNumericOIDPlusLength ) 235 { 236 this.syntaxDescriptionNumericOIDPlusLength = syntaxDescriptionNumericOIDPlusLength; 237 } 238 239 240 245 public String getSyntaxDescriptionNumericOIDTransitive() 246 { 247 if ( this.syntaxDescriptionNumericOIDPlusLength != null ) 248 { 249 if ( this.syntaxDescriptionNumericOIDPlusLength.endsWith( "}" ) 250 && this.syntaxDescriptionNumericOIDPlusLength.indexOf( "{" ) != -1 ) 251 { 252 String 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 277 public String getSyntaxDescriptionLengthTransitive() 278 { 279 if ( this.syntaxDescriptionNumericOIDPlusLength != null 280 && this.syntaxDescriptionNumericOIDPlusLength.endsWith( "}" ) 281 && this.syntaxDescriptionNumericOIDPlusLength.indexOf( "{" ) != -1 ) 282 { 283 String 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 303 public String getUsage() 304 { 305 return usage; 306 } 307 308 309 public void setUsage( String 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 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 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 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 376 public boolean isString() 377 { 378 return !isBinary(); 379 } 380 381 382 390 public boolean isBinary() 391 { 392 Set 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 return this.getSyntaxDescription().isBinary(); 409 } 410 411 412 417 public LdapSyntaxDescription getSyntaxDescription() 418 { 419 420 String 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 451 public AttributeTypeDescription[] getDerivedAttributeTypeDescriptions() 452 { 453 Set derivedATDSet = new HashSet (); 454 for ( Iterator it = this.getSchema().getAtdMapByName().values().iterator(); it.hasNext(); ) 455 { 456 AttributeTypeDescription atd = ( AttributeTypeDescription ) it.next(); 457 String 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 475 public ObjectClassDescription[] getUsedAsMust() 476 { 477 Set usedAsMustSet = new HashSet (); 478 for ( Iterator it = this.getSchema().getOcdMapByName().values().iterator(); it.hasNext(); ) 479 { 480 ObjectClassDescription ocd = ( ObjectClassDescription ) it.next(); 481 Set 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 499 public ObjectClassDescription[] getUsedAsMay() 500 { 501 Set usedAsMaySet = new HashSet (); 502 for ( Iterator it = this.getSchema().getOcdMapByName().values().iterator(); it.hasNext(); ) 503 { 504 ObjectClassDescription ocd = ( ObjectClassDescription ) it.next(); 505 Set 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 524 public String [] getOtherMatchingRuleDescriptionNames() 525 { 526 Set otherMatchingRuleSet = new HashSet (); 527 for ( Iterator it = this.getSchema().getMrudMapByName().values().iterator(); it.hasNext(); ) 528 { 529 MatchingRuleUseDescription mrud = ( MatchingRuleUseDescription ) it.next(); 530 Set atdSet = toLowerCaseSet( mrud.getAppliesAttributeTypeDescriptionOIDs() ); 531 if ( atdSet.removeAll( this.getLowerCaseIdentifierSet() ) ) 532 { 533 otherMatchingRuleSet.addAll( Arrays.asList( mrud.getNames() ) ); 534 } 535 } 536 String [] mrds = ( String [] ) otherMatchingRuleSet.toArray( new String [0] ); 537 Arrays.sort( mrds ); 538 return mrds; 539 } 540 541 } 542 | Popular Tags |