View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/ebxmlrr/src/share/com/sun/ebxml/registry/query/filter/ClassificationNodeQueryProcessor.java,v 1.8 2003/01/14 22:20:36 nstojano Exp $ 3 */ 4 5 package com.sun.ebxml.registry.query.filter; 6 7 import java.io.*; 8 9 import javax.xml.transform.*; 10 import javax.xml.transform.stream.*; 11 12 import com.sun.ebxml.registry.*; 13 import com.sun.ebxml.registry.util.*; 14 15 import org.exolab.castor.xml.*; 16 17 import org.oasis.ebxml.registry.bindings.query.*; 18 import org.oasis.ebxml.registry.bindings.rs.*; 19 20 /*** 21 * Class Declaration for ClassificationNodeQueryProcessor 22 * @see 23 * @author Nikola Stojanovic 24 */ 25 public class ClassificationNodeQueryProcessor extends RegistryObjectQueryProcessor { 26 27 private ClassificationNodeQuery classificationNodeQuery = null; 28 29 30 protected String getName() { 31 32 return "ClassificationNode"; 33 } 34 35 36 protected void setNativeQuery(RegistryObjectQueryType query) { 37 38 classificationNodeQuery = (ClassificationNodeQuery)query; 39 super.setNativeQuery((RegistryObjectQueryType)classificationNodeQuery); 40 } 41 42 43 protected void buildFilterClauses() throws RegistryException { 44 45 convertClassificationNodeFilter(); 46 super.buildFilterClauses(); 47 } 48 49 50 protected void buildQueryClauses() throws RegistryException { 51 52 convertClasificationSchemeQuery(); 53 super.buildQueryClauses(); 54 } 55 56 57 protected void buildBranchClauses() throws RegistryException { 58 59 convertClassificationNodeParentBranch(); 60 convertClassificationNodeChildrenBranches(); 61 super.buildBranchClauses(); 62 } 63 64 65 private void convertClassificationNodeFilter() throws RegistryException { 66 67 if (classificationNodeQuery.getClassificationNodeFilter() != null) { 68 whereClause = filterProcessor.addNativeWhereClause(whereClause, classificationNodeQuery.getClassificationNodeFilter()); 69 } 70 } 71 72 73 private void convertClasificationSchemeQuery() throws RegistryException { 74 75 if (classificationNodeQuery.getClassificationSchemeQuery() != null) { 76 ClassificationSchemeQueryProcessor queryProcessor = new ClassificationSchemeQueryProcessor(); 77 queryProcessor.setParentJoinColumn("classificationScheme"); 78 queryProcessor.setSelectColumn("id"); 79 whereClause = queryProcessor.addWhereClause(whereClause, classificationNodeQuery.getClassificationSchemeQuery()); 80 } 81 } 82 83 84 private void convertClassificationNodeParentBranch() throws RegistryException { 85 86 if (classificationNodeQuery.getClassificationNodeParentBranch() != null) { 87 ClassificationNodeQueryProcessor queryProcessor = new ClassificationNodeQueryProcessor(); 88 ClassificationNodeQuery query = new ClassificationNodeQuery(); 89 queryProcessor.setParentJoinColumn("parent"); 90 queryProcessor.setSelectColumn("id"); 91 query = translateBranchIntoQuery(classificationNodeQuery.getClassificationNodeParentBranch()); 92 whereClause = queryProcessor.addWhereClause(whereClause, query); 93 } 94 } 95 96 97 private void convertClassificationNodeChildrenBranches() throws RegistryException { 98 99 ClassificationNodeChildrenBranch[] classificationNodeChildrenBranch = classificationNodeQuery.getClassificationNodeChildrenBranch(); 100 101 if (classificationNodeChildrenBranch.length > 0) { 102 ClassificationNodeQuery query = new ClassificationNodeQuery(); 103 104 for (int i=0; i<classificationNodeChildrenBranch.length; i++) { 105 ClassificationNodeQueryProcessor queryProcessor = new ClassificationNodeQueryProcessor(); 106 queryProcessor.setParentJoinColumn("id"); 107 queryProcessor.setSelectColumn("parent"); 108 query = translateBranchIntoQuery(classificationNodeChildrenBranch[i]); 109 whereClause = queryProcessor.addWhereClause(whereClause, query); 110 } 111 } 112 } 113 114 115 private ClassificationNodeQuery translateBranchIntoQuery(ClassificationNodeQueryType branch) throws RegistryException { 116 117 ClassificationNodeQuery classificationNodeQuery = null; 118 119 try { 120 TransformerFactory tFactory = TransformerFactory.newInstance(); 121 String xslFileURL = "file://" + RegistryProperties.getInstance().getProperty("ebxmlrr.home") + "/data/xsl/sqlQueryResultToFilterQueryResult.xsl"; 122 Transformer transformer = tFactory.newTransformer(new StreamSource(xslFileURL)); 123 transformer.setParameter("outputQuery", "ClassificationNodeQuery"); 124 125 StringWriter sw = new StringWriter(); 126 branch.marshal(sw); 127 StringReader sr = new StringReader(sw.toString()); 128 StreamSource input = new StreamSource(sr); 129 130 sw = new StringWriter(); 131 transformer.transform(input, new StreamResult(sw)); 132 sr = new StringReader(sw.toString()); 133 134 classificationNodeQuery = ClassificationNodeQuery.unmarshal(sr); 135 } 136 // these Exceptions should already be caught by Binding 137 catch (TransformerConfigurationException e) { 138 throw new RegistryException(e); 139 } 140 catch (TransformerException e) { 141 throw new RegistryException(e); 142 } 143 catch (MarshalException e) { 144 throw new RegistryException(e); 145 } 146 catch (ValidationException e) { 147 throw new RegistryException(e); 148 } 149 150 return classificationNodeQuery; 151 } 152 }

This page was automatically generated by Maven