View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/ebxmlrr/src/share/com/sun/ebxml/registry/query/filter/RegistryPackageQueryProcessor.java,v 1.6 2002/03/25 04:13:14 nstojano Exp $ 3 */ 4 5 package com.sun.ebxml.registry.query.filter; 6 7 import java.io.*; 8 9 import com.sun.ebxml.registry.*; 10 11 import org.exolab.castor.xml.*; 12 13 import org.oasis.ebxml.registry.bindings.query.*; 14 import org.oasis.ebxml.registry.bindings.rs.*; 15 16 /*** 17 * Class Declaration for RegistryPackageQueryProcessor 18 * @see 19 * @author Nikola Stojanovic 20 */ 21 public class RegistryPackageQueryProcessor extends RegistryEntryQueryProcessor { 22 23 private RegistryPackageQuery registryPackageQuery = null; 24 25 26 protected String getName() { 27 28 return "RegistryPackage"; 29 } 30 31 32 protected void setNativeQuery(RegistryObjectQueryType query) { 33 34 registryPackageQuery = (RegistryPackageQuery)query; 35 super.setNativeQuery((RegistryObjectQueryType)registryPackageQuery); 36 } 37 38 39 protected void buildFilterClauses() throws RegistryException { 40 41 convertRegistryPackageFilter(); 42 super.buildFilterClauses(); 43 } 44 45 46 protected void buildQueryClauses() throws RegistryException { 47 48 convertRegistryObjectQueries(); 49 convertRegistryEntryQueries(); 50 super.buildQueryClauses(); 51 } 52 53 54 protected void buildBranchClauses() throws RegistryException { 55 56 super.buildBranchClauses(); 57 } 58 59 60 private void convertRegistryPackageFilter() throws RegistryException { 61 62 if (registryPackageQuery.getRegistryPackageFilter() != null) { 63 whereClause = filterProcessor.addNativeWhereClause(whereClause, registryPackageQuery.getRegistryPackageFilter()); 64 } 65 } 66 67 68 private void convertRegistryObjectQueries() throws RegistryException { 69 70 RegistryObjectQuery[] registryObjectQuery = registryPackageQuery.getRegistryObjectQuery(); 71 72 if (registryObjectQuery.length > 0) { 73 AssociationBranchProcessor branchProcessor = new AssociationBranchProcessor(); 74 75 for (int i=0; i<registryObjectQuery.length; i++) { 76 SourceAssociationBranch branch = translateContainmentIntoAssociation(registryObjectQuery[i]); 77 branchProcessor.setSelectColumn("sourceObject"); 78 whereClause = branchProcessor.addWhereClause(whereClause, branch); 79 } 80 } 81 } 82 83 84 private void convertRegistryEntryQueries() throws RegistryException { 85 86 RegistryEntryQuery[] registryEntryQuery = registryPackageQuery.getRegistryEntryQuery(); 87 88 if (registryEntryQuery.length > 0) { 89 AssociationBranchProcessor branchProcessor = new AssociationBranchProcessor(); 90 91 for (int i=0; i<registryEntryQuery.length; i++) { 92 SourceAssociationBranch branch = translateContainmentIntoAssociation(registryEntryQuery[i]); 93 branchProcessor.setSelectColumn("sourceObject"); 94 whereClause = branchProcessor.addWhereClause(whereClause, branch); 95 } 96 } 97 } 98 99 100 private SourceAssociationBranch translateContainmentIntoAssociation(RegistryObjectQueryType query) { 101 SourceAssociationBranch packageAssociation = null; 102 String prefix = "<SourceAssociationBranch><AssociationFilter><Clause><SimpleClause leftArgument = \"associationType\"><StringClause stringPredicate = \"Equal\">HasMember</StringClause></SimpleClause></Clause></AssociationFilter>"; 103 String postfix = "</SourceAssociationBranch>"; 104 105 try { 106 StringWriter writer = new StringWriter(); 107 writer.write(prefix); 108 Marshaller marshaller = new Marshaller(writer); 109 marshaller.setMarshalAsDocument(false); 110 marshaller.marshal(query); 111 writer.write(postfix); 112 StringReader sr = new StringReader(writer.toString()); 113 packageAssociation = SourceAssociationBranch.unmarshal(sr); 114 } 115 // these Exceptions should already be caught by Binding 116 catch (IOException e) { 117 e.printStackTrace(); 118 } 119 catch (MarshalException e) { 120 e.printStackTrace(); 121 } 122 catch (ValidationException e) { 123 e.printStackTrace(); 124 } 125 126 return packageAssociation; 127 } 128 }

This page was automatically generated by Maven