View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/infomodel/ServiceBindingImpl.java,v 1.14 2003/07/23 01:20:18 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 import java.io.*; 13 14 import com.sun.xml.registry.ebxml.LifeCycleManagerImpl; 15 16 import org.oasis.ebxml.registry.bindings.rim.ServiceType; 17 import org.oasis.ebxml.registry.bindings.rim.ServiceBindingType; 18 import org.oasis.ebxml.registry.bindings.rim.SpecificationLinkType; 19 import org.oasis.ebxml.registry.bindings.rim.ObjectRef; 20 21 /*** 22 * Class Declaration for Class1 23 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 24 */ 25 public class ServiceBindingImpl extends RegistryObjectImpl 26 implements ServiceBinding { 27 private RegistryObjectRef serviceRef = null; 28 private String accessURI = null; 29 30 private RegistryObjectRef targetBindingRef = null; 31 private HashSet specLinks = new HashSet(); 32 private boolean validateURI = true; 33 34 public ServiceBindingImpl(LifeCycleManagerImpl lcm) 35 throws JAXRException { 36 super(lcm); 37 } 38 39 public ServiceBindingImpl(LifeCycleManagerImpl lcm, ServiceBindingType ebBinding) 40 throws JAXRException { 41 super(lcm, ebBinding); 42 43 serviceRef = new RegistryObjectRef(lcm, ebBinding.getService()); 44 45 accessURI = ebBinding.getAccessURI(); 46 47 Object targetBindingObj = ebBinding.getTargetBinding(); 48 if (targetBindingObj != null) { 49 targetBindingRef = new RegistryObjectRef(lcm, targetBindingObj); 50 } 51 52 SpecificationLinkType[] ebSpecLinks = ebBinding.getSpecificationLink(); 53 for (int i = 0; i < ebSpecLinks.length; i++) { 54 addSpecificationLink(new SpecificationLinkImpl(lcm, ebSpecLinks[i])); 55 } 56 } 57 58 public String toXML() throws JAXRException { 59 org.oasis.ebxml.registry.bindings.rim.RegistryObjectType ebObj = toBindingObject(); 60 StringWriter sw = new StringWriter(); 61 try { 62 ebObj.marshal(sw); 63 } catch (org.exolab.castor.xml.MarshalException x) { 64 throw new JAXRException(x); 65 } catch (org.exolab.castor.xml.ValidationException x) { 66 throw new JAXRException(x); 67 } 68 return sw.toString(); 69 } 70 71 public String getAccessURI() throws JAXRException { 72 return accessURI; 73 } 74 75 public void setAccessURI(String par1) throws JAXRException { 76 accessURI = par1; 77 setModified(true); 78 } 79 80 //??JAXR 2.0 81 public RegistryObjectRef getTargetBindingRef() throws JAXRException { 82 return targetBindingRef; 83 } 84 85 public ServiceBinding getTargetBinding() throws JAXRException { 86 ServiceBinding targetBinding = null; 87 if (targetBindingRef != null) { 88 targetBinding = (ServiceBinding)targetBindingRef.getRegistryObject("ServiceBinding"); 89 } 90 91 return targetBinding; 92 } 93 94 /*** 95 * Internal method to set the targetBinding 96 */ 97 void setTargetBindingInternal(ServiceBinding targetBinding) throws JAXRException { 98 targetBindingRef = new RegistryObjectRef(lcm, targetBinding); 99 setModified(true); 100 } 101 102 103 public void setTargetBinding(ServiceBinding _binding) throws JAXRException { 104 if (targetBindingRef != null) { 105 if (!(_binding.getKey().getId().equals(targetBindingRef.getId()))) { 106 if (!(_binding instanceof ServiceBindingImpl)) { 107 throw new InvalidRequestException("Expected ServiceBindingImpl, got " + _binding); 108 } 109 setTargetBindingInternal(_binding); 110 } 111 } 112 } 113 114 //??JAXR 2.0 115 public RegistryObjectRef getServiceRef() throws JAXRException { 116 return serviceRef; 117 } 118 119 public Service getService() throws JAXRException { 120 Service service = null; 121 if (serviceRef != null) { 122 service = (Service)serviceRef.getRegistryObject("Service"); 123 } 124 125 return service; 126 } 127 128 /*** 129 * Internal method to set the service 130 */ 131 void setServiceInternal(Service service) throws JAXRException { 132 serviceRef = new RegistryObjectRef(lcm, service); 133 setModified(true); 134 } 135 136 137 /*** 138 * Not to be used by clients. Expected to be used only by ServiceImpl. 139 */ 140 void setService(Service service) throws JAXRException { 141 if (serviceRef != null) { 142 if (!(service.getKey().getId().equals(serviceRef.getId()))) { 143 if (!(service instanceof ServiceImpl)) { 144 throw new InvalidRequestException("Expected ServiceImpl, got " + service); 145 } 146 } 147 } 148 setServiceInternal(service); 149 } 150 151 public void addSpecificationLink(SpecificationLink specLink) throws JAXRException { 152 specLinks.add(specLink); 153 ((SpecificationLinkImpl)specLink).setServiceBinding(this); 154 155 //In version 2.1 there is no parent attribute in SpecificationLink (fixed in 2.5). 156 //This means that a SpecificationLink must be saved within a ServiceBinding. 157 //Therefor we must force the ServiceBinding to be saved. 158 setModified(true); 159 } 160 161 public void addSpecificationLinks(Collection _specLinks) throws JAXRException { 162 Iterator iter = _specLinks.iterator(); 163 while (iter.hasNext()) { 164 Object obj = (SpecificationLinkImpl)iter.next(); 165 if (!(obj instanceof SpecificationLinkImpl)) { 166 throw new InvalidRequestException("Expected SpecificationLinkImpl, got " + obj); 167 } 168 SpecificationLinkImpl specLink = (SpecificationLinkImpl)obj; 169 addSpecificationLink(specLink); 170 } 171 } 172 173 public void removeSpecificationLink(SpecificationLink specLink) throws JAXRException { 174 specLinks.remove(specLink); 175 ((SpecificationLinkImpl)specLink).setServiceBinding(null); 176 //In version 2.1 there is no parent attribute in SpecificationLink (fixed in 2.5). 177 //This means that a SpecificationLink must be saved within a ServiceBinding. 178 //Therefor we must force the ServiceBinding to be saved. 179 setModified(true); 180 } 181 182 public void removeSpecificationLinks(Collection _specLinks) throws JAXRException { 183 Iterator iter = _specLinks.iterator(); 184 while (iter.hasNext()) { 185 Object obj = (SpecificationLinkImpl)iter.next(); 186 if (!(obj instanceof SpecificationLinkImpl)) { 187 throw new InvalidRequestException("Expected SpecificationLinkImpl, got " + obj); 188 } 189 SpecificationLinkImpl specLink = (SpecificationLinkImpl)obj; 190 removeSpecificationLink(specLink); 191 } 192 } 193 194 public Collection getSpecificationLinks() throws JAXRException { 195 return (HashSet)(specLinks.clone()); 196 } 197 198 public boolean getValidateURI() throws JAXRException { 199 return validateURI; 200 } 201 202 public void setValidateURI(boolean validateURI) throws JAXRException { 203 this.validateURI = validateURI; 204 } 205 206 /*** 207 * This method takes this JAXR infomodel object and returns an 208 * equivalent binding object for it. Note it does the reverse of one 209 * of the constructors above. 210 */ 211 public org.oasis.ebxml.registry.bindings.rim.ServiceBinding toBindingObject() throws JAXRException { 212 org.oasis.ebxml.registry.bindings.rim.ServiceBinding ebBinding = 213 new org.oasis.ebxml.registry.bindings.rim.ServiceBinding(); 214 215 setBindingObject(ebBinding); 216 217 return ebBinding; 218 } 219 220 protected void setBindingObject(org.oasis.ebxml.registry.bindings.rim.ServiceBindingType ebBinding) throws JAXRException { 221 super.setBindingObject(ebBinding); 222 223 if (accessURI != null) { 224 ebBinding.setAccessURI(accessURI); 225 } 226 227 if (targetBindingRef != null) { 228 org.oasis.ebxml.registry.bindings.rim.ObjectRef ebTargetBindingRef = 229 new org.oasis.ebxml.registry.bindings.rim.ObjectRef(); 230 ebTargetBindingRef.setId(targetBindingRef.getId()); 231 ebBinding.setTargetBinding(ebTargetBindingRef); 232 } 233 234 if (serviceRef != null) { 235 org.oasis.ebxml.registry.bindings.rim.ObjectRef ebServiceRef = 236 new org.oasis.ebxml.registry.bindings.rim.ObjectRef(); 237 ebServiceRef.setId(serviceRef.getId()); 238 ebBinding.setService(ebServiceRef); 239 } 240 241 Iterator iter = getSpecificationLinks().iterator(); 242 while (iter.hasNext()) { 243 SpecificationLinkImpl specLink = (SpecificationLinkImpl)iter.next(); 244 ebBinding.addSpecificationLink(specLink.toBindingObject()); 245 } 246 247 } 248 249 public void getComposedObjects(HashSet composedObjects) throws JAXRException { 250 super.getComposedObjects(composedObjects); 251 252 Collection specLinks = getSpecificationLinks(); 253 composedObjects.addAll(specLinks); 254 Iterator iter = specLinks.iterator(); 255 while (iter.hasNext()) { 256 SpecificationLinkImpl specLink = (SpecificationLinkImpl)iter.next(); 257 specLink.getComposedObjects(composedObjects); 258 } 259 } 260 261 /*** 262 * Used by LifeCycleManagerImpl.saveObjects 263 * 264 */ 265 public HashSet getRegistryObjectRefs() { 266 HashSet refs = new HashSet(); 267 268 //refs.addAll(super.getRegistryObjectRefs()); 269 270 if (targetBindingRef != null) { 271 refs.add(targetBindingRef); 272 } 273 274 if (serviceRef != null) { 275 refs.add(serviceRef); 276 } 277 278 return refs; 279 } 280 }

This page was automatically generated by Maven