View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/infomodel/AssociationImpl.java,v 1.27 2003/07/24 22:26:18 farrukh_najmi Exp $ 3 * 4 * 5 */ 6 7 package com.sun.xml.registry.ebxml.infomodel; 8 9 import java.util.*; 10 import java.io.*; 11 12 import javax.xml.registry.*; 13 import javax.xml.registry.infomodel.*; 14 15 import com.sun.xml.registry.ebxml.DeclarativeQueryManagerImpl; 16 import com.sun.xml.registry.ebxml.LifeCycleManagerImpl; 17 import javax.xml.registry.LifeCycleManager; 18 19 import org.oasis.ebxml.registry.bindings.rim.AssociationType1; 20 import org.oasis.ebxml.registry.bindings.rim.ObjectRef; 21 22 23 /*** 24 * Class Declaration for Class1 25 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 26 */ 27 public class AssociationImpl extends RegistryObjectImpl implements Association 28 { 29 //??Move to Association interface in JAXR API 2.0 30 public static final String ASSOCIATION_TYPE_RELATED_TO = "RelatedTo"; 31 public static final String ASSOCIATION_TYPE_HAS_FEDERATION_MEMBER = "HasFederationMember"; 32 public static final String ASSOCIATION_TYPE_HAS_MEMBER = "HasMember"; 33 public static final String ASSOCIATION_TYPE_EXTERNALLY_LINKS = "ExternallyLinks"; 34 public static final String ASSOCIATION_TYPE_CONTAINS = "Contains"; 35 public static final String ASSOCIATION_TYPE_EQUIVALENT_TO = "EquivalentTo"; 36 public static final String ASSOCIATION_TYPE_EXTENDS = "Extends"; 37 public static final String ASSOCIATION_TYPE_IMPLEMENTS = "Implements"; 38 public static final String ASSOCIATION_TYPE_INSTANCE_OF = "InstanceOf"; 39 public static final String ASSOCIATION_TYPE_SUPERSEDES = "Supersedes"; 40 public static final String ASSOCIATION_TYPE_USES = "Uses"; 41 public static final String ASSOCIATION_TYPE_REPLACES = "Replaces"; 42 public static final String ASSOCIATION_TYPE_SUBMITTER_OF = "SubmitterOf"; 43 public static final String ASSOCIATION_TYPE_RESPONSIBLE_FOR = "ResponsibleFor"; 44 public static final String ASSOCIATION_TYPE_OFFERS_SERVICE = "OffersService"; 45 public static final String ASSOCIATION_TYPE_CONTENT_MANAGEMENT_SERVICE_FOR = "ContentManagementServiceFor"; 46 public static final String ASSOCIATION_TYPE_INVOCATION_CONTROL_FILE_FOR = "InvocationControlFileFor"; 47 48 public static final String CANONICAL_ID_NODE_ASSOCIATION_TYPE_EXTERNALLY_LINKS = 49 "urn:uuid:92d03292-84a0-4b86-8139-dd244173ddbb"; 50 51 52 private RegistryObjectRef sourceObjectRef = null; 53 private RegistryObjectRef targetObjectRef = null; 54 55 Concept assocType = null; 56 private static ClassificationScheme assocTypeScheme = null; 57 private static HashMap assocTypesMap = null; 58 59 public AssociationImpl(LifeCycleManagerImpl lcm) 60 throws JAXRException 61 { 62 super(lcm); 63 } 64 65 public AssociationImpl(LifeCycleManagerImpl lcm, AssociationType1 ebAss) 66 throws JAXRException 67 { 68 super(lcm, ebAss); 69 70 String assocTypeStr = ebAss.getAssociationType(); 71 72 DeclarativeQueryManagerImpl dqm = (DeclarativeQueryManagerImpl) 73 lcm.getRegistryService().getDeclarativeQueryManager(); 74 75 76 if (assocTypeScheme == null) { 77 assocTypeScheme = (ClassificationScheme)bqm.getRegistryObject("urn:uuid:6902675f-2f18-44b8-888b-c91db8b96b4d", LifeCycleManager.CLASSIFICATION_SCHEME); 78 initializeAssociationTypesMap(); 79 } 80 81 assocType = (Concept)assocTypesMap.get(assocTypeStr); 82 if (assocType == null) { 83 if ( assocTypeStr.startsWith("urn:uuid:")) { 84 assocType = (Concept)bqm.getRegistryObject(assocTypeStr, LifeCycleManager.CONCEPT); 85 } 86 else { 87 assocType = bqm.findConceptByPath("/" + assocTypeScheme.getKey().getId() + "/" + assocTypeStr); 88 } 89 90 if (assocType == null) { 91 assocType = lcm.createConcept(assocTypeScheme, assocTypeStr, assocTypeStr); 92 } 93 94 assocTypesMap.put(assocTypeStr, assocType); 95 } 96 97 98 sourceObjectRef = new RegistryObjectRef(lcm, ebAss.getSourceObject()); 99 targetObjectRef = new RegistryObjectRef(lcm, ebAss.getTargetObject()); 100 } 101 102 private static void initializeAssociationTypesMap() { 103 assocTypesMap = new HashMap(); 104 try { 105 Collection assocTypes = assocTypeScheme.getChildrenConcepts(); 106 107 Iterator iter = assocTypes.iterator(); 108 while (iter.hasNext()) { 109 Concept concept = (Concept)iter.next(); 110 String value = concept.getValue(); 111 assocTypesMap.put(value, concept); 112 } 113 } 114 catch (JAXRException e) { 115 e.printStackTrace(); 116 } 117 } 118 119 public String toXML() throws JAXRException { 120 org.oasis.ebxml.registry.bindings.rim.RegistryObjectType ebObj = toBindingObject(); 121 StringWriter sw = new StringWriter(); 122 try { 123 ebObj.marshal(sw); 124 } catch (org.exolab.castor.xml.MarshalException x) { 125 throw new JAXRException(x); 126 } catch (org.exolab.castor.xml.ValidationException x) { 127 throw new JAXRException(x); 128 } 129 return sw.toString(); 130 } 131 132 //??JAXR 2.0 133 public RegistryObjectRef getSourceObjectRef() throws JAXRException { 134 return sourceObjectRef; 135 } 136 137 public RegistryObject getSourceObject() throws JAXRException { 138 RegistryObject sourceObject = null; 139 if (sourceObjectRef != null) { 140 sourceObject = sourceObjectRef.getRegistryObject("RegistryObject"); 141 } 142 143 return sourceObject; 144 } 145 146 /*** 147 * Internal method to set the sourceObject 148 */ 149 void setSourceObjectInternal(RegistryObject sourceObject) throws JAXRException { 150 sourceObjectRef = new RegistryObjectRef(lcm, sourceObject); 151 setModified(true); 152 } 153 154 public void setSourceObject(RegistryObject sourceObject) 155 throws JAXRException 156 { 157 sourceObject.addAssociation(this); 158 } 159 160 //??JAXR 2.0 161 public void setSourceObjectRef(RegistryObjectRef sourceObjectRef) throws JAXRException { 162 this.sourceObjectRef = sourceObjectRef; 163 setModified(true); 164 } 165 166 //??JAXR 2.0 167 public RegistryObjectRef getTargetObjectRef() throws JAXRException { 168 return targetObjectRef; 169 } 170 171 public RegistryObject getTargetObject() throws JAXRException { 172 RegistryObject targetObject = null; 173 if (targetObjectRef != null) { 174 targetObject = targetObjectRef.getRegistryObject("RegistryObject"); 175 } 176 177 return targetObject; 178 } 179 180 public void setTargetObject(RegistryObject targetObject) throws JAXRException { 181 targetObjectRef = new RegistryObjectRef(lcm, targetObject); 182 setModified(true); 183 } 184 185 //??JAXR 2.0 186 public void setTargetObjectRef(RegistryObjectRef targetObjectRef) throws JAXRException { 187 this.targetObjectRef = targetObjectRef; 188 setModified(true); 189 } 190 191 public Concept getAssociationType() throws JAXRException { 192 if (assocType == null) { 193 assocType = (Concept)bqm.getRegistryObject("urn:uuid:7aad31a7-501e-4cbc-ac37-ddc44fdf3e1a", LifeCycleManager.CONCEPT); 194 } 195 196 return assocType; 197 } 198 199 public void setAssociationType(Concept par1) throws JAXRException { 200 assocType = par1; 201 setModified(true); 202 } 203 204 public boolean isExtramural() throws JAXRException { 205 // To check if Association is Extramural requires us to determine 206 // owners of the three involved objects: source, target, Association. 207 if (isNew() || sourceObjectRef == null || targetObjectRef == null) { 208 //throw i18nUtil.newJAXRException("unsaved.Association"); 209 return false; //?? 210 } 211 212 RegistryObjectImpl srcObject = ((RegistryObjectImpl)getSourceObject()); 213 RegistryObjectImpl targetObject = ((RegistryObjectImpl)getTargetObject()); 214 215 if (srcObject == null) { 216 return false; 217 } 218 219 if (targetObject == null) { 220 return false; 221 } 222 223 UserImpl assOwner = (UserImpl)getOwner(); 224 if (assOwner == null) { 225 return false; //??Should this be an error 226 } 227 228 UserImpl sourceOwner = (UserImpl)(srcObject.getOwner()); 229 UserImpl targetOwner = (UserImpl)(targetObject.getOwner()); 230 231 232 if (assOwner.getId().equals(targetOwner.getId()) && 233 assOwner.getId().equals(sourceOwner.getId())) { 234 return false; 235 } else { 236 return true; 237 } 238 } 239 240 public boolean isConfirmedBySourceOwner() throws JAXRException { 241 // Write your code here 242 return true; 243 } 244 245 public boolean isConfirmedByTargetOwner() throws JAXRException { 246 // Write your code here 247 return true; 248 } 249 250 public boolean isConfirmed() throws JAXRException { 251 boolean confirmed = false; 252 if (isConfirmedBySourceOwner() && isConfirmedByTargetOwner()) { 253 confirmed = true; 254 } 255 return confirmed; 256 } 257 258 /*** 259 * This method takes this JAXR infomodel object and returns an 260 * equivalent binding object for it. Note it does the reverse of one 261 * of the constructors above. 262 */ 263 public org.oasis.ebxml.registry.bindings.rim.Association toBindingObject() throws JAXRException 264 { 265 org.oasis.ebxml.registry.bindings.rim.Association ebOrg = 266 new org.oasis.ebxml.registry.bindings.rim.Association(); 267 268 setBindingObject(ebOrg); 269 270 return ebOrg; 271 } 272 273 protected void setBindingObject(org.oasis.ebxml.registry.bindings.rim.AssociationType1 ebAssociation) throws JAXRException { 274 super.setBindingObject(ebAssociation); 275 276 if (assocType != null) { 277 ebAssociation.setAssociationType(assocType.getKey().getId()); 278 } 279 280 org.oasis.ebxml.registry.bindings.rim.ObjectRef ebSourceObjectRef = 281 new org.oasis.ebxml.registry.bindings.rim.ObjectRef(); 282 ebSourceObjectRef.setId(sourceObjectRef.getId()); 283 ebAssociation.setSourceObject(ebSourceObjectRef); 284 285 org.oasis.ebxml.registry.bindings.rim.ObjectRef ebTargetObjectRef = 286 new org.oasis.ebxml.registry.bindings.rim.ObjectRef(); 287 ebTargetObjectRef.setId(targetObjectRef.getId()); 288 ebAssociation.setTargetObject(ebTargetObjectRef); 289 } 290 291 /*** 292 * Used by LifeCycleManagerImpl.saveObjects 293 * 294 */ 295 public HashSet getRegistryObjectRefs() { 296 HashSet refs = new HashSet(); 297 298 //refs.addAll(super.getRegistryObjectRefs()); 299 300 if (sourceObjectRef != null) { 301 refs.add(sourceObjectRef); 302 } 303 304 if (targetObjectRef != null) { 305 refs.add(targetObjectRef); 306 } 307 308 return refs; 309 } 310 311 }

This page was automatically generated by Maven