This project has retired. For details please refer to its Attic page.
Finder xref
View Javadoc
1   /**
2    *
3    * Copyright 2004 The Apache Software Foundation
4    *
5    *  Licensed under the Apache License, Version 2.0 (the "License");
6    *  you may not use this file except in compliance with the License.
7    *  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   *  Unless required by applicable law or agreed to in writing, software
12   *  distributed under the License is distributed on an "AS IS" BASIS,
13   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   *  See the License for the specific language governing permissions and
15   *  limitations under the License.
16   */
17  package org.apache.ws.scout;
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.Iterator;
22  
23  import javax.xml.registry.BulkResponse;
24  import javax.xml.registry.BusinessLifeCycleManager;
25  import javax.xml.registry.BusinessQueryManager;
26  import javax.xml.registry.FindQualifier;
27  import javax.xml.registry.JAXRException;
28  import javax.xml.registry.JAXRResponse;
29  import javax.xml.registry.infomodel.Classification;
30  import javax.xml.registry.infomodel.ClassificationScheme;
31  import javax.xml.registry.infomodel.Key;
32  import javax.xml.registry.infomodel.Service;
33  import javax.xml.registry.infomodel.ServiceBinding;
34  import javax.xml.registry.infomodel.SpecificationLink;
35  
36  /**
37   * Find RegistryObjects
38   * 
39   * @author <a href="mailto:kstam@apache.org">Kurt Stam</a>
40   * 
41   */
42  public class Finder
43  {
44      private BusinessQueryManager bqm;
45      private String uddiVersion;
46      
47      public Finder(BusinessQueryManager bqm, String version) {
48      	super();
49      	this.bqm = bqm;
50      	this.uddiVersion = version;
51      }
52  
53      public Collection findOrganizationsByName(String queryStr) throws JAXRException {
54      	// Define find qualifiers and name patterns
55      	Collection<String> findQualifiers = new ArrayList<String>();
56      	findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
57      	Collection<String> namePatterns = new ArrayList<String>();
58      	if ("3.0".equals(uddiVersion)) {
59      		namePatterns.add(queryStr);
60      	} else {
61      		namePatterns.add("%" + queryStr + "%");
62      	}
63      	// Find based upon qualifier type and values
64      	System.out.println("\n-- searching the registry --\n");
65          BulkResponse response =
66      		bqm.findOrganizations(findQualifiers,
67      				namePatterns,
68      				null,
69      				null,
70      				null,
71      				null);
72      	
73      	return response.getCollection();
74      }
75      
76      public Collection findClassificationSchemesByName(String queryStr) throws JAXRException {
77          // Define find qualifiers and name patterns
78          Collection<String> findQualifiers = new ArrayList<String>();
79          findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
80          Collection<String> namePatterns = new ArrayList<String>();
81          if ("3.0".equals(uddiVersion)) {
82          	namePatterns.add(queryStr);
83          } else {
84          	namePatterns.add("%" + queryStr + "%");
85          }
86          // Find based upon qualifier type and values
87          System.out.println("\n-- searching the registry --\n");
88          BulkResponse response =
89              bqm.findClassificationSchemes(findQualifiers,
90                      namePatterns,
91                      null,
92                      null);
93          
94          return response.getCollection();
95      }
96      
97      public ClassificationScheme findClassificationSchemeByName(String queryStr) throws JAXRException {
98          // Define find qualifiers and name patterns
99          Collection<String> findQualifiers = new ArrayList<String>();
100         findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
101         Collection<String> namePatterns = new ArrayList<String>();
102         namePatterns.add(queryStr);
103         
104         // Find based upon qualifier type and values
105         System.out.println("\n-- searching the registry --\n");
106         BulkResponse response =
107             bqm.findClassificationSchemes(findQualifiers,
108                     namePatterns,
109                     null,
110                     null);
111         if ((response == null) || (response.getCollection() == null) || (response.getCollection().size() ==0) ) {
112         	return null;
113         }
114         
115         return (ClassificationScheme) response.getCollection().iterator().next();
116     }
117     
118     /**
119      * Search a service, by matching the name and the classification.
120      * 
121      * @param category - name of the category classification
122      * @param serviceName - name of the service
123      * @param blm
124      * @return JAXR Service
125      * @throws JAXRException
126      */
127     public Service findService(String category, String serviceName, BusinessLifeCycleManager blm) throws JAXRException
128     {
129         if (category==null) {
130             category="";
131         }
132         if (serviceName==null) {
133             serviceName="";
134         }  
135         // Define find qualifiers and name patterns
136         Collection<String> findQualifiers = new ArrayList<String>();
137         findQualifiers.add(FindQualifier.AND_ALL_KEYS);
138         findQualifiers.add(FindQualifier.EXACT_NAME_MATCH);
139         findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
140         ClassificationScheme cScheme = bqm.findClassificationSchemeByName(findQualifiers, "org.jboss.soa.esb.:testcategory");
141         Collection<Classification> classifications = new ArrayList<Classification>();
142         Classification classification = 
143             blm.createClassification( 
144               cScheme, 
145               "category", category );
146         classifications.add(classification);
147         Collection<String> namePatterns = new ArrayList<String>();
148         namePatterns.add(serviceName);
149         //Find based upon qualifier type and values
150         BulkResponse response = bqm.findServices(null, findQualifiers,
151                 namePatterns, classifications, null);
152         if (response.getStatus()==JAXRResponse.STATUS_SUCCESS) {
153             for (Iterator servIter = response.getCollection().iterator(); servIter.hasNext();) 
154             {
155                 Service service = (Service) servIter.next();
156                 return service;
157             }
158         }
159         return null;
160     }
161     
162     @SuppressWarnings("unchecked")
163     public Collection<ServiceBinding> findServiceBindings(Key serviceKey) throws JAXRException
164     {
165         Collection<ServiceBinding> serviceBindings=null;
166         Collection<String> findQualifiers = new ArrayList<String>();
167         findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
168         BulkResponse bulkResponse = bqm.findServiceBindings(serviceKey,findQualifiers,null,null);
169         if (bulkResponse.getStatus()==JAXRResponse.STATUS_SUCCESS){
170             serviceBindings = (Collection<ServiceBinding>) bulkResponse.getCollection();
171         }
172         return serviceBindings;
173     }
174 
175     @SuppressWarnings("unchecked")
176     public Collection<ServiceBinding> findServiceBindings(Key serviceKey, Classification classification) throws JAXRException
177     {
178         Collection<ServiceBinding> serviceBindings=null;
179         Collection<String> findQualifiers = new ArrayList<String>();
180         Collection<Classification> classifications = new ArrayList<Classification>();
181         classifications.add(classification);
182         BulkResponse bulkResponse = bqm.findServiceBindings(serviceKey,findQualifiers,classifications,null);
183         if (bulkResponse.getStatus()==JAXRResponse.STATUS_SUCCESS){
184             serviceBindings = (Collection<ServiceBinding>) bulkResponse.getCollection();
185         }
186         return serviceBindings;
187     }
188 
189     
190     
191     @SuppressWarnings("unchecked")
192     public Collection<ServiceBinding> findServiceBindings(Key serviceKey, SpecificationLink specLink) throws JAXRException
193     {
194         Collection<ServiceBinding> serviceBindings=null;
195         Collection<String> findQualifiers = new ArrayList<String>();
196         Collection<SpecificationLink> specifications = new ArrayList<SpecificationLink>();
197         specifications.add(specLink);
198         BulkResponse bulkResponse = bqm.findServiceBindings(serviceKey,findQualifiers,null,specifications);
199         if (bulkResponse.getStatus()==JAXRResponse.STATUS_SUCCESS){
200             serviceBindings = (Collection<ServiceBinding>) bulkResponse.getCollection();
201         }
202         return serviceBindings;
203     }
204 }