View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/infomodel/RegistryObjectRef.java,v 1.13 2003/07/23 01:14:51 farrukh_najmi Exp $ 3 * 4 * 5 */ 6 7 package com.sun.xml.registry.ebxml.infomodel; 8 9 import java.lang.ref.*; 10 11 import com.sun.xml.registry.ebxml.*; 12 import javax.xml.registry.*; 13 import javax.xml.registry.infomodel.*; 14 15 import org.oasis.ebxml.registry.bindings.rim.ObjectRef; 16 import org.oasis.ebxml.registry.bindings.rim.RegistryObjectType; 17 18 import org.apache.commons.logging.Log; 19 20 /*** 21 * Holds a direct or indirect reference to a RegistryObject 22 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 23 */ 24 public class RegistryObjectRef { 25 26 private LifeCycleManagerImpl lcm = null; 27 private String id = null; 28 private Reference ref = null; 29 30 public String getId() throws JAXRException { 31 return id; 32 } 33 34 private RegistryObjectRef() { 35 } 36 37 RegistryObjectRef(LifeCycleManagerImpl lcm, Object obj) throws JAXRException { 38 if (obj instanceof RegistryObject) { 39 init(lcm, (RegistryObject)obj); 40 } 41 else if (obj instanceof RegistryObjectType) { 42 init(lcm, (RegistryObjectType)obj); 43 } 44 else if (obj instanceof ObjectRef) { 45 init(lcm, (ObjectRef)obj); 46 } 47 else { 48 JAXRException e = new JAXRException("Unexpected object: " + obj); 49 e.printStackTrace(); 50 throw e; 51 } 52 } 53 54 RegistryObjectRef(LifeCycleManagerImpl lcm, RegistryObject ro) throws JAXRException { 55 init(lcm, ro); 56 } 57 58 RegistryObjectRef(LifeCycleManagerImpl lcm, RegistryObjectType ro) throws JAXRException { 59 init(lcm, ro.getId()); 60 } 61 62 RegistryObjectRef(LifeCycleManagerImpl lcm, ObjectRef or) throws JAXRException { 63 init(lcm, or.getId()); 64 } 65 66 RegistryObjectRef(LifeCycleManagerImpl lcm, String id) throws JAXRException { 67 init(lcm, id); 68 } 69 70 private void init(LifeCycleManagerImpl lcm, RegistryObject ro) throws JAXRException { 71 init(lcm, ro.getKey().getId()); 72 ((RegistryServiceImpl)lcm.getRegistryService()).getObjectCache().putRegistryObject(ro); 73 } 74 75 private void init(LifeCycleManagerImpl lcm, RegistryObjectType ro) throws JAXRException { 76 init(lcm, ro.getId()); 77 } 78 79 private void init(LifeCycleManagerImpl lcm, ObjectRef or) throws JAXRException { 80 init(lcm, or.getId()); 81 } 82 83 private void init(LifeCycleManagerImpl lcm, String id) throws JAXRException { 84 this.lcm = lcm; 85 this.id = id; 86 87 if (id == null) { 88 throw new JAXRException("Cannot create ref with id null"); 89 } 90 ref = null; 91 } 92 93 94 95 public Reference getReference(String objectType) throws JAXRException { 96 97 //Need to also check if ref.get() == null as referrant could have been GCed 98 if ((ref == null) || (ref.get() == null)) { 99 ref = ((RegistryServiceImpl)lcm.getRegistryService()).getObjectCache().getReference(id, objectType); 100 } 101 102 return ref; 103 } 104 105 public RegistryObject getRegistryObject(String objectType) throws JAXRException { 106 RegistryObject ro = null; 107 Reference ref = null; 108 try { 109 ref = getReference(objectType); 110 ro = (RegistryObject)(ref.get()); 111 } 112 catch (JAXRException e) { //Doing the call again to help debug 113 ref = getReference(objectType); 114 } 115 116 return ro; 117 } 118 119 public String toString() { 120 String str = super.toString(); 121 try { 122 str = getId() + "," + str; 123 } 124 catch (JAXRException e) { 125 try { 126 getLog().warn("Error getting id", e); 127 } 128 catch (JAXRException e1) { 129 } 130 } 131 132 return str; 133 } 134 135 protected Log getLog() throws JAXRException { 136 Log log = ((RegistryServiceImpl)(lcm.getRegistryService())).getConnection().getConnectionFactory().getLog(); 137 return log; 138 } 139 140 141 }

This page was automatically generated by Maven