View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/infomodel/ClassificationImpl.java,v 1.22 2003/08/01 02:27:42 farrukh_najmi Exp $ 3 * 4 * 5 */ 6 7 package com.sun.xml.registry.ebxml.infomodel; 8 9 import java.lang.ref.*; 10 import java.io.*; 11 12 import java.util.*; 13 import javax.xml.registry.*; 14 import javax.xml.registry.infomodel.*; 15 16 import org.oasis.ebxml.registry.bindings.rim.ClassificationType; 17 18 import com.sun.xml.registry.ebxml.*; 19 20 21 /*** 22 * Class Declaration for Class1 23 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 24 */ 25 public class ClassificationImpl extends RegistryObjectImpl 26 implements Classification { 27 private RegistryObjectRef conceptRef = null; 28 private RegistryObjectRef schemeRef = null; 29 private String value = null; 30 private RegistryObjectRef classifiedObjectRef = null; 31 32 public ClassificationImpl(LifeCycleManagerImpl lcm) 33 throws JAXRException { 34 super(lcm); 35 } 36 37 public ClassificationImpl(LifeCycleManagerImpl lcm, 38 ClassificationType ebClass, RegistryObject classifiedObject) 39 throws JAXRException { 40 super(lcm, ebClass); 41 42 Object schemeObj = ebClass.getClassificationScheme(); 43 if (schemeObj != null) { 44 schemeRef = new RegistryObjectRef(lcm, schemeObj); 45 } 46 47 if (classifiedObject != null) { 48 classifiedObjectRef = new RegistryObjectRef(lcm, classifiedObject); 49 } 50 51 Object cnodeObj = ebClass.getClassificationNode(); 52 if (cnodeObj != null) { 53 conceptRef = new RegistryObjectRef(lcm, cnodeObj); 54 } 55 56 value = ebClass.getNodeRepresentation(); 57 58 // clean modified flag since object freshly loaded from registry 59 setModified(false); 60 } 61 62 public String toXML() throws JAXRException { 63 org.oasis.ebxml.registry.bindings.rim.RegistryObjectType ebObj = toBindingObject(); 64 StringWriter sw = new StringWriter(); 65 try { 66 ebObj.marshal(sw); 67 } catch (org.exolab.castor.xml.MarshalException x) { 68 throw new JAXRException(x); 69 } catch (org.exolab.castor.xml.ValidationException x) { 70 throw new JAXRException(x); 71 } 72 return sw.toString(); 73 } 74 75 public Concept getConcept() throws JAXRException { 76 Concept concept = null; 77 if (conceptRef != null) { 78 concept = (Concept)(conceptRef.getRegistryObject("ClassificationNode")); 79 } 80 81 return concept; 82 } 83 84 public void setConcept(Concept concept) throws JAXRException { 85 ClassificationScheme scheme = concept.getClassificationScheme(); 86 if (scheme == null) { 87 throw new InvalidRequestException("Error: Classification.setConcept must not be called using a concept that has no ClassificationScheme ancestor."); 88 } 89 90 conceptRef = new RegistryObjectRef(lcm, concept); 91 setModified(true); 92 } 93 94 public ClassificationScheme getClassificationScheme() throws JAXRException { 95 ClassificationScheme scheme = null; 96 if (schemeRef == null) { 97 Concept concept = getConcept(); 98 if (concept != null) { 99 scheme = concept.getClassificationScheme(); 100 } 101 } 102 else { 103 scheme = (ClassificationScheme)(schemeRef.getRegistryObject("ClassificationScheme")); 104 } 105 106 return scheme; 107 } 108 109 public void setClassificationScheme(ClassificationScheme scheme) throws JAXRException { 110 schemeRef = new RegistryObjectRef(lcm, scheme); 111 setModified(true); 112 } 113 114 public InternationalString getName() throws JAXRException { 115 InternationalString name = super.getName(); 116 117 //Clone name from Concept if none defined 118 if (name.getLocalizedStrings().size() == 0) { 119 if (!isExternal()) { 120 Concept concept = getConcept(); 121 if (concept != null) { 122 name = (InternationalStringImpl)((InternationalStringImpl)(concept.getName())).clone(); 123 } 124 } 125 } 126 127 return name; 128 } 129 130 public String getValue() throws JAXRException { 131 String val = null; 132 if (isExternal()) { 133 val = value; 134 } 135 else { 136 Concept concept = getConcept(); 137 if (concept != null) { 138 val = concept.getValue(); 139 } 140 } 141 142 return val; 143 } 144 145 public void setValue(String par1) throws JAXRException { 146 value = par1; 147 setModified(true); 148 } 149 150 public RegistryObject getClassifiedObject() throws JAXRException { 151 RegistryObject classifiedObject = null; 152 if (classifiedObjectRef != null) { 153 classifiedObject = (RegistryObject)(conceptRef.getRegistryObject("RegistryObject")); 154 } 155 156 return classifiedObject; 157 } 158 159 public void setClassifiedObject(RegistryObject ro) throws JAXRException { 160 if (ro == null) { 161 throw new JAXRException("Classified Object must not be null"); 162 } 163 164 classifiedObjectRef = new RegistryObjectRef(lcm, ro); 165 setModified(true); 166 167 //In case this was called directly by client, make sure that this classification is added to classified Object 168 Collection classifications = ro.getClassifications(); 169 if (!classifications.contains(this)) { 170 ro.addClassification(this); 171 } 172 } 173 174 public boolean isExternal() throws JAXRException { 175 boolean external = false; 176 177 if (conceptRef == null) { 178 external = true; 179 } 180 return external; 181 } 182 183 /*** 184 * This method takes this JAXR infomodel object and returns an 185 * equivalent binding object for it. Note it does the reverse of one 186 * of the constructors above. 187 */ 188 public org.oasis.ebxml.registry.bindings.rim.Classification toBindingObject() throws JAXRException { 189 org.oasis.ebxml.registry.bindings.rim.Classification ebClassification = 190 new org.oasis.ebxml.registry.bindings.rim.Classification(); 191 192 setBindingObject(ebClassification); 193 194 return ebClassification; 195 } 196 197 protected void setBindingObject(org.oasis.ebxml.registry.bindings.rim.ClassificationType ebClassification) throws JAXRException { 198 super.setBindingObject(ebClassification); 199 200 if (schemeRef != null) { 201 org.oasis.ebxml.registry.bindings.rim.ObjectRef ebSchemeRef = 202 new org.oasis.ebxml.registry.bindings.rim.ObjectRef(); 203 ebSchemeRef.setId(schemeRef.getId()); 204 ebClassification.setClassificationScheme(ebSchemeRef); 205 } 206 207 org.oasis.ebxml.registry.bindings.rim.ObjectRef ebClassifiedObjectRef = 208 new org.oasis.ebxml.registry.bindings.rim.ObjectRef(); 209 ebClassifiedObjectRef.setId(classifiedObjectRef.getId()); 210 ebClassification.setClassifiedObject(ebClassifiedObjectRef); 211 212 if (conceptRef != null) { 213 org.oasis.ebxml.registry.bindings.rim.ObjectRef ebClassificationNodeRef = 214 new org.oasis.ebxml.registry.bindings.rim.ObjectRef(); 215 ebClassificationNodeRef.setId(conceptRef.getId()); 216 ebClassification.setClassificationNode(ebClassificationNodeRef); 217 } 218 219 if (value != null) { 220 ebClassification.setNodeRepresentation(value); 221 } 222 223 } 224 225 /*** 226 * Used by LifeCycleManagerImpl.saveObjects 227 * 228 */ 229 public HashSet getRegistryObjectRefs() { 230 HashSet refs = new HashSet(); 231 232 //refs.addAll(super.getRegistryObjectRefs()); 233 234 if (conceptRef != null) { 235 refs.add(conceptRef); 236 } 237 238 if (schemeRef != null) { 239 refs.add(schemeRef); 240 } 241 242 if (classifiedObjectRef != null) { 243 refs.add(classifiedObjectRef); 244 } 245 246 return refs; 247 } 248 249 }

This page was automatically generated by Maven