View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/infomodel/ConceptImpl.java,v 1.28 2003/08/22 03:01:38 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.ClassificationNodeType; 17 import org.oasis.ebxml.registry.bindings.rim.RegistryObjectType; 18 import org.oasis.ebxml.registry.bindings.rim.ObjectRef; 19 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 23 /*** 24 * Class Declaration for Class1 25 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 26 */ 27 public class ConceptImpl extends RegistryObjectImpl implements Concept { 28 29 private static final Log log = 30 LogFactory.getLog(ConceptImpl.class); 31 32 private RegistryObjectRef parentRef = null; 33 private ArrayList children = new ArrayList(); 34 private boolean childrenLoaded = false; 35 private String value; 36 private String path; 37 private RegistryObjectRef schemeRef = null; 38 39 public ConceptImpl(LifeCycleManagerImpl lcm) throws JAXRException { 40 super(lcm); 41 childrenLoaded = true; 42 43 } 44 45 public ConceptImpl(LifeCycleManagerImpl lcm, ClassificationNodeType cnode) 46 throws JAXRException { 47 super(lcm, cnode); 48 49 value = cnode.getCode(); 50 path = cnode.getPath(); 51 52 String schemeId = getSchemeId(); 53 54 if (schemeId != null) { 55 schemeRef = new RegistryObjectRef(lcm, schemeId); 56 } 57 58 Object pnode = cnode.getParent(); 59 if (pnode != null) { 60 parentRef = new RegistryObjectRef(lcm, pnode); 61 } 62 63 // ClassificationNodeType pnode = (ClassificationNodeType) 64 // cnode.getParent(); 65 // com.sun.xml.registry.ebxml.D.out("cName=" + dGetName(cnode) 66 // + ", pName=" + dGetName(pnode)); 67 68 // org.oasis.ebxml.registry.bindings.rim.ClassificationNode[] _children = node.getClassificationNode(); 69 // for (int i=0; i<_children.length; i++) { 70 // Concept concept = new ConceptImpl(regService, _children[i]); 71 // addChildConcept(concept); 72 // } 73 } 74 75 private String dGetName( 76 org.oasis.ebxml.registry.bindings.rim.ClassificationNodeType cnt) { 77 if (cnt != null) { 78 org.oasis.ebxml.registry.bindings.rim.InternationalStringType 79 ist = cnt.getName(); 80 if (ist != null) { 81 Enumeration e = ist.enumerateInternationalStringTypeItem(); 82 if (e.hasMoreElements()) { 83 org.oasis.ebxml.registry.bindings.rim.InternationalStringTypeItem 84 item = (org.oasis.ebxml.registry.bindings.rim.InternationalStringTypeItem)e.nextElement(); 85 org.oasis.ebxml.registry.bindings.rim.LocalizedStringType 86 lst = (org.oasis.ebxml.registry.bindings.rim.LocalizedStringType)item.getLocalizedString(); 87 return lst.getValue(); 88 } 89 } 90 } 91 return null; 92 } 93 94 public String toXML() throws JAXRException { 95 org.oasis.ebxml.registry.bindings.rim.RegistryObjectType ebObj = toBindingObject(); 96 StringWriter sw = new StringWriter(); 97 try { 98 ebObj.marshal(sw); 99 } catch (org.exolab.castor.xml.MarshalException x) { 100 throw new JAXRException(x); 101 } catch (org.exolab.castor.xml.ValidationException x) { 102 throw new JAXRException(x); 103 } 104 return sw.toString(); 105 } 106 107 public String getValue() throws JAXRException { 108 return value; 109 } 110 111 public void setValue(String par1) throws JAXRException { 112 value = par1; 113 setModified(true); 114 } 115 116 public void addChildConcept(Concept par1) throws JAXRException { 117 ((ConceptImpl)par1).setParentConcept(this); 118 children.add(par1); 119 //No need to call setModified(true) since RIM does not require parent to remember children 120 } 121 122 public void addChildConcepts(Collection par1) throws JAXRException { 123 Iterator iter = par1.iterator(); 124 while (iter.hasNext()) { 125 ConceptImpl concept = (ConceptImpl)iter.next(); 126 concept.setParentConcept(this); 127 } 128 children.addAll(par1); 129 //No need to call setModified(true) since RIM does not require parent to remember children 130 } 131 132 public void removeChildConcept(Concept par1) throws JAXRException { 133 children.remove(par1); 134 //No need to call setModified(true) since RIM does not require parent to remember children 135 } 136 137 public void removeChildConcepts(Collection par1) throws JAXRException { 138 children.removeAll(par1); 139 //No need to call setModified(true) since RIM does not require parent to remember children 140 } 141 142 public int getChildConceptCount() throws JAXRException { 143 return getChildrenConcepts().size(); 144 } 145 146 public Collection getChildrenConcepts() throws JAXRException { 147 if (!childrenLoaded) { 148 DeclarativeQueryManager dqm = lcm.getRegistryService() 149 .getDeclarativeQueryManager(); 150 String qs = "SELECT * FROM ClassificationNode WHERE parent = '" 151 + getKey().getId() + "' ORDER BY CODE"; 152 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, qs); 153 children.addAll(dqm.executeQuery(query).getCollection()); 154 childrenLoaded = true; 155 } 156 return children; 157 } 158 159 public Collection getDescendantConcepts() throws JAXRException { 160 ArrayList descendants = new ArrayList(children); 161 Iterator iter = children.iterator(); 162 163 while (iter.hasNext()) { 164 Concept child = (Concept) iter.next(); 165 166 if (child.getChildConceptCount() > 0) { 167 descendants.addAll(child.getDescendantConcepts()); 168 } 169 } 170 return descendants; 171 } 172 173 public Concept getParentConcept() throws JAXRException { 174 RegistryObject parentObj = parentRef.getRegistryObject("RegistryObject"); 175 if (parentObj instanceof Concept) { 176 return (Concept)parentObj; 177 } else { 178 return null; 179 } 180 } 181 182 //??Add to JAXR API 183 public RegistryObject getParent() throws JAXRException { 184 RegistryObject parentObj = null; 185 186 if (parentRef != null) { 187 parentObj = parentRef.getRegistryObject("RegistryObject"); 188 } 189 190 return parentObj; 191 } 192 193 public void setParentConcept(Concept c) throws JAXRException { 194 parentRef = new RegistryObjectRef(lcm, c); 195 setModified(true); 196 } 197 198 /*** 199 * Gets teh id for this Concept's ClassificationScheme. 200 **/ 201 private String getSchemeId() { 202 String id = null; 203 204 if (path != null) { 205 int end = path.indexOf('/', 1); 206 if (end > 1) { 207 id = path.substring(1, end); 208 } 209 } 210 211 return id; 212 } 213 214 public ClassificationScheme getClassificationScheme() throws JAXRException { 215 ClassificationScheme scheme = null; 216 217 if (schemeRef != null) { 218 scheme = (ClassificationScheme)schemeRef.getRegistryObject("ClassificationScheme"); 219 } 220 221 return scheme; 222 } 223 224 public void setClassificationScheme(ClassificationScheme c) throws JAXRException { 225 parentRef = new RegistryObjectRef(lcm, c); 226 setModified(true); 227 } 228 229 public String getPath() throws JAXRException { 230 return path; 231 } 232 233 /*** 234 * Gets the level for this Concept. 235 * Add to JAXR 2.0?? 236 * 237 * @return 0 for a Concept with no parent, 1 for a first level Concept, n otherwise 238 * 239 */ 240 public int getLevel() throws JAXRException { 241 int level = 0; 242 243 if (parentRef != null) { 244 //Count the number of '/' characters in path and subtract 1 245 for (int i=0; i<path.length(); i++) { 246 if (path.charAt(i) == '/') { 247 level++; 248 } 249 } 250 } 251 252 return level; 253 } 254 255 public org.oasis.ebxml.registry.bindings.rim.ClassificationNode toBindingObject() throws JAXRException { 256 org.oasis.ebxml.registry.bindings.rim.ClassificationNode ebClassificationNode = 257 new org.oasis.ebxml.registry.bindings.rim.ClassificationNode(); 258 259 setBindingObject(ebClassificationNode); 260 261 return ebClassificationNode; 262 } 263 264 public void getComposedObjects(HashSet composedObjects) throws JAXRException { 265 super.getComposedObjects(composedObjects); 266 composedObjects.addAll(children); 267 } 268 269 protected void setBindingObject(org.oasis.ebxml.registry.bindings.rim.ClassificationNodeType ebClassificationNode) throws JAXRException { 270 super.setBindingObject(ebClassificationNode); 271 272 if (parentRef != null) { 273 org.oasis.ebxml.registry.bindings.rim.ObjectRef ebParentRef = 274 new org.oasis.ebxml.registry.bindings.rim.ObjectRef(); 275 ebParentRef.setId(parentRef.getId()); 276 ebClassificationNode.setParent(ebParentRef); 277 } 278 279 /* 280 * Following code was added to support ability to export 281 * entire tree (see export action in graphical browser). 282 * It is being removed because it was causing major performance problems. 283 getChildrenConcepts(); 284 Iterator iter = children.iterator(); 285 while (iter.hasNext()) { 286 ConceptImpl childConcept = (ConceptImpl)iter.next(); 287 org.oasis.ebxml.registry.bindings.rim.ClassificationNode ebChildNode = childConcept.toBindingObject(); 288 ebClassificationNode.addClassificationNode(ebChildNode); 289 } 290 */ 291 292 ebClassificationNode.setCode(getValue()); 293 } 294 295 /*** 296 * Will be added to JAXR 2.0 API in future. 297 * Gets all RegistryObjects that are classified by this Concept. 298 **/ 299 public BulkResponse getClassifiedObjects() throws JAXRException { 300 String query = "SELECT id FROM RegistryObject WHERE id IN " + 301 "(SELECT classifiedObject FROM Classification " + 302 "WHERE classificationNode = '" + getKey().getId() + "')"; 303 304 Query q = dqm.createQuery(Query.QUERY_TYPE_SQL, query); 305 306 return dqm.executeQuery(q); 307 } 308 309 /*** 310 * Used by LifeCycleManagerImpl.saveObjects 311 * 312 */ 313 public HashSet getRegistryObjectRefs() { 314 HashSet refs = new HashSet(); 315 316 //refs.addAll(super.getRegistryObjectRefs()); 317 318 if (parentRef != null) { 319 refs.add(parentRef); 320 } 321 322 if (schemeRef != null) { 323 refs.add(schemeRef); 324 } 325 326 return refs; 327 } 328 329 public String toString() { 330 String str = super.toString(); 331 try { 332 str = getValue(); 333 } 334 catch (Exception e) { 335 log.warn(e); 336 } 337 return str; 338 } 339 340 341 }

This page was automatically generated by Maven