KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > webservices > util > UDDIAccessBean


1 /*
2  * UDDIAccessBean.java
3  *
4  * Created on October 23, 2001, 7:39 PM
5  */

6
7 package org.apache.jetspeed.webservices.util;
8 // import javabeans packages
9
import java.io.Serializable JavaDoc;
10 // import uddi packages
11
import org.uddi4j.UDDIException;
12 import org.uddi4j.transport.TransportException;
13 import org.uddi4j.client.UDDIProxy;
14 import org.uddi4j.response.*;
15
16 // Jetspeed classes
17
import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
18 import org.apache.jetspeed.services.logging.JetspeedLogger;
19
20 /**
21  * UDDIAccessBean provides a command bean interface
22  * to UDDI registry services.
23  * Please note that currently only inquiry tasks are supported. I
24  * hope to add other task types soon.
25  * @author Scott A. Roehrig@IBM Corporation
26  * @version 1.0
27  */

28 public class UDDIAccessBean extends Object JavaDoc implements Serializable JavaDoc
29 {
30     /**
31      * Static initialization of the logger for this class
32      */

33     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(UDDIAccessBean.class.getName());
34     
35     // declare member variables
36
private transient UDDIProxy proxy;
37     private String JavaDoc queryURL;
38    
39     /** setter method for queryURL */
40     public void setQueryURL(String JavaDoc queryURL) {
41         this.queryURL = queryURL;
42     }
43     
44     /** getter method for queryURL */
45     public String JavaDoc getQueryURL() {
46         return queryURL;
47     }
48     
49     /** creates new UDDIAccessBean */
50     public UDDIAccessBean() {
51         proxy = new UDDIProxy();
52         queryURL = "http://www-3.ibm.com/services/uddi/testregistry/inquiryapi";
53     }
54     
55     /** creates new UDDIAccessBean with provided queryURL */
56     public UDDIAccessBean(String JavaDoc queryURL) {
57         proxy = new UDDIProxy();
58         this.queryURL = queryURL;
59     }
60     
61     /** performs business lookup against registry */
62     public java.util.List JavaDoc queryBusiness(String JavaDoc name) {
63         // create list to store results
64
java.util.List JavaDoc businessList = new java.util.Vector JavaDoc();
65         // perform query
66
try {
67             proxy.setInquiryURL(queryURL);
68             BusinessList results = proxy.find_business(name, null, 0);
69             businessList = results.getBusinessInfos().getBusinessInfoVector();
70             if (logger.isDebugEnabled()) {
71                 java.util.ListIterator JavaDoc iterator = businessList.listIterator();
72                 while (iterator.hasNext() == true) {
73                     org.uddi4j.response.BusinessInfo business = (org.uddi4j.response.BusinessInfo)iterator.next();
74                     logger.debug(business.getDefaultDescriptionString());
75                 }
76             }
77         }
78         catch (java.net.MalformedURLException JavaDoc exception) {
79             exception.printStackTrace();
80             if (logger.isDebugEnabled()) {
81                 logger.error(exception.getMessage(), exception);
82             }
83         }
84         catch (UDDIException exception) {
85             exception.printStackTrace();
86             if (logger.isDebugEnabled()) {
87                 logger.error(exception.getMessage(), exception);
88             }
89         }
90         catch (TransportException exception) {
91             exception.printStackTrace();
92             if (logger.isDebugEnabled()) {
93                 logger.error(exception.getMessage(), exception);
94             }
95         }
96         // return results
97
return businessList;
98     }
99     
100     /** returns businessKey object associated with provided business */
101    public String JavaDoc getBusinessKey(String JavaDoc businessName) {
102        String JavaDoc businessKey = null;
103        // create List to store results
104
java.util.List JavaDoc businessList = new java.util.Vector JavaDoc();
105        // perform query
106
try {
107             proxy.setInquiryURL(queryURL);
108             BusinessList results = proxy.find_business(businessName, null, 0);
109             businessList = results.getBusinessInfos().getBusinessInfoVector();
110             // create iterator to search for match
111
java.util.ListIterator JavaDoc iterator = businessList.listIterator();
112             while (iterator.hasNext() == true) {
113                 BusinessInfo business = (BusinessInfo)iterator.next();
114                 if (business.getNameString().equals(businessName)) {
115                     businessKey = business.getBusinessKey();
116                     if (logger.isDebugEnabled()) {
117                         logger.debug(business.getNameString()+" has associated key "+businessKey);
118                     }
119                 }
120             }
121        }
122        catch (java.net.MalformedURLException JavaDoc exception) {
123             exception.printStackTrace();
124             if (logger.isDebugEnabled()) {
125                 logger.error(exception.getMessage(), exception);
126             }
127        }
128        catch (UDDIException exception) {
129             exception.printStackTrace();
130            if (logger.isDebugEnabled()) {
131                 logger.error(exception.getMessage(), exception);
132             }
133        }
134         catch (TransportException exception) {
135             exception.printStackTrace();
136             if (logger.isDebugEnabled()) {
137                 logger.error(exception.getMessage(), exception);
138             }
139         }
140        // return result
141
return businessKey;
142    }
143    
144     /** performs service lookup against registry */
145     public java.util.List JavaDoc queryService(String JavaDoc businessKey, String JavaDoc description) {
146         // create List to store results
147
java.util.List JavaDoc serviceList = new java.util.Vector JavaDoc();
148         // perform query
149
try {
150             proxy.setInquiryURL(queryURL);
151             ServiceList results = proxy.find_service(businessKey, description, null, 0);
152             serviceList = results.getServiceInfos().getServiceInfoVector();
153             if (logger.isDebugEnabled()) {
154                 java.util.ListIterator JavaDoc iterator = serviceList.listIterator();
155                 while (iterator.hasNext() == true) {
156                     org.uddi4j.response.ServiceInfo service = (org.uddi4j.response.ServiceInfo)iterator.next();
157                     logger.debug(service.getNameString());
158                 }
159             }
160         }
161         catch (java.net.MalformedURLException JavaDoc exception) {
162             exception.printStackTrace();
163             if (logger.isDebugEnabled()) {
164                 logger.error(exception.getMessage(), exception);
165             }
166         }
167         catch (UDDIException exception) {
168             exception.printStackTrace();
169             if (logger.isDebugEnabled()) {
170                 logger.error(exception.getMessage(), exception);
171             }
172         }
173         catch (TransportException exception) {
174             exception.printStackTrace();
175             if (logger.isDebugEnabled()) {
176                 logger.error(exception.getMessage(), exception);
177             }
178         }
179         // return results
180
return serviceList;
181     }
182     
183     /** returns serviceKey associated with provided service */
184     public String JavaDoc getServiceKey(String JavaDoc businessKey, String JavaDoc serviceName) {
185         String JavaDoc serviceKey = null;
186        // create List to store results
187
java.util.List JavaDoc serviceList = new java.util.Vector JavaDoc();
188        // perform query
189
try {
190             proxy.setInquiryURL(queryURL);
191             ServiceList results = proxy.find_service(businessKey, serviceName, null, 0);
192             serviceList = results.getServiceInfos().getServiceInfoVector();
193             // create iterator to search for match
194
java.util.ListIterator JavaDoc iterator = serviceList.listIterator();
195             while (iterator.hasNext() == true) {
196                 ServiceInfo service = (ServiceInfo)iterator.next();
197                 if (service.getNameString().equals(serviceName)) {
198                     serviceKey = service.getServiceKey();
199                     if (logger.isDebugEnabled()) {
200                         logger.debug(service.getNameString()+" has associated key "+serviceKey);
201                     }
202                 }
203             }
204        }
205        catch (java.net.MalformedURLException JavaDoc exception) {
206             exception.printStackTrace();
207             if (logger.isDebugEnabled()) {
208                 logger.error(exception.getMessage(), exception);
209             }
210        }
211        catch (UDDIException exception) {
212             exception.printStackTrace();
213             if (logger.isDebugEnabled()) {
214                 logger.error(exception.getMessage(), exception);
215             }
216        }
217         catch (TransportException exception) {
218             exception.printStackTrace();
219             if (logger.isDebugEnabled()) {
220                 logger.error(exception.getMessage(), exception);
221             }
222         }
223        // return result
224
return serviceKey;
225     }
226     
227     /** called before object is garbage collected */
228     public void finalize() {
229         proxy = null;
230         queryURL = null;
231     }
232     
233 }
234
Popular Tags