001: /**
002: *
003: * Copyright 2004 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.ws.scout;
017:
018: import java.util.ArrayList;
019: import java.util.Collection;
020: import java.util.Iterator;
021:
022: import javax.xml.registry.BulkResponse;
023: import javax.xml.registry.BusinessLifeCycleManager;
024: import javax.xml.registry.BusinessQueryManager;
025: import javax.xml.registry.FindQualifier;
026: import javax.xml.registry.JAXRException;
027: import javax.xml.registry.JAXRResponse;
028: import javax.xml.registry.infomodel.Classification;
029: import javax.xml.registry.infomodel.ClassificationScheme;
030: import javax.xml.registry.infomodel.Key;
031: import javax.xml.registry.infomodel.Service;
032: import javax.xml.registry.infomodel.ServiceBinding;
033:
034: /**
035: * Find RegistryObjects
036: *
037: * @author <a href="mailto:kstam@apache.org">Kurt Stam</a>
038: *
039: */
040: public class Finder {
041: private BusinessQueryManager bqm;
042:
043: public Finder(BusinessQueryManager bqm) {
044: super ();
045: this .bqm = bqm;
046: }
047:
048: public Collection findOrganizationsByName(String queryStr)
049: throws JAXRException {
050: // Define find qualifiers and name patterns
051: Collection<String> findQualifiers = new ArrayList<String>();
052: findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
053: Collection<String> namePatterns = new ArrayList<String>();
054: namePatterns.add("%" + queryStr + "%");
055:
056: // Find based upon qualifier type and values
057: System.out.println("\n-- searching the registry --\n");
058: BulkResponse response = bqm.findOrganizations(findQualifiers,
059: namePatterns, null, null, null, null);
060:
061: return response.getCollection();
062: }
063:
064: public Collection findClassificationSchemesByName(String queryStr)
065: throws JAXRException {
066: // Define find qualifiers and name patterns
067: Collection<String> findQualifiers = new ArrayList<String>();
068: findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
069: Collection<String> namePatterns = new ArrayList<String>();
070: namePatterns.add("%" + queryStr + "%");
071:
072: // Find based upon qualifier type and values
073: System.out.println("\n-- searching the registry --\n");
074: BulkResponse response = bqm.findClassificationSchemes(
075: findQualifiers, namePatterns, null, null);
076:
077: return response.getCollection();
078: }
079:
080: public ClassificationScheme findClassificationSchemeByName(
081: String queryStr) throws JAXRException {
082: // Define find qualifiers and name patterns
083: Collection<String> findQualifiers = new ArrayList<String>();
084: findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
085: Collection<String> namePatterns = new ArrayList<String>();
086: namePatterns.add("%" + queryStr + "%");
087:
088: // Find based upon qualifier type and values
089: System.out.println("\n-- searching the registry --\n");
090: BulkResponse response = bqm.findClassificationSchemes(
091: findQualifiers, namePatterns, null, null);
092:
093: return (ClassificationScheme) response.getCollection()
094: .iterator().next();
095: }
096:
097: /**
098: * Search a service, by matching the name and the classification.
099: *
100: * @param category - name of the category classification
101: * @param serviceName - name of the service
102: * @param blm
103: * @return JAXR Service
104: * @throws JAXRException
105: */
106: public Service findService(String category, String serviceName,
107: BusinessLifeCycleManager blm) throws JAXRException {
108: if (category == null) {
109: category = "";
110: }
111: if (serviceName == null) {
112: serviceName = "";
113: }
114: // Define find qualifiers and name patterns
115: Collection<String> findQualifiers = new ArrayList<String>();
116: findQualifiers.add(FindQualifier.AND_ALL_KEYS);
117: findQualifiers.add(FindQualifier.EXACT_NAME_MATCH);
118: findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
119: ClassificationScheme cScheme = bqm
120: .findClassificationSchemeByName(findQualifiers,
121: "org.jboss.soa.esb.:testcategory");
122: Collection<Classification> classifications = new ArrayList<Classification>();
123: Classification classification = blm.createClassification(
124: cScheme, "category", category);
125: classifications.add(classification);
126: Collection<String> namePatterns = new ArrayList<String>();
127: namePatterns.add(serviceName);
128: //Find based upon qualifier type and values
129: BulkResponse response = bqm.findServices(null, findQualifiers,
130: namePatterns, classifications, null);
131: if (response.getStatus() == JAXRResponse.STATUS_SUCCESS) {
132: for (Iterator servIter = response.getCollection()
133: .iterator(); servIter.hasNext();) {
134: Service service = (Service) servIter.next();
135: return service;
136: }
137: }
138: return null;
139: }
140:
141: @SuppressWarnings("unchecked")
142: public Collection<ServiceBinding> findServiceBindings(Key serviceKey)
143: throws JAXRException {
144: Collection<ServiceBinding> serviceBindings = null;
145: Collection<String> findQualifiers = new ArrayList<String>();
146: findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
147: BulkResponse bulkResponse = bqm.findServiceBindings(serviceKey,
148: findQualifiers, null, null);
149: if (bulkResponse.getStatus() == JAXRResponse.STATUS_SUCCESS) {
150: serviceBindings = (Collection<ServiceBinding>) bulkResponse
151: .getCollection();
152: }
153: return serviceBindings;
154: }
155:
156: }
|