View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/infomodel/ClassificationSchemeImpl.java,v 1.20 2003/07/26 13:11:10 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 /*** 17 * Class Declaration for Class1 18 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 19 */ 20 public class ClassificationSchemeImpl extends RegistryEntryImpl 21 implements ClassificationScheme 22 { 23 private boolean external = false; 24 private int valueType = ClassificationScheme.VALUE_TYPE_UNIQUE; //??No default defined by spec 25 26 private ArrayList children = new ArrayList(); 27 private boolean childrenLoaded = false; 28 29 public ClassificationSchemeImpl(LifeCycleManagerImpl lcm) 30 throws JAXRException 31 { 32 super(lcm); 33 childrenLoaded = true; 34 } 35 36 /*** 37 * This constructir is to do a type safe cast from a Concept with no parent to a scheme. 38 * This has history in UDDI and we are not sure what value it has in ebXML. 39 * We are implementing it as it is required by the JAXR API. 40 * Needs evaluation for relevance in JAXR2.0?? 41 **/ 42 public ClassificationSchemeImpl(LifeCycleManagerImpl lcm, Concept concept) 43 throws JAXRException 44 { 45 super(lcm); 46 if (concept.getParent() != null) { 47 throw new InvalidRequestException("Cannot use a Concept that has a parent to create a ClassificationScheme"); 48 } 49 50 setName(concept.getName()); 51 setDescription(concept.getDescription()); 52 addClassifications(concept.getClassifications()); 53 addExternalIdentifiers(concept.getExternalIdentifiers()); 54 55 //??incomplete 56 } 57 58 public ClassificationSchemeImpl(LifeCycleManagerImpl lcm, 59 org.oasis.ebxml.registry.bindings.rim.ClassificationSchemeType ebScheme) 60 throws JAXRException 61 { 62 super(lcm, ebScheme); 63 64 external = !(ebScheme.getIsInternal()); 65 66 // XXX Translate this to ClassificationScheme.ValueType in JAXR 0.81 67 // ebScheme.getNodeType(); 68 } 69 70 //??This shoudl be added to JAXR 2.0 API. 71 public void setExternal(boolean external) { 72 this.external = external; 73 } 74 75 //??JAXR2.0 change to specify a Writer instead. 76 public String toXML() throws JAXRException { 77 org.oasis.ebxml.registry.bindings.rim.RegistryObjectType ebObj = toBindingObject(); 78 StringWriter sw = new StringWriter(); 79 try { 80 ebObj.marshal(sw); 81 } catch (org.exolab.castor.xml.MarshalException x) { 82 throw new JAXRException(x); 83 } catch (org.exolab.castor.xml.ValidationException x) { 84 throw new JAXRException(x); 85 } 86 return sw.toString(); 87 } 88 89 public void addChildConcept(Concept c) throws JAXRException { 90 children.add(c); 91 92 ((ConceptImpl)c).setClassificationScheme(this); 93 //No need to call setModified(true) since RIM does not require parent to remember children 94 } 95 96 public void addChildConcepts(Collection par1) throws JAXRException { 97 Iterator iter = par1.iterator(); 98 while (iter.hasNext()) { 99 ConceptImpl concept = (ConceptImpl)iter.next(); 100 concept.setClassificationScheme(this); 101 } 102 children.addAll(par1); 103 //No need to call setModified(true) since RIM does not require parent to remember children 104 } 105 106 public void removeChildConcept(Concept par1) throws JAXRException { 107 children.remove(par1); 108 //No need to call setModified(true) since RIM does not require parent to remember children 109 } 110 111 public void removeChildConcepts(Collection par1) throws JAXRException { 112 children.removeAll(par1); 113 //No need to call setModified(true) since RIM does not require parent to remember children 114 } 115 116 public int getChildConceptCount() throws JAXRException { 117 return getChildrenConcepts().size(); 118 } 119 120 public Collection getChildrenConcepts() throws JAXRException { 121 if (!childrenLoaded) { 122 DeclarativeQueryManager dqm = lcm.getRegistryService() 123 .getDeclarativeQueryManager(); 124 String qs = "SELECT * FROM ClassificationNode WHERE parent = '" 125 + getKey().getId() + "' ORDER BY CODE"; 126 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, qs); 127 children.addAll(dqm.executeQuery(query).getCollection()); 128 childrenLoaded = true; 129 } 130 return children; 131 } 132 133 public Collection getDescendantConcepts() throws JAXRException { 134 DeclarativeQueryManager dqm = lcm.getRegistryService() 135 .getDeclarativeQueryManager(); 136 String qs = "SELECT * FROM ClassificationNode WHERE path LIKE '/" 137 + getKey().getId() + "/%'"; 138 Query query = dqm.createQuery(Query.QUERY_TYPE_SQL, qs); 139 Collection col = dqm.executeQuery(query).getCollection(); 140 141 // Post-process the results to add Concept-s one level down from 142 // ClassificationScheme as children 143 for (Iterator it = col.iterator(); it.hasNext(); ) { 144 ConceptImpl concept = (ConceptImpl)it.next(); 145 Concept parentConcept = concept.getParentConcept(); 146 if (parentConcept == null) { 147 // null parent Concept means that the parent is a 148 // ClassificationScheme 149 addChildConcept(concept); 150 } else { 151 parentConcept.addChildConcept(concept); 152 } 153 } 154 return col; 155 156 // ArrayList descendants = new ArrayList(children); 157 // Iterator iter = children.iterator(); 158 159 // while (iter.hasNext()) { 160 // Concept child = (Concept) iter.next(); 161 162 // if (child.getChildConceptCount() > 0) { 163 // descendants.addAll(child.getDescendantConcepts()); 164 // } 165 // } 166 // return descendants; 167 } 168 169 public boolean isExternal() throws JAXRException { 170 return external; 171 } 172 173 174 public void setValueType(int param) throws javax.xml.registry.JAXRException { 175 this.valueType = param; 176 setModified(true); 177 } 178 179 public int getValueType() throws javax.xml.registry.JAXRException { 180 return valueType; 181 } 182 183 public org.oasis.ebxml.registry.bindings.rim.ClassificationScheme toBindingObject() throws JAXRException 184 { 185 org.oasis.ebxml.registry.bindings.rim.ClassificationScheme ebScheme = 186 new org.oasis.ebxml.registry.bindings.rim.ClassificationScheme(); 187 188 setBindingObject(ebScheme); 189 190 return ebScheme; 191 } 192 193 public void getComposedObjects(HashSet composedObjects) throws JAXRException { 194 super.getComposedObjects(composedObjects); 195 composedObjects.addAll(children); 196 } 197 198 199 protected void setBindingObject(org.oasis.ebxml.registry.bindings.rim.ClassificationSchemeType ebClassificationScheme) throws JAXRException { 200 super.setBindingObject(ebClassificationScheme); 201 202 /* 203 * Following code was added to support ability to export 204 * entire CllassificationScheme. It is being removed because 205 * it was causing major performance problems. 206 getChildrenConcepts(); 207 Iterator iter = children.iterator(); 208 while (iter.hasNext()) { 209 ConceptImpl concept = (ConceptImpl)iter.next(); 210 org.oasis.ebxml.registry.bindings.rim.ClassificationNode ebClassificationNode = concept.toBindingObject(); 211 ebClassificationScheme.addClassificationNode(ebClassificationNode); 212 } 213 */ 214 215 ebClassificationScheme.setIsInternal(!isExternal()); 216 217 switch(this.getValueType()) { 218 case VALUE_TYPE_EMBEDDED_PATH: 219 ebClassificationScheme.setNodeType(org.oasis.ebxml.registry.bindings.rim.types.NodeTypeType.EMBEDDEDPATH); 220 break; 221 case VALUE_TYPE_NON_UNIQUE: 222 ebClassificationScheme.setNodeType(org.oasis.ebxml.registry.bindings.rim.types.NodeTypeType.NONUNIQUECODE); 223 break; 224 case VALUE_TYPE_UNIQUE: 225 ebClassificationScheme.setNodeType(org.oasis.ebxml.registry.bindings.rim.types.NodeTypeType.UNIQUECODE); 226 break; 227 } 228 } 229 230 }

This page was automatically generated by Maven