View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/ebxmlrr/src/share/com/sun/ebxml/registry/query/filter/OrganizationQueryProcessor.java,v 1.9 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 OrganizationQueryProcessor 22 * @see 23 * @author Nikola Stojanovic 24 */ 25 public class OrganizationQueryProcessor extends RegistryObjectQueryProcessor { 26 27 private OrganizationQuery organizationQuery = null; 28 29 30 protected String getName() { 31 32 return "Organization"; 33 } 34 35 36 protected void setNativeQuery(RegistryObjectQueryType query) { 37 38 organizationQuery = (OrganizationQuery)query; 39 super.setNativeQuery((RegistryObjectQueryType)organizationQuery); 40 } 41 42 43 protected void buildFilterClauses() throws RegistryException { 44 45 convertOrganizationFilter(); 46 convertPostalAddressFilter(); 47 convertTelephoneNumberFilters(); 48 super.buildFilterClauses(); 49 } 50 51 52 protected void buildQueryClauses() throws RegistryException { 53 54 super.buildQueryClauses(); 55 } 56 57 58 protected void buildBranchClauses() throws RegistryException { 59 60 convertUserBranch(); 61 convertOrganizationParentBranch(); 62 convertOrganizationChildrenBranches(); 63 super.buildBranchClauses(); 64 } 65 66 67 private void convertOrganizationFilter() throws RegistryException { 68 69 if (organizationQuery.getOrganizationFilter() != null) { 70 whereClause = filterProcessor.addNativeWhereClause(whereClause, organizationQuery.getOrganizationFilter()); 71 } 72 } 73 74 75 private void convertPostalAddressFilter() throws RegistryException { 76 77 if (organizationQuery.getPostalAddressFilter() != null) { 78 filterProcessor.setSelectColumn("parent"); 79 whereClause = filterProcessor.addForeignWhereClause(whereClause, organizationQuery.getPostalAddressFilter()); 80 } 81 } 82 83 84 private void convertTelephoneNumberFilters() throws RegistryException { 85 86 TelephoneNumberFilter[] telFilter = organizationQuery.getTelephoneNumberFilter(); 87 88 if (telFilter.length > 0) { 89 filterProcessor.setSelectColumn("parent"); 90 91 for (int i=0; i<telFilter.length; i++) { 92 whereClause = filterProcessor.addForeignWhereClause(whereClause, telFilter[i]); 93 } 94 } 95 } 96 97 98 private void convertUserBranch() throws RegistryException { 99 100 if (organizationQuery.getUserBranch() != null) { 101 UserBranchProcessor branchProcessor = new UserBranchProcessor(); 102 branchProcessor.setParentJoinColumn("primaryContact"); 103 branchProcessor.setSelectColumn("id"); 104 whereClause = branchProcessor.addWhereClause(whereClause, organizationQuery.getUserBranch()); 105 } 106 } 107 108 109 private void convertOrganizationParentBranch() throws RegistryException { 110 111 if (organizationQuery.getOrganizationParentBranch() != null) { 112 OrganizationQueryProcessor queryProcessor = new OrganizationQueryProcessor(); 113 OrganizationQuery query = new OrganizationQuery(); 114 queryProcessor.setParentJoinColumn("parent"); 115 queryProcessor.setSelectColumn("id"); 116 query = translateBranchIntoQuery(organizationQuery.getOrganizationParentBranch()); 117 whereClause = queryProcessor.addWhereClause(whereClause, query); 118 } 119 } 120 121 122 private void convertOrganizationChildrenBranches() throws RegistryException { 123 124 OrganizationChildrenBranch[] organizationChildrenBranch = organizationQuery.getOrganizationChildrenBranch(); 125 126 if (organizationChildrenBranch.length > 0) { 127 OrganizationQuery query = new OrganizationQuery(); 128 129 for (int i=0; i<organizationChildrenBranch.length; i++) { 130 OrganizationQueryProcessor queryProcessor = new OrganizationQueryProcessor(); 131 queryProcessor.setParentJoinColumn("id"); 132 queryProcessor.setSelectColumn("parent"); 133 query = translateBranchIntoQuery(organizationChildrenBranch[i]); 134 whereClause = queryProcessor.addWhereClause(whereClause, query); 135 } 136 } 137 } 138 139 140 private OrganizationQuery translateBranchIntoQuery(OrganizationQueryType branch) throws RegistryException { 141 142 OrganizationQuery organizationQuery = null; 143 144 try { 145 TransformerFactory tFactory = TransformerFactory.newInstance(); 146 String xslFileURL = "file://" + RegistryProperties.getInstance().getProperty("ebxmlrr.home") + "/data/xsl/sqlQueryResultToFilterQueryResult.xsl"; 147 Transformer transformer = tFactory.newTransformer(new StreamSource(xslFileURL)); 148 transformer.setParameter("outputQuery", "OrganizationQuery"); 149 150 StringWriter sw = new StringWriter(); 151 branch.marshal(sw); 152 StringReader sr = new StringReader(sw.toString()); 153 StreamSource input = new StreamSource(sr); 154 155 sw = new StringWriter(); 156 transformer.transform(input, new StreamResult(sw)); 157 sr = new StringReader(sw.toString()); 158 159 organizationQuery = OrganizationQuery.unmarshal(sr); 160 } 161 // these Exceptions should already be caught by Binding 162 catch (TransformerConfigurationException e) { 163 throw new RegistryException(e); 164 } 165 catch (TransformerException e) { 166 throw new RegistryException(e); 167 } 168 catch (MarshalException e) { 169 throw new RegistryException(e); 170 } 171 catch (ValidationException e) { 172 throw new RegistryException(e); 173 } 174 175 return organizationQuery; 176 } 177 }

This page was automatically generated by Maven