1 2 package com.ca.commons.naming; 3 4 import com.ca.commons.cbutil.*; 5 import com.ca.commons.jndi.SchemaOps; 6 7 import javax.naming.*; 8 import javax.naming.directory.*; 9 10 import java.util.*; 11 import java.util.logging.Logger ; 12 import java.util.logging.Level ; 13 14 23 24 30 34 public class DXAttributes implements Attributes 35 { 36 37 static Hashtable attOIDs = new Hashtable(100); 39 static int ID = 0; 40 41 int id; 43 Hashtable atts; 45 HashSet must; 48 boolean ignoreCase = true; 50 boolean schemaChecked = false; Attribute allObjectClasses; 54 56 String objectClassName = null; 58 Vector orderedSOCs = new Vector(); 60 61 static SchemaOps schema; 63 static Hashtable knownParents = new Hashtable(30); static Hashtable knownSubSets = new Hashtable(30); static Hashtable objectClassDepths = new Hashtable(30); 67 private final static Logger log = Logger.getLogger(DXAttributes.class.getName()); 68 69 70 static 71 { 72 objectClassDepths.put("top", new Integer (0)); 73 74 objectClassDepths.put("schema", new Integer (1)); 76 objectClassDepths.put("AttributeDefinition", new Integer (2)); 77 objectClassDepths.put("ClassDefinition", new Integer (2)); 78 objectClassDepths.put("SyntaxDefinition", new Integer (2)); 79 80 } 81 82 void basicInit() 84 { 85 id = ID++; 86 87 atts = new Hashtable(); 88 must = new HashSet(); 89 90 } 92 93 96 public DXAttributes() 97 { 98 basicInit(); 99 } 100 101 104 105 public DXAttributes(Attribute a) 106 { 107 basicInit(); 108 put(a); 109 } 110 111 115 116 public DXAttributes(Attributes a) 117 { 118 119 if (a==null) 120 { 121 atts = new Hashtable(); 122 must = new HashSet(); 123 } 124 else 125 { 126 atts = new Hashtable(a.size()+10); 127 must = new HashSet(a.size()); 129 Enumeration e = a.getAll(); 130 while (e.hasMoreElements()) 131 { 132 DXAttribute newAtt = new DXAttribute((Attribute)e.nextElement()); 133 put (newAtt); 134 } 135 } 136 } 137 138 144 145 public DXAttributes(Hashtable newAtts) 146 { 147 atts = (Hashtable) newAtts.clone(); 148 } 149 150 151 157 158 public DXAttributes(NamingEnumeration newAtts) 159 { 160 atts = new Hashtable(); 161 while (newAtts.hasMoreElements()) 162 { 163 Attribute current = (Attribute) newAtts.nextElement(); 164 atts.put(current.getID().toLowerCase(), current); 165 } 166 } 167 168 169 177 public static void setDefaultSchema(SchemaOps defaultSchema) 178 { 179 schema = defaultSchema; 180 181 DXAttribute.setDefaultSchema(defaultSchema); 182 } 183 184 185 public int getID() { return id; } 186 187 191 192 public Object clone() 193 { 194 return new DXAttributes(atts); 195 } 196 197 203 204 public Attribute get(java.lang.String attrID) 205 { 206 Attribute ret = (Attribute) atts.get(attrID.toLowerCase()); 207 if (ret==null) 208 { 209 ret = (Attribute) atts.get(attrID.toLowerCase() + ";binary"); 210 } 211 212 return ret; 213 } 214 215 220 public NamingEnumeration getAll() 221 { 222 return (new DXNamingEnumeration (atts.elements())).sort(); 223 } 224 225 233 public Attributes getAsNonNullAttributes() 234 { 235 return new DXAttributes(getAllNonNull()); 236 } 237 238 249 250 public NamingEnumeration getAllNonNull() 251 { 252 DXNamingEnumeration returnEnumeration = new DXNamingEnumeration (); 253 Enumeration allatts = getAll(); 254 255 while (allatts.hasMoreElements()) 256 { 257 Attribute fnord = (Attribute) allatts.nextElement(); 258 if (fnord != null) { 260 try 261 { 262 if (fnord.get() != null) returnEnumeration.add(fnord); } 265 catch (NoSuchElementException e) { 267 268 } 269 catch (NamingException e2) 270 { 271 log.log(Level.WARNING, "whoops: Naming Exception reading " + fnord.getID(), e2); 272 } 273 } 274 } 275 276 returnEnumeration.sort(); 277 278 return returnEnumeration; 279 } 280 281 286 public NamingEnumeration getMandatory() 287 { 288 DXNamingEnumeration returnEnumeration = new DXNamingEnumeration (); 289 290 if (must==null) return returnEnumeration; 292 Iterator musts = must.iterator(); 293 while (musts.hasNext()) 294 { 295 String s = (String )musts.next(); 296 returnEnumeration.add(get(s)); 297 } 298 returnEnumeration.sort(); 299 300 return returnEnumeration; 301 } 302 303 304 305 309 310 public HashSet getMandatoryIDs() 311 { 312 return must; 313 } 314 315 316 317 322 public NamingEnumeration getOptional() 323 { 324 DXNamingEnumeration returnEnumeration = new DXNamingEnumeration (); 325 Enumeration allIDs = atts.keys(); 326 while (allIDs.hasMoreElements()) 327 { 328 String id = (String ) allIDs.nextElement(); 329 if (must.contains(id)==false) returnEnumeration.add(get(id)); } 332 returnEnumeration.sort(); 333 334 return returnEnumeration; 335 } 336 337 338 339 343 344 public NamingEnumeration getIDs() 345 { 346 DXNamingEnumeration ret = new DXNamingEnumeration(); 348 NamingEnumeration allAtts = getAll(); 349 while (allAtts.hasMoreElements()) 350 ret.add(((Attribute)allAtts.nextElement()).getID()); 351 352 return ret; 353 354 } 356 357 364 365 public boolean isCaseIgnored() 366 { 367 return ignoreCase; 368 } 369 370 379 380 public Attribute put(Attribute attr) 381 { 382 if (attr == null) return null; 384 Attribute old = get(attr.getID().toLowerCase()); 385 schemaChecked = false; 386 387 if (old!=null) 388 { 389 atts.remove(old.getID().toLowerCase()); } 391 392 String ID = attr.getID().toLowerCase(); 393 if (attr instanceof DXAttribute) 394 atts.put(ID, attr); 395 else 396 atts.put(ID, new DXAttribute(attr)); 397 398 return old; 399 } 400 401 414 415 public Attribute put(java.lang.String attrID, java.lang.Object val) 416 { 417 schemaChecked = false; 418 return put(new DXAttribute(attrID.toLowerCase(), val)); 419 } 420 421 426 427 public void put(Enumeration attributeList) 428 { 429 while (attributeList.hasMoreElements()) 430 { 431 Attribute a = (Attribute)attributeList.nextElement(); 432 if (a instanceof DXAttribute) 433 put(a); 434 else 435 put(new DXAttribute(a)); 436 } 437 } 438 439 444 445 public Attribute remove(java.lang.String attrID) 446 { 447 schemaChecked = false; 448 return (Attribute) atts.remove(attrID.toLowerCase()); 449 } 450 451 456 public int size() 457 { 458 return atts.size(); 459 } 460 461 467 489 502 public void setAllObjectClasses() 503 { 504 allObjectClasses = getAllObjectClasses(); 505 } 506 507 510 public Vector getOrderedOCs() 511 { 512 Vector ret = null; 513 try 514 { 515 Attribute oc = getAllObjectClasses(); 516 if (oc == null) 517 return null; 518 519 ret = new Vector(oc.size()); 520 NamingEnumeration vals = oc.getAll(); 521 while (vals.hasMore()) 522 { 523 ret.add(vals.next()); 524 } 525 return ret; 526 } 527 catch (NamingException e) 528 { 529 log.log(Level.WARNING, "Yet another rare naming exception - DXAttributes:getOrderedOCs ", e); 530 return new Vector(0); 531 } 532 } 533 534 public Attribute getAllObjectClasses() 535 { 536 Attribute att = get("objectclass"); 537 538 if (att != null) { 540 if (att instanceof DXAttribute) 541 return getAllObjectClasses((DXAttribute)att); 542 else 543 return getAllObjectClasses(new DXAttribute(att)); 544 } 545 return null; } 547 548 556 557 560 public static DXAttribute getAllObjectClasses(DXAttribute oc) 561 { 562 if (oc==null) return null; 564 if (knownSubSets.containsKey(oc)) 565 return(DXAttribute) knownSubSets.get(oc); 566 567 try 568 { 569 DXAttribute orig = new DXAttribute(oc); 570 571 Enumeration vals = oc.getAll(); 572 while (vals.hasMoreElements()) 573 { 574 Attribute parents = getParentObjectClasses((String )vals.nextElement()); 575 if (parents != null) 576 { 577 Enumeration parentVals = parents.getAll(); 578 while (parentVals.hasMoreElements()) 579 { 580 String parent = (String ) parentVals.nextElement(); 581 if (oc.contains(parent) == false) 582 { 583 oc.add(parent); 584 } 585 } 586 } 587 } 588 589 DXAttribute fullOC = sortOCByDepth(oc); 590 knownSubSets.put(orig, fullOC); 591 return fullOC; 592 } 593 catch (NamingException e) 594 { 595 log.log(Level.WARNING, "NamingException in getAllObjectClasses ", e); 596 return oc; 597 } 598 } 599 600 605 606 protected static DXAttribute sortOCByDepth(Attribute oc) 607 { 608 DXAttribute ret = new DXAttribute("objectClass"); 609 ret.setOrdered(true); 610 611 try 612 { 613 Enumeration vals = oc.getAll(); 614 while (vals.hasMoreElements()) 615 { 616 String val = (String ) vals.nextElement(); 617 Integer myInt = (Integer )objectClassDepths.get(val); 618 619 if (myInt == null) { 621 getParentObjectClasses(val); myInt = (Integer )objectClassDepths.get(val); if (myInt == null) myInt = new Integer (0); 625 } 626 int depth = myInt.intValue(); 627 int i; 628 for (i=ret.size()-1; i>=0; i--) 629 { 630 int existing = ( (Integer )objectClassDepths.get(ret.get(i)) ).intValue(); 631 if ( existing >= depth) 632 { 633 ret.add(i+1, val); 634 break; 635 } 636 } 637 if (i == -1) 638 ret.add(0, val); 639 } 640 return ret; 641 } 642 catch (NamingException e) 643 { 644 log.log(Level.WARNING, "Naming Exception in DXAttributes sortOCByDepth()", e); 645 return new DXAttribute(oc); 646 } 647 } 648 649 650 651 658 659 public static DXAttribute getParentObjectClasses(String childOC) 660 throws NamingException 661 { 662 if (schema == null) { 664 objectClassDepths.put(childOC, new Integer (1)); 665 return null; 666 } 667 668 if ("schema attributedefinition classdefinition syntaxdefinition matchingrule".indexOf(childOC.toLowerCase()) != -1) return null; 670 if (knownParents.containsKey(childOC)) 671 { 672 return (DXAttribute) knownParents.get(childOC); 673 } 674 675 DXAttribute parents = new DXAttribute("objectClass"); 677 String schemaParent = null; 678 try 679 { 680 Attributes schemaDef = schema.getAttributes("ClassDefinition/" + childOC); 682 if (schemaDef!=null) 683 { 684 Attribute sup = schemaDef.get("SUP"); 685 if (sup!=null) 686 schemaParent = (String )sup.get(); 687 } 688 } 689 catch (NamingException e) { 691 log.warning("Possible Schema Error: class definition for " + childOC + " could not be found"); 692 objectClassDepths.put(childOC, new Integer (1)); 694 return null; } 696 697 700 if (schemaParent != null) { 702 DXAttribute oc = getParentObjectClasses(schemaParent); 704 if (oc != null) 705 { 706 Enumeration vals = oc.getAll(); 707 while (vals.hasMoreElements()) { 709 parents.add(vals.nextElement()); } 711 } 712 713 int depth = ((Integer )objectClassDepths.get(schemaParent)).intValue(); 714 if (objectClassDepths.containsKey(childOC) == false) 715 { 716 objectClassDepths.put(childOC, new Integer (depth+1)); 717 } 718 else 719 { 720 int oldDepth = ((Integer )objectClassDepths.get(childOC)).intValue(); 721 if (oldDepth <= depth) 722 objectClassDepths.put(childOC, new Integer (depth+1)); 723 } 724 } 725 else { 727 objectClassDepths.put(childOC, new Integer (1)); } 730 731 parents.add(childOC); 733 knownParents.put(childOC, parents); 734 735 return parents; 736 } 737 738 742 761 766 767 void setOrderedSOCs(String oc) 768 throws NamingException 769 { 770 orderedSOCs.add(oc); 771 772 if (oc.equalsIgnoreCase("top")) return; 774 775 String parent = schema.schemaLookup("ClassDefinition/" + oc, "SUP"); 776 String struct = schema.schemaLookup("ClassDefinition/" + parent, "STRUCTURAL"); 777 if ("true".equalsIgnoreCase(struct) ) 779 { 780 setOrderedSOCs(parent); return; } 783 784 800 } 801 802 803 815 public boolean registerOID(String oid, String ldapName) 816 { 817 char test = oid.charAt(0); 819 if (test < '0' || test > '9') { 821 return false; 822 } 823 824 if (oid.endsWith(";binary")) oid = oid.substring(0,oid.indexOf(";binary")); 826 if (ldapName.endsWith(";binary")) ldapName = ldapName.substring(0,ldapName.indexOf(";binary")); 827 828 if (attOIDs.contains(oid)==true) return false; 829 attOIDs.put(oid, ldapName); return true; 831 } 832 833 837 838 public void removeEmptyAttributes() 839 { 840 Enumeration atts = getAll(); 841 while (atts.hasMoreElements()) 842 { 843 Attribute att = (Attribute)atts.nextElement(); 844 if (att.size() == 0) 845 remove(att.getID()); 846 } 847 } 848 849 850 851 852 866 867 public void expandAllAttributes() 868 { 869 if (schema == null) return; 870 871 Attribute oc = null; 872 oc = getAllObjectClasses(); 873 874 try 875 { 876 879 if (oc.contains(SchemaOps.SCHEMA_FAKE_OBJECT_CLASS_NAME) ) 880 return; 882 NamingEnumeration ocs = oc.getAll(); 883 884 while (ocs.hasMore()) 886 { 887 String objectClass = (String )ocs.next(); 888 Attributes ocAttrs = schema.getAttributes("ClassDefinition/" + objectClass); 889 Attribute mustAtt = ocAttrs.get("MUST"); Attribute mayAtt = ocAttrs.get("MAY"); 892 if (mustAtt != null) 893 { 894 NamingEnumeration musts = mustAtt.getAll(); 895 while (musts.hasMore()) 896 { 897 String attOID = (String ) musts.next(); 898 899 if (attOID.indexOf(";binary")>0) attOID = attOID.substring(0,attOID.indexOf(";binary")); 901 902 String ldapName = getldapName(attOID); 903 904 registerOID(attOID, ldapName); 905 if (get(ldapName)==null) { 907 put(new DXAttribute(getldapName(attOID))); } 910 911 if (must.contains(ldapName.toLowerCase())==false) { 913 must.add(ldapName.toLowerCase()); } 915 } 916 } 917 918 if (mayAtt != null) 919 { 920 NamingEnumeration mays = mayAtt.getAll(); 921 while (mays.hasMore()) 922 { 923 String attOID = (String ) mays.next(); 924 if (attOID.indexOf(";binary")>0) attOID = attOID.substring(0,attOID.indexOf(";binary")); 926 927 String ldapName = getldapName(attOID); 928 registerOID(attOID, ldapName); 929 930 if (get(ldapName)==null) { 932 put(new DXAttribute(getldapName(attOID))); } 935 } 936 } 937 } 938 } 939 catch (NamingException e) 940 { 941 log.log(Level.WARNING, "unable to read attribute list for object classes: ", e); 942 try 943 { 944 CBUtility.printEnumeration(oc.getAll()); 945 } 946 catch (NamingException e2) 947 { 948 log.warning("...(further error: can't print object class list)..."); 949 } 950 return; 951 } 952 catch (NullPointerException e) 953 { 954 log.log(Level.WARNING, "ERROR: unable to read list of object classes from schema - some functionality will not be available", e); 955 } 956 } 957 958 970 971 public String getldapName(String attOID) 972 { 973 return (schema==null?attOID:schema.translateOID(attOID)); 974 1017 } 1018 1019 public String toString() 1020 { 1021 StringBuffer text = new StringBuffer ("size (" + size() + ")\n"); 1022 1023 NamingEnumeration allatts = this.getAll(); 1024 while (allatts.hasMoreElements()) 1025 { 1026 Attribute fnord = (Attribute) allatts.nextElement(); 1027 if (fnord == null) 1028 log.warning("bizarre null attribute in element list"); 1029 else 1030 { 1031 if (must != null && must.contains(fnord.getID())) 1032 text.append("must "); 1033 1034 if (fnord instanceof DXAttribute) 1035 text.append(" dx ").append(((DXAttribute)fnord).toDebugString()).append(" "); 1036 else 1037 { 1038 String ID = fnord.getID(); 1039 text.append("\n " + ID + " (not DXAttribute)" ); 1040 try 1041 { 1042 if (fnord.size() == 0) 1043 text.append(" " + " (empty) "); 1044 else 1045 { 1046 Enumeration vals = fnord.getAll(); 1047 1048 while (vals.hasMoreElements()) 1049 { 1050 Object val = vals.nextElement(); 1051 String fnordel = (val==null)?"*null*":val.toString(); 1052 text.append(" '" + fnordel + "'"); 1053 } 1054 } 1055 } 1056 catch (NamingException e) 1057 { 1058 log.log(Level.WARNING, "whoops: Naming Exception reading " + ID, e); 1059 } 1060 } 1061 } 1062 } 1063 return text.toString(); 1064 } 1065 1066 public void print() { print(null); } 1067 1068 public void print(String msg) 1069 { 1070 if (msg!=null) System.out.println(msg); 1071 printAttributes(this); 1072 } 1073 1074 public static void printAttributes(Attributes a) 1075 { 1076 if (a==null) System.out.println("null attributes set"); 1077 NamingEnumeration allatts = a.getAll(); 1078 1079 printAttributeList(allatts); 1080 } 1081 1082 public static void printAttributeList(NamingEnumeration en) 1083 { 1084 while (en.hasMoreElements()) 1085 { 1086 Attribute fnord = (Attribute) en.nextElement(); 1087 if (fnord == null) 1088 log.warning("bizarre null attribute in element list"); 1089 else 1090 { 1091 String ID = fnord.getID(); 1092 System.out.println(" " + ID); 1093 try 1094 { 1095 Enumeration vals = fnord.getAll(); 1096 1097 while (vals.hasMoreElements()) 1098 { 1099 Object val = vals.nextElement(); 1100 String fnordel = (val==null)?"*null*":val.toString(); 1101 System.out.println(" " + fnordel); 1102 } 1103 } 1104 catch (NamingException e) 1105 { 1106 log.log(Level.WARNING, "whoops: Naming Exception reading " + ID, e); 1107 } 1108 } 1109 } 1110 } 1111 1112 1113 1114 1146 1147 public static DXAttributes getAdditionSet(RDN newRDN, Attributes oldSet, Attributes newSet) 1148 throws NamingException 1149 { 1150 DXAttributes additionSet = new DXAttributes(); 1151 NamingEnumeration listOfNewAttributes = newSet.getAll(); 1152 1153 while (listOfNewAttributes.hasMore()) 1154 { 1155 Attribute newAtt = (Attribute)listOfNewAttributes.next(); 1156 1157 String attributeName = newAtt.getID(); 1158 1159 boolean isNamingAttribute = newRDN.contains(attributeName); 1160 1161 Attribute oldAtt = oldSet.get(attributeName); 1162 1163 if (! emptyAtt(newAtt)) { 1165 1171 1172 if ((isNamingAttribute == false) && (oldAtt == null || emptyAtt(oldAtt))) 1173 { 1174 additionSet.put(newAtt); 1175 } 1176 1177 1181 1183 else if (isNamingAttribute || (oldAtt.size() > 1 || newAtt.size() > 1 )) 1184 { 1185 DXNamingEnumeration valuesToAdd = getMissingValues(oldAtt.getAll(), newAtt.getAll()); 1186 1187 if (isNamingAttribute) 1189 removeAnyDistinguishedValues(newRDN, attributeName, valuesToAdd); 1190 1191 if (valuesToAdd.size()>0) 1192 additionSet.put(new DXAttribute(attributeName, valuesToAdd)); 1193 } 1194 } 1195 } 1196 return additionSet; 1197 } 1198 1199 1200 1201 1221 1222 1224 public static DXAttributes getReplacementSet(RDN newRDN, Attributes oldSet, Attributes newSet) 1225 throws NamingException 1226 { 1227 DXAttributes replacementSet = new DXAttributes(); 1228 1229 NamingEnumeration listOfNewAttributes = newSet.getAll(); 1230 1231 while (listOfNewAttributes.hasMore()) { 1233 Attribute newAtt = (Attribute)listOfNewAttributes.next(); 1234 1235 if (newAtt != null && newAtt.size() == 1) { 1237 String attributeName = newAtt.getID(); 1238 1239 if (newRDN.contains(attributeName) == false) { 1241 Attribute oldAtt = oldSet.get(attributeName); 1242 1243 if (oldAtt != null && oldAtt.size() == 1) { 1245 if (attributesEqual(newAtt, oldAtt)==false) 1247 replacementSet.put(newAtt); 1248 } 1249 } 1250 } 1251 } 1252 return replacementSet; 1253 } 1254 1255 1256 1257 1275 1276 public static DXAttributes getDeletionSet(RDN newRDN, Attributes oldSet, Attributes newSet) 1277 throws NamingException 1278 { 1279 DXAttributes deletionSet = new DXAttributes(); 1280 1281 NamingEnumeration listOfOldAttributes = oldSet.getAll(); 1282 1283 while (listOfOldAttributes.hasMore()) 1284 { 1285 Attribute oldAtt = (Attribute)listOfOldAttributes.next(); 1286 1287 if (! emptyAtt(oldAtt)) { 1289 String attributeName = oldAtt.getID(); 1290 1291 boolean isNamingAttribute = newRDN.contains(attributeName); 1292 1293 Attribute newAtt = newSet.get(attributeName); 1294 1295 if (newAtt == null) 1296 newAtt = new DXAttribute(attributeName); 1297 1298 1301 1302 if (emptyAtt(newAtt) && !isNamingAttribute) 1303 { 1304 deletionSet.put(newAtt); 1305 } 1306 1307 1311 1312 else if (isNamingAttribute || oldAtt.size() > 1 || newAtt.size() > 1 ) 1313 { 1314 DXNamingEnumeration valuesToDelete = getMissingValues(newAtt.getAll(), oldAtt.getAll()); 1315 if (isNamingAttribute) 1317 removeAnyDistinguishedValues(newRDN, attributeName, valuesToDelete); 1318 1319 if (valuesToDelete.size()>0) 1320 deletionSet.put(new DXAttribute(attributeName, valuesToDelete)); 1321 } 1322 } 1323 } 1324 return deletionSet; 1325 } 1326 1327 1328 1329 1333 1334 private static boolean attributesEqual(Attribute a, Attribute b) 1335 throws NamingException 1336 { 1337 if (a == null && b == null) return true; 1339 if (a == null || b == null) return false; 1340 if (a.size() == 0 && b.size() == 0) return true; 1341 if (a.size() != b.size()) return false; 1342 if (a.get() == null && b.get() == null) return true; 1343 if (a.get() == null || b.get() == null) return false; 1344 if (a.getID().equalsIgnoreCase(b.getID())==false) return false; 1345 1346 1347 try 1348 { 1349 Object [] A = CBArray.enumerationToArray(a.getAll()); 1350 Object [] B = CBArray.enumerationToArray(b.getAll()); 1351 return CBArray.isUnorderedEqual(A,B); 1352 } 1353 catch (NamingException e) 1354 { 1355 log.log(Level.WARNING, "Naming Exception testing attributes " + a.getID() + " & " + b.getID() + " in DXAttributes:attributesEqual()", e); 1356 } 1357 return false; } 1359 1360 1363 1364 public static boolean attributesEqual(Attributes a, Attributes b) 1365 { 1366 if (a == null && b == null) return true; 1367 if (a == null || b == null) return false; 1368 return a.equals(b); 1369 } 1370 1371 public boolean equals(Object o) 1372 { 1373 if (o == null) return false; 1374 1375 try 1376 { 1377 if (o instanceof Attributes) 1378 return this.equals((Attributes) o); 1379 } 1380 catch (NamingException e) 1381 { 1382 return false; } 1384 1385 return false; 1386 } 1387 1388 public boolean equals(Attributes atts) throws NamingException 1389 { 1390 if (atts == null) return false; 1392 if (size() == 0 && atts.size() == 0) return true; 1393 if (size() != atts.size()) return false; 1394 1395 1397 NamingEnumeration testAtts = getAll(); 1398 while (testAtts.hasMore()) { 1400 Attribute testAtt = (Attribute)testAtts.next(); 1401 String ID = testAtt.getID(); 1402 1403 Attribute bAtt = atts.get(ID); 1404 1405 if ( emptyAtt(bAtt) ^ emptyAtt(testAtt) ) return false; 1406 1407 if (attributesEqual(testAtt, bAtt) == false) return false; 1408 } 1409 1410 1412 return true; 1413 } 1414 1415 1422 1423 private static void removeAnyDistinguishedValues(RDN newRDN, String attributeName, DXNamingEnumeration values) 1424 { 1425 String distinguishedValue = newRDN.getRawVal(attributeName); 1426 values.remove(distinguishedValue); } 1428 1429 1430 1436 1437 static private DXNamingEnumeration getMissingValues(NamingEnumeration A, NamingEnumeration B) 1438 throws NamingException 1439 { 1440 DXNamingEnumeration ret = new DXNamingEnumeration(B); 1441 1442 if (A == null) return ret; 1443 1444 while (A.hasMore()) 1445 { 1446 ret.remove(A.next()); 1447 } 1448 return ret; 1449 } 1450 1451 1453 public String [] toIDStringArray() 1454 { 1455 DXNamingEnumeration ret = new DXNamingEnumeration(getIDs()); 1456 return ret.toStringArray(); 1457 } 1458 1459 1463 public boolean hasOIDs() 1464 { 1465 return (attOIDs.size()>0); 1466 } 1467 1468 1472 public static boolean emptyAtt(Attribute att) 1473 { 1474 return DXAttribute.isEmpty(att); 1475 } 1476 1477 1478 1479} | Popular Tags |