View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/ebxmlrr/src/share/com/sun/ebxml/registry/query/filter/FilterQueryProcessor.java,v 1.11 2002/12/27 13:27:00 ritzmann Exp $ 3 */ 4 5 package com.sun.ebxml.registry.query.filter; 6 7 import com.sun.ebxml.registry.*; 8 import com.sun.ebxml.registry.util.*; 9 10 import org.oasis.ebxml.registry.bindings.rim.*; 11 import org.oasis.ebxml.registry.bindings.query.*; 12 import org.oasis.ebxml.registry.bindings.query.types.*; 13 import org.oasis.ebxml.registry.bindings.rs.*; 14 15 import com.sun.ebxml.registry.*; 16 import com.sun.ebxml.registry.query.filter.*; 17 import com.sun.ebxml.registry.query.sql.*; 18 import com.sun.ebxml.registry.persistence.rdb.*; 19 20 import javax.xml.transform.*; 21 import javax.xml.transform.stream.*; 22 23 import java.io.*; 24 25 /*** 26 * Class Declaration for FilterQueryProcessor 27 * @see 28 * @author Nikola Stojanovic 29 */ 30 public class FilterQueryProcessor { 31 32 /*** 33 * @link 34 * @shapeType PatternLink 35 * @pattern Singleton 36 * @supplierRole Singleton factory 37 */ 38 /*# private FilterQueryProcessor _filterQueryProcessor; */ 39 private static FilterQueryProcessor instance = null; 40 private static SQLQueryProcessor sqlQueryProcessor = SQLQueryProcessor.getInstance(); 41 private String sqlQuery = null; 42 43 44 public AdhocQueryResponse executeQuery(User user, FilterQuery filterQueryRequest, ResponseOption responseOption) throws RegistryException { 45 46 AdhocQueryResponse response = new AdhocQueryResponse(); 47 48 if (filterQueryRequest.getRegistryObjectQuery() != null) { 49 RegistryObjectQueryProcessor registryObjectQueryProcessor = new RegistryObjectQueryProcessor(); 50 sqlQuery = registryObjectQueryProcessor.convertToSQL((RegistryObjectQueryType)filterQueryRequest.getRegistryObjectQuery()); 51 } 52 else if (filterQueryRequest.getRegistryEntryQuery() != null) { 53 RegistryEntryQueryProcessor registryEntryQueryProcessor = new RegistryEntryQueryProcessor(); 54 sqlQuery = registryEntryQueryProcessor.convertToSQL((RegistryObjectQueryType)filterQueryRequest.getRegistryEntryQuery()); 55 } 56 else if (filterQueryRequest.getAssociationQuery() != null) { 57 AssociationQueryProcessor associationQueryProcessor = new AssociationQueryProcessor(); 58 sqlQuery = associationQueryProcessor.convertToSQL((RegistryObjectQueryType)filterQueryRequest.getAssociationQuery()); 59 } 60 else if (filterQueryRequest.getAuditableEventQuery() != null) { 61 AuditableEventQueryProcessor auditableEventQueryProcessor = new AuditableEventQueryProcessor(); 62 sqlQuery = auditableEventQueryProcessor.convertToSQL((RegistryObjectQueryType)filterQueryRequest.getAuditableEventQuery()); 63 } 64 else if (filterQueryRequest.getClassificationQuery() != null) { 65 ClassificationQueryProcessor classificationQueryProcessor = new ClassificationQueryProcessor(); 66 sqlQuery = classificationQueryProcessor.convertToSQL((RegistryObjectQueryType)filterQueryRequest.getClassificationQuery()); 67 } 68 else if (filterQueryRequest.getClassificationNodeQuery() != null) { 69 ClassificationNodeQueryProcessor classificationNodeQueryProcessor = new ClassificationNodeQueryProcessor(); 70 sqlQuery = classificationNodeQueryProcessor.convertToSQL((RegistryObjectQueryType)filterQueryRequest.getClassificationNodeQuery()); 71 } 72 else if (filterQueryRequest.getClassificationSchemeQuery() != null) { 73 ClassificationSchemeQueryProcessor classificationSchemeQueryProcessor = new ClassificationSchemeQueryProcessor(); 74 sqlQuery = classificationSchemeQueryProcessor.convertToSQL((RegistryObjectQueryType)filterQueryRequest.getClassificationSchemeQuery()); 75 } 76 else if (filterQueryRequest.getExtrinsicObjectQuery() != null) { 77 ExtrinsicObjectQueryProcessor extrinsicObjectQueryProcessor = new ExtrinsicObjectQueryProcessor(); 78 sqlQuery = extrinsicObjectQueryProcessor.convertToSQL((RegistryObjectQueryType)filterQueryRequest.getExtrinsicObjectQuery()); 79 } 80 else if (filterQueryRequest.getOrganizationQuery() != null) { 81 OrganizationQueryProcessor organizationQueryProcessor = new OrganizationQueryProcessor(); 82 sqlQuery = organizationQueryProcessor.convertToSQL((RegistryObjectQueryType)filterQueryRequest.getOrganizationQuery()); 83 } 84 else if (filterQueryRequest.getRegistryPackageQuery() != null) { 85 RegistryPackageQueryProcessor registryPackageQueryProcessor = new RegistryPackageQueryProcessor(); 86 sqlQuery = registryPackageQueryProcessor.convertToSQL((RegistryObjectQueryType)filterQueryRequest.getRegistryPackageQuery()); 87 } 88 else if (filterQueryRequest.getServiceQuery() != null) { 89 ServiceQueryProcessor serviceQueryProcessor = new ServiceQueryProcessor(); 90 sqlQuery = serviceQueryProcessor.convertToSQL((RegistryObjectQueryType)filterQueryRequest.getServiceQuery()); 91 } 92 else { 93 throw new RegistryException("Unexpected Filter Query Request " + filterQueryRequest); 94 } 95 96 response = sqlQueryProcessor.executeQuery(user, sqlQuery, responseOption); 97 response = fixAdhocQueryResponseXSLT(filterQueryRequest, response); 98 99 return response; 100 } 101 102 103 public static FilterQueryProcessor getInstance(){ 104 105 if (instance == null) { 106 synchronized(com.sun.ebxml.registry.query.filter.FilterQueryProcessor.class) { 107 if (instance == null) { 108 instance = new com.sun.ebxml.registry.query.filter.FilterQueryProcessor(); 109 } 110 } 111 } 112 113 return instance; 114 } 115 116 117 protected FilterQueryProcessor(){} 118 119 120 /*** 121 * Fixes the AdhocQueryResponse to have a FilterQueryResult instead of SQLQueryResult. 122 * Uses XSLT instead of castor stuff. 123 */ 124 private AdhocQueryResponse fixAdhocQueryResponseXSLT(FilterQuery fqReq, AdhocQueryResponse resp) throws RegistryException { 125 126 try { 127 128 //Determine param1 which is teh sub-element of FilterQueryResult 129 String param1 = null; 130 131 if (fqReq.getAssociationQuery() != null) { 132 param1 = "AssociationQueryResult"; 133 } 134 else if (fqReq.getAuditableEventQuery() != null) { 135 param1 = "AuditableEventQueryResult"; 136 } 137 else if (fqReq.getClassificationNodeQuery() != null) { 138 param1 = "ClassificationNodeQueryResult"; 139 } 140 else if (fqReq.getClassificationQuery() != null) { 141 param1 = "ClassificationQueryResult"; 142 } 143 else if (fqReq.getClassificationSchemeQuery() != null) { 144 param1 = "ClassificationSchemeQueryResult"; 145 } 146 else if (fqReq.getExtrinsicObjectQuery() != null) { 147 param1 = "ExtrinsicObjectQueryResult"; 148 } 149 else if (fqReq.getOrganizationQuery() != null) { 150 param1 = "OrganizationQueryResult"; 151 } 152 else if (fqReq.getRegistryEntryQuery() != null) { 153 param1 = "RegistryEntryQueryResult"; 154 } 155 else if (fqReq.getRegistryObjectQuery() != null) { 156 param1 = "RegistryObjectQueryResult"; 157 } 158 else if (fqReq.getRegistryPackageQuery() != null) { 159 param1 = "RegistryPackageQueryResult"; 160 } 161 else if (fqReq.getServiceQuery() != null) { 162 param1 = "ServiceQueryResult"; 163 } 164 else { 165 throw new RegistryException("Unknown sub-element of FilterQuery"); 166 } 167 168 TransformerFactory tFactory = TransformerFactory.newInstance(); 169 File xslFile = new File(RegistryProperties.getInstance().getProperty("ebxmlrr.home"), 170 "data" + File.separator + "xsl" + File.separator + "sqlQueryResultToFilterQueryResult.xsl"); 171 Transformer transformer = tFactory.newTransformer(new StreamSource(xslFile)); 172 173 StringWriter sw = new StringWriter(); 174 resp.marshal(sw); 175 176 StringReader sr = new StringReader(sw.toString()); 177 StreamSource input = new StreamSource(sr); 178 sw = new StringWriter(); 179 180 transformer.setParameter("param1", param1); 181 transformer.transform(input, new StreamResult(sw)); 182 183 sr = new StringReader(sw.toString()); 184 AdhocQueryResponse newResp = resp.unmarshal(sr); 185 return newResp; 186 } 187 catch (TransformerConfigurationException e) { 188 throw new RegistryException(e); 189 } 190 catch (TransformerException e) { 191 throw new RegistryException(e); 192 } 193 catch (org.exolab.castor.xml.MarshalException e) { 194 throw new RegistryException(e); 195 } 196 catch (org.exolab.castor.xml.ValidationException e) { 197 throw new RegistryException(e); 198 } 199 } 200 }

This page was automatically generated by Maven