View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/infomodel/RegistryObjectImpl.java,v 1.60 2003/09/13 19:43:54 farrukh_najmi Exp $ 3 * 4 * 5 */ 6 7 package com.sun.xml.registry.ebxml.infomodel; 8 9 import javax.xml.registry.*; 10 import javax.xml.registry.infomodel.*; 11 import java.util.*; 12 13 import com.sun.xml.registry.ebxml.*; 14 import com.sun.xml.registry.ebxml.util.*; 15 16 import org.oasis.ebxml.registry.bindings.rim.RegistryObjectType; 17 import org.oasis.ebxml.registry.bindings.rim.ClassificationType; 18 import org.oasis.ebxml.registry.bindings.rim.ExternalIdentifierType; 19 20 import org.apache.commons.logging.Log; 21 22 23 /*** 24 * Class Declaration for Class1 25 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 26 */ 27 public abstract class RegistryObjectImpl extends ExtensibleObjectImpl 28 implements RegistryObject 29 { 30 private Key key = null; 31 private InternationalString description = null; 32 protected InternationalString name = null; 33 34 /*** The ObjectType Concept value represented as a String */ 35 protected String objectTypeStr; 36 protected Concept objectType; 37 38 /*** Composed objects */ 39 protected Collection classifications = new ArrayList(); 40 protected Collection externalIds = new ArrayList(); 41 42 /*** Even though in JAXR Association-s are non-composed objects, their 43 save behavior should be similar to composed objects. */ 44 protected Collection associations = null; 45 46 //Following are collection of non-composed objects that are cached by this 47 //implementation for performance efficiency. They are initialized on first access. 48 protected HashSet externalLinks = null; 49 protected Collection packages = null; 50 protected Collection auditTrail = null; 51 52 //Replace with functions to save memory later?? 53 protected DeclarativeQueryManagerImpl dqm = null; 54 protected BusinessQueryManagerImpl bqm = null; 55 56 private Organization org = null; 57 58 RegistryObjectImpl(LifeCycleManagerImpl lcm) 59 throws JAXRException 60 { 61 super(lcm); 62 63 dqm = (DeclarativeQueryManagerImpl)(lcm.getRegistryService().getDeclarativeQueryManager()); 64 bqm = (BusinessQueryManagerImpl)(lcm.getRegistryService().getBusinessQueryManager()); 65 66 //Assign default key 67 key = lcm.createKey(); 68 69 String str = getClass().getName(); 70 objectTypeStr = str.substring(str.lastIndexOf('.')+1, 71 str.length()-4); 72 } 73 74 RegistryObjectImpl(LifeCycleManagerImpl lcm, 75 RegistryObjectType ebObject) 76 throws JAXRException 77 { 78 // Pass ebObject to superclass so slot-s can be initialized 79 super(lcm, ebObject); 80 81 dqm = (DeclarativeQueryManagerImpl)(lcm.getRegistryService().getDeclarativeQueryManager()); 82 bqm = (BusinessQueryManagerImpl)(lcm.getRegistryService().getBusinessQueryManager()); 83 key = new KeyImpl(lcm); 84 key.setId(ebObject.getId()); 85 86 if (ebObject.getName() != null) { 87 name = new InternationalStringImpl(lcm, ebObject.getName()); 88 } 89 90 if (ebObject.getDescription() != null) { 91 description = new InternationalStringImpl( 92 lcm, ebObject.getDescription()); 93 } 94 95 ClassificationType[] ebClasses = ebObject.getClassification(); 96 for (int i = 0; i < ebClasses.length; i++) { 97 internalAddClassification(new ClassificationImpl(lcm, ebClasses[i], this)); 98 } 99 100 ExternalIdentifierType[] extIds = ebObject.getExternalIdentifier(); 101 for (int i = 0; i < extIds.length; i++) { 102 // XXX Finish this by passing in extIds[i] 103 internalAddExternalIdentifier(new ExternalIdentifierImpl(lcm, extIds[i], this)); 104 } 105 106 String ebObjectType = ebObject.getObjectType(); 107 objectTypeStr = (ebObjectType == null) ? "Unknown" : ebObjectType; 108 109 // XXX Finish these attrbutes: 110 ebObject.getAccessControlPolicy(); 111 } 112 113 /*** 114 * Implementation private 115 */ 116 public void setModified(boolean modified) { 117 super.setModified(modified); 118 if (modified == true) { 119 lcm.addModifiedObject(this); 120 } 121 else { 122 lcm.removeModifiedObject(this); 123 } 124 } 125 126 127 public Concept getObjectType() throws JAXRException { 128 129 if (objectType == null) { 130 if (objectTypeStr.startsWith("urn:uuid:")) { 131 RegistryObject ro = dqm.getRegistryObject(objectTypeStr, LifeCycleManager.CONCEPT); 132 if (ro instanceof Concept) { 133 objectType = (Concept)ro; 134 } 135 } 136 137 if (objectType == null) { 138 String jaxrInterfaceName = getClass().getName(); 139 jaxrInterfaceName = jaxrInterfaceName.substring(jaxrInterfaceName.lastIndexOf(".")+1); 140 if (jaxrInterfaceName.endsWith("Impl")) { 141 //Remove Impl suffix for JAXR provider Impl classes 142 jaxrInterfaceName = jaxrInterfaceName.substring(0, jaxrInterfaceName.length() -4); 143 } 144 145 objectType = (Concept)(lcm.getObjectTypesMap().get(jaxrInterfaceName)); 146 } 147 } 148 return objectType; 149 } 150 151 public abstract String toXML() throws JAXRException; 152 153 public Key getKey() throws JAXRException { 154 return key; 155 } 156 157 /*** 158 * Do we add this to the API?? 159 */ 160 public String getId() throws JAXRException { 161 return key.getId(); 162 } 163 164 public InternationalString getDescription() throws JAXRException { 165 if (description == null) { 166 description = lcm.createInternationalString(""); 167 } 168 return description; 169 } 170 171 public void setDescription(InternationalString desc) throws JAXRException { 172 description = desc; 173 setModified(true); 174 } 175 176 public InternationalString getName() throws JAXRException { 177 if (name == null) { 178 name = lcm.createInternationalString(""); 179 } 180 return name; 181 } 182 183 public void setName(InternationalString name) throws JAXRException { 184 this.name = name; 185 setModified(true); 186 } 187 188 public void setKey(Key key) throws JAXRException { 189 this.key = key; 190 setModified(true); 191 } 192 193 /*** Internal method, does not set modified flag. */ 194 private void internalAddClassification(Classification c) throws JAXRException { 195 getClassifications().add(c); 196 c.setClassifiedObject(this); 197 } 198 199 public void addClassification(Classification c) throws JAXRException { 200 internalAddClassification(c); 201 setModified(true); 202 } 203 204 public void addClassifications(Collection classifications) throws JAXRException { 205 Iterator iter = classifications.iterator(); 206 while (iter.hasNext()) { 207 Classification cls = (Classification)iter.next(); 208 internalAddClassification(cls); 209 } 210 setModified(true); 211 } 212 213 public void removeClassification(Classification c) throws JAXRException { 214 if (classifications != null) { 215 getClassifications().remove(c); 216 setModified(true); 217 } 218 } 219 220 public void removeClassifications(Collection classifications) throws JAXRException { 221 if (classifications != null) { 222 getClassifications().removeAll(classifications); 223 setModified(true); 224 } 225 } 226 227 //??Add to JAXR 2.0. Apply same pattern to all Collection attributes in RIM. 228 public void removeAllClassifications() throws JAXRException { 229 if (classifications != null) { 230 removeClassifications(classifications); 231 setModified(true); 232 } 233 } 234 235 public void setClassifications(Collection classifications) throws JAXRException { 236 removeAllClassifications(); 237 238 addClassifications(classifications); 239 setModified(true); 240 } 241 242 public Collection getClassifications() throws JAXRException { 243 if (classifications == null) { 244 classifications = new ArrayList(); 245 } 246 return classifications; 247 } 248 249 /*** 250 * Gets all Concepts classifying this object that have specified path as prefix. 251 * Used in RegistryObjectsTableModel.getValueAt via reflections API if so configured. 252 */ 253 public Collection getClassificationConceptsByPath(String pathPrefix) throws JAXRException { 254 Collection matchingClassificationConcepts = new ArrayList(); 255 Collection _classifications = getClassifications(); 256 Iterator iter = _classifications.iterator(); 257 while (iter.hasNext()) { 258 Classification cl = (Classification)iter.next(); 259 Concept concept = cl.getConcept(); 260 String conceptPath = concept.getPath(); 261 if (conceptPath.startsWith(pathPrefix)) { 262 matchingClassificationConcepts.add(concept); 263 } 264 } 265 return matchingClassificationConcepts; 266 } 267 268 public Collection getAuditTrail() throws JAXRException { 269 if (auditTrail == null) { 270 if (!isNew()) { 271 String queryStr = "SELECT id FROM AuditableEvent WHERE registryObject = '" + getKey().getId() + "'"; 272 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr); 273 BulkResponse response = dqm.executeQuery(query); 274 275 checkBulkResponseExceptions(response); 276 auditTrail = response.getCollection(); 277 } 278 279 if (auditTrail == null) { 280 auditTrail = new ArrayList(); 281 } 282 } 283 284 return auditTrail; 285 } 286 287 /*** 288 * Do we add this to the API?? 289 * 290 * @return owner, ie. creator or null if this is a new object 291 */ 292 public User getOwner() throws JAXRException { 293 if (!isNew()) { 294 // Ask server who our creator is 295 Collection events = getAuditTrail(); 296 for (Iterator it = events.iterator(); it.hasNext(); ) { 297 AuditableEventImpl ev = (AuditableEventImpl)it.next(); 298 if (ev.getEventType() == AuditableEvent.EVENT_TYPE_CREATED) { 299 return ev.getUser(); 300 } 301 } 302 } 303 return null; 304 } 305 306 public void addAssociation(Association ass) throws JAXRException { 307 getAssociations(); 308 if (!(associations.contains(ass))) { 309 associations.add(ass); 310 } 311 ((AssociationImpl)ass).setSourceObjectInternal(this); 312 } 313 314 public void addAssociations(Collection asses) throws JAXRException { 315 for (Iterator it = asses.iterator(); it.hasNext(); ) { 316 Association ass = (Association)it.next(); 317 addAssociation(ass); 318 } 319 } 320 321 public void removeAssociation(Association ass) throws JAXRException { 322 getAssociations(); 323 if (associations.contains(ass)) { 324 associations.remove(ass); 325 326 //Need to mark as deleted and only remove from server on Save in future. 327 //For now leaving as is in order to minimize change.??? 328 // Remove from server only if Association exists there 329 if (!((AssociationImpl)ass).isNew()) { 330 // assert(Association must exist on server) 331 ArrayList keys = new ArrayList(); 332 keys.add(ass.getKey()); 333 BulkResponse response = lcm.deleteObjects(keys); 334 JAXRException ex = getBulkResponseException(response); 335 if (ex != null) { 336 throw ex; 337 } 338 } 339 //No need to call setModified(true) since RIM modified object is an Assoociation 340 //setModified(true); 341 } 342 } 343 344 public void removeAssociations(Collection asses) throws JAXRException { 345 Collection savedAsses = getAssociations(); 346 if (associations.removeAll(asses)) { 347 // Remove from server only if Association exists there 348 ArrayList keys = new ArrayList(); 349 for (Iterator it = asses.iterator(); it.hasNext(); ) { 350 AssociationImpl ass = (AssociationImpl)it.next(); 351 if (!ass.isNew()) { 352 // assert(Association must exist on server) 353 keys.add(ass.getKey()); 354 } 355 } 356 BulkResponse response = lcm.deleteObjects(keys); 357 JAXRException ex = getBulkResponseException(response); 358 if (ex != null) { 359 // Undo remove 360 // ??eeg Assumes all-or-nothing delete 361 associations = savedAsses; 362 throw ex; 363 } 364 } 365 } 366 367 public void setAssociations(Collection asses) throws JAXRException { 368 // We make a copy of this.associations to avoid a 369 // concurrent modification exception 370 removeAssociations((Collection)new ArrayList(getAssociations())); 371 addAssociations(asses); 372 } 373 374 public Collection getAssociations() throws JAXRException { 375 if (associations == null) { 376 associations = new HashSet(); 377 378 //If existing object then now is the time to do lazy fetch from server 379 if (!isNew()) { 380 // Return Collection from server 381 String id = getKey().getId(); 382 String queryStr = "SELECT id FROM Association WHERE sourceObject = '" + id + "'"; 383 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr); 384 BulkResponse response = dqm.executeQuery(query); 385 checkBulkResponseExceptions(response); 386 addAssociations(response.getCollection()); 387 } 388 } 389 return associations; 390 } 391 392 public Collection getAssociatedObjects() throws JAXRException { 393 if (isNew()) { 394 // ??eeg Still can have client side associated objects! 395 // Return an empty Collection instead of null 396 return new ArrayList(); 397 } 398 399 String id = getKey().getId(); 400 String queryStr = 401 "SELECT id FROM Association WHERE sourceObject = '" + id + 402 "' OR targetObject = '" + id + "'"; 403 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr); 404 BulkResponse response = dqm.executeQuery(query); 405 checkBulkResponseExceptions(response); 406 return response.getCollection(); 407 } 408 409 /*** Internal method, does not set modified flag. */ 410 private void internalAddExternalIdentifier(ExternalIdentifier ei) throws JAXRException { 411 getExternalIdentifiers().add(ei); 412 } 413 414 public void addExternalIdentifier(ExternalIdentifier ei) throws JAXRException { 415 internalAddExternalIdentifier(ei); 416 setModified(true); 417 } 418 419 public void addExternalIdentifiers(Collection extLink) throws JAXRException { 420 getExternalIdentifiers().add(extLink); 421 setModified(true); 422 } 423 424 public void removeExternalIdentifier(ExternalIdentifier extLink) throws JAXRException { 425 if (externalIds != null) { 426 externalIds.remove(extLink); 427 setModified(true); 428 } 429 } 430 431 public void removeExternalIdentifiers(Collection extLink) throws JAXRException { 432 if (externalIds != null) { 433 externalIds.removeAll(extLink); 434 setModified(true); 435 } 436 } 437 438 public void setExternalIdentifiers(Collection extLink) throws JAXRException { 439 externalIds = extLink; 440 setModified(true); 441 } 442 443 public Collection getExternalIdentifiers() throws JAXRException { 444 if (externalIds == null) { 445 externalIds = new ArrayList(); 446 } 447 return externalIds; 448 } 449 450 public void addExternalLink(ExternalLink extLink) throws JAXRException { 451 452 getExternalLinks(); 453 454 // If the external link is not in this object's in-memory-cache of 455 // external links, add it. 456 if (!(externalLinks.contains(extLink))) { 457 458 // Check that an ExternallyLinks association exists between this 459 // object and its external link. 460 boolean associationExists = false; 461 BusinessQueryManagerImpl bqm = 462 (BusinessQueryManagerImpl)(lcm.getRegistryService().getBusinessQueryManager()); 463 Concept assocType = 464 bqm.findConceptByPath("/urn:uuid:6902675f-2f18-44b8-888b-c91db8b96b4d/" + 465 AssociationImpl.ASSOCIATION_TYPE_EXTERNALLY_LINKS); 466 Collection linkAssociations = extLink.getAssociations(); 467 if (linkAssociations != null) { 468 Iterator assIter = linkAssociations.iterator(); 469 while (assIter.hasNext()) { 470 Association ass = (Association)assIter.next(); 471 if (ass.getSourceObject().equals(extLink) && 472 ass.getTargetObject().equals(this) && 473 ass.getAssociationType().equals(assocType)) 474 { 475 associationExists = true; 476 break; 477 } 478 } 479 } 480 481 // Create the association between the external link and this object, 482 // if necessary. 483 if (!associationExists) { 484 Association ass = lcm.createAssociation(this, assocType); 485 extLink.addAssociation(ass); 486 } 487 488 externalLinks.add(extLink); 489 490 // Note: There is no need to call setModified(true) since 491 // the RIM modified object is an Association 492 } 493 } 494 495 public void addExternalLinks(Collection extLinks) throws JAXRException { 496 Iterator iter = extLinks.iterator(); 497 while (iter.hasNext()) { 498 ExternalLink extLink = (ExternalLink)iter.next(); 499 addExternalLink(extLink); 500 } 501 //No need to call setModified(true) since RIM modified object is an Assoociation 502 } 503 504 public void removeExternalLink(ExternalLink extLink) throws JAXRException { 505 getExternalLinks(); 506 if (externalLinks.contains(extLink)) { 507 externalLinks.remove(extLink); 508 509 //Now remove the ExternallyLinks association that has extLink as src and this object as target 510 // We make a copy of this.externalLinks to avoid a 511 // concurrent modification exception in the removeExternalLinks 512 Collection linkAssociations = new ArrayList(extLink.getAssociations()); 513 if (linkAssociations != null) { 514 Iterator iter = linkAssociations.iterator(); 515 while (iter.hasNext()) { 516 Association ass = (Association)iter.next(); 517 if (ass.getTargetObject() == this) { 518 if (ass.getAssociationType().getValue().equalsIgnoreCase(AssociationImpl.ASSOCIATION_TYPE_EXTERNALLY_LINKS)) { 519 extLink.removeAssociation(ass); 520 } 521 } 522 } 523 } 524 //No need to call setModified(true) since RIM modified object is an Assoociation 525 //setModified(true); 526 } 527 } 528 529 public void removeExternalLinks(Collection extLinks) throws JAXRException { 530 getExternalLinks(); 531 Iterator iter = extLinks.iterator(); 532 while (iter.hasNext()) { 533 ExternalLink extLink = (ExternalLink)iter.next(); 534 removeExternalLink(extLink); 535 } 536 //No need to call setModified(true) since RIM modified object is an Assoociation } 537 } 538 539 /*** Set this object's list of external links to the list specified. If the 540 * current list of external links contains links that are not in the specified 541 * list, they will be removed and the association between them and this object 542 * will be removed from the server. For any external links that are in the 543 * list specified, an association will be created (in-memory, not on the 544 * server) and they will be added to this object's list of external links. 545 * 546 * @param newExternalLinks 547 * A Collection of ExternalLink objects. 548 * @throws JAXRException 549 */ 550 public void setExternalLinks(Collection newExternalLinks) throws JAXRException { 551 552 Collection currentExternalLinks = getExternalLinks(); 553 554 // Add any external links that are not currently in this object's list. 555 Iterator newExtLinksIter = newExternalLinks.iterator(); 556 while (newExtLinksIter.hasNext()) { 557 ExternalLink externalLink = (ExternalLink)newExtLinksIter.next(); 558 if (!currentExternalLinks.contains(externalLink)) { 559 addExternalLink(externalLink); 560 } 561 } 562 563 // Remove any external links that are currently in this object's list, 564 // but are not in the new list. 565 Iterator currentExtLinksIter = currentExternalLinks.iterator(); 566 while (currentExtLinksIter.hasNext()) { 567 ExternalLink externalLink = (ExternalLink)currentExtLinksIter.next(); 568 if (!newExternalLinks.contains(externalLink)) { 569 removeExternalLink(externalLink); 570 } 571 } 572 } 573 574 public Collection getExternalLinks() throws JAXRException { 575 576 if (externalLinks == null) { 577 externalLinks = new HashSet(); 578 579 //If existing object then now is the time to do lazy fetch from server 580 if (!isNew()) { 581 String id = getId(); 582 String queryStr = 583 "SELECT id FROM ExternalLink el, Association ass WHERE ass.targetObject = '" + id + 584 "' AND ass.associationType = '" + AssociationImpl.CANONICAL_ID_NODE_ASSOCIATION_TYPE_EXTERNALLY_LINKS + 585 "' AND ass.sourceObject = el.id "; 586 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr); 587 588 BulkResponse response = dqm.executeQuery(query); 589 checkBulkResponseExceptions(response); 590 addExternalLinks(response.getCollection()); 591 } 592 } 593 594 return externalLinks; 595 } 596 597 598 public Organization getSubmittingOrganization() throws JAXRException { 599 return org; 600 } 601 602 public Collection getRegistryPackages() throws JAXRException { 603 <b>if (packages == null) { 604 if (!isNew()) { 605 String queryStr = "SELECT id FROM RegistryPackage WHERE id IN (RegistryObject_registryPackages('" + getKey().getId() + "'))"; 606 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, queryStr); 607 BulkResponse response = dqm.executeQuery(query); 608 checkBulkResponseExceptions(response); 609 packages = response.getCollection(); 610 } 611 612 if (packages == null) { 613 packages = new ArrayList(); 614 } 615 } 616 return packages; 617 } 618 619 protected void setBindingObject(org.oasis.ebxml.registry.bindings.rim.RegistryObjectType ebObject) throws JAXRException { 620 // Pass ebObject to superclass so slot-s can be initialized 621 super.setBindingObject(ebObject); 622 623 ebObject.setId(key.getId()); 624 ebObject.setObjectType(objectTypeStr); 625 626 org.oasis.ebxml.registry.bindings.rim.Name ebName = 627 new org.oasis.ebxml.registry.bindings.rim.Name(); 628 ((InternationalStringImpl)getName()).setBindingObject(ebName); 629 ebObject.setName(ebName); 630 631 org.oasis.ebxml.registry.bindings.rim.Description ebDesc = 632 new org.oasis.ebxml.registry.bindings.rim.Description(); 633 ((InternationalStringImpl)getDescription()).setBindingObject(ebDesc); 634 ebObject.setDescription(ebDesc); 635 636 Iterator iter = getClassifications().iterator(); 637 while (iter.hasNext()) { 638 ClassificationImpl cls = (ClassificationImpl)iter.next(); 639 org.oasis.ebxml.registry.bindings.rim.Classification ebCls = cls.toBindingObject(); 640 ebObject.addClassification(ebCls); 641 } 642 643 iter = getExternalIdentifiers().iterator(); 644 while (iter.hasNext()) { 645 ExternalIdentifierImpl extId = (ExternalIdentifierImpl)iter.next(); 646 org.oasis.ebxml.registry.bindings.rim.ExternalIdentifier ebExtId = extId.toBindingObject(); 647 ebObject.addExternalIdentifier(ebExtId); 648 } 649 } 650 651 public void getComposedObjects(HashSet composedObjects) 652 throws JAXRException 653 { 654 Log log = getLog(); 655 super.getComposedObjects(composedObjects); 656 //log.debug("getComposedObject slots" + this + " composedObjects = " + composedObjects); 657 658 Collection classifications = getClassifications(); 659 composedObjects.addAll(classifications); 660 Iterator iter = classifications.iterator(); 661 while (iter.hasNext()) { 662 ClassificationImpl cls = (ClassificationImpl)iter.next(); 663 cls.getComposedObjects(composedObjects); 664 } 665 //log.debug("getComposedObject classifications" + this + " composedObjects = " + composedObjects); 666 667 Collection extIds = getExternalIdentifiers(); 668 composedObjects.addAll(extIds); 669 iter = extIds.iterator(); 670 while (iter.hasNext()) { 671 ExternalIdentifierImpl extId = (ExternalIdentifierImpl)iter.next(); 672 extId.getComposedObjects(composedObjects); 673 } 674 //log.debug("getComposedObject externalIdentifiers" + this + " composedObjects = " + composedObjects); 675 676 } 677 678 public LifeCycleManager getLifeCycleManager() throws JAXRException { 679 return lcm; 680 } 681 682 /*** 683 * @return First exception in BulkResponse if there is one else null 684 */ 685 RegistryException getBulkResponseException(BulkResponse response) 686 throws JAXRException 687 { 688 Collection exceptions = response.getExceptions(); 689 if (exceptions != null) { 690 return (RegistryException)exceptions.iterator().next(); 691 } 692 return null; 693 } 694 695 /*** 696 * Throw first exception in BulkResponse if there is one else return 697 */ 698 void checkBulkResponseExceptions(BulkResponse response) 699 throws JAXRException 700 { 701 RegistryException ex = getBulkResponseException(response); 702 if (ex != null) { 703 throw ex; 704 } 705 return; 706 } 707 708 /*** 709 * Gest all Associations and their targets for which this object is a source. 710 * Used by LifeCycleManagerImpl.saveObjects 711 * 712 */ 713 public HashSet getAssociationsAndAssociatedObjects() throws JAXRException { 714 HashSet assObjects = new HashSet(); 715 716 // Automatically save any Association-s with an object in the save 717 // list along with the target object of the Association per JAXR 1.0 spec. 718 Collection asses = getAssociations(); 719 720 // Add the Association targets 721 for (Iterator j = asses.iterator(); j.hasNext(); ) { 722 AssociationImpl ass = (AssociationImpl)j.next(); 723 RegistryObject target = ass.getTargetObject(); 724 assObjects.add(target); 725 } 726 727 // Add also the Association-s themselves 728 assObjects.addAll(asses); 729 730 return assObjects; 731 } 732 733 734 735 /*** 736 * Gets all referenced objects for which this object is a referant. 737 * Extended by base classes. 738 * Used by LifeCycleManagerImpl.saveObjects 739 * 740 */ 741 public HashSet getRegistryObjectRefs() { 742 HashSet refs = new HashSet(); 743 744 return refs; 745 } 746 747 public String toString() { 748 String str = super.toString(); 749 try { 750 str = getId() + "," + str; 751 } 752 catch (JAXRException e) { 753 try { 754 getLog().warn("Error getting id", e); 755 } 756 catch (JAXRException e1) { 757 } 758 } 759 760 return str; 761 } 762 763 /*** Returns true if the object specified is a RegistryObjectImpl 764 * with the same id. 765 * 766 * @param o 767 * The object to compare to. 768 * @return 769 * <code>true</code> if the objects are equal. 770 * @todo 771 * Do we need to ensure the object is the same type as this 772 * instance? For example, this instance could be a ServiceImpl 773 * and the object could be an ExternalLinkImpl. Could these have 774 * the same id? 775 */ 776 public boolean equals(Object o) { 777 if (compareTo(o) == 0) { 778 return true; 779 } 780 else { 781 return false; 782 } 783 } 784 785 /*** 786 * Compares two registries objects. 787 * Consider adding Coparable to RegistryObject in JAXR 2.0?? 788 * 789 * @return 0 (equal) is the id of the objects matches this objects id. 790 * Otherwise return -1 (this object is less than arg o). 791 */ 792 public int compareTo(Object o) { 793 int result = -1; 794 795 if (o instanceof RegistryObject) { 796 try { 797 String myId = getId(); 798 String otherId = ((RegistryObject)o).getKey().getId(); 799 result = myId.compareTo(otherId); 800 } 801 catch (JAXRException e) { 802 e.printStackTrace(); 803 } 804 } 805 806 return result; 807 } 808 809 protected Log getLog() throws JAXRException { 810 Log log = ((RegistryServiceImpl)(lcm.getRegistryService())).getConnection().getConnectionFactory().getLog(); 811 return log; 812 } 813 814 }

This page was automatically generated by Maven