KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > function > GetServiceDetailFunction


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.juddi.function;
17
18 import java.util.Vector JavaDoc;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.juddi.datastore.DataStore;
23 import org.apache.juddi.datastore.DataStoreFactory;
24 import org.apache.juddi.datatype.RegistryObject;
25 import org.apache.juddi.datatype.request.GetServiceDetail;
26 import org.apache.juddi.datatype.response.ServiceDetail;
27 import org.apache.juddi.error.InvalidKeyPassedException;
28 import org.apache.juddi.error.RegistryException;
29 import org.apache.juddi.registry.RegistryEngine;
30 import org.apache.juddi.util.Config;
31 ;
32
33 /**
34  * @author Steve Viens (sviens@apache.org)
35  */

36 public class GetServiceDetailFunction extends AbstractFunction
37 {
38   // private reference to jUDDI Logger
39
private static Log log = LogFactory.getLog(GetServiceDetailFunction.class);
40
41   /**
42    *
43    */

44   public GetServiceDetailFunction(RegistryEngine registry)
45   {
46     super(registry);
47   }
48
49   /**
50    *
51    */

52   public RegistryObject execute(RegistryObject regObject)
53     throws RegistryException
54   {
55     GetServiceDetail request = (GetServiceDetail)regObject;
56     String JavaDoc generic = request.getGeneric();
57     Vector JavaDoc keyVector = request.getServiceKeyVector();
58
59     // aquire a jUDDI datastore instance
60
DataStore dataStore = DataStoreFactory.getDataStore();
61
62     try
63     {
64       dataStore.beginTrans();
65
66       for (int i=0; i<keyVector.size(); i++)
67       {
68         String JavaDoc serviceKey = (String JavaDoc)keyVector.elementAt(i);
69
70         // If the a BusinessService doesn't exist hrow an InvalidKeyPassedException.
71
if ((serviceKey == null) || (serviceKey.length() == 0) ||
72             (!dataStore.isValidServiceKey(serviceKey)))
73           throw new InvalidKeyPassedException("get_serviceDetail: "+
74               "serviceKey="+serviceKey);
75       }
76
77       Vector JavaDoc serviceVector = new Vector JavaDoc();
78
79       for (int i=0; i<keyVector.size(); i++)
80       {
81         String JavaDoc serviceKey = (String JavaDoc)keyVector.elementAt(i);
82         serviceVector.add(dataStore.fetchService(serviceKey));
83       }
84
85       dataStore.commit();
86
87       // create a new ServiceDetail and stuff the new serviceVector into it.
88
ServiceDetail detail = new ServiceDetail();
89       detail.setGeneric(generic);
90       detail.setOperator(Config.getOperator());
91       detail.setBusinessServiceVector(serviceVector);
92       return detail;
93     }
94     catch(InvalidKeyPassedException keyex)
95     {
96       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
97       log.info(keyex.getMessage());
98       throw (RegistryException)keyex;
99     }
100     catch(RegistryException regex)
101     {
102       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
103       log.error(regex);
104       throw (RegistryException)regex;
105     }
106     catch(Exception JavaDoc ex)
107     {
108       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
109       log.error(ex);
110       throw new RegistryException(ex);
111     }
112     finally
113     {
114       if (dataStore != null)
115         dataStore.release();
116     }
117   }
118
119
120   /***************************************************************************/
121   /***************************** TEST DRIVER *********************************/
122   /***************************************************************************/
123
124
125   public static void main(String JavaDoc[] args)
126   {
127     // initialize the registry
128
RegistryEngine reg = new RegistryEngine();
129     reg.init();
130
131     try
132     {
133     }
134     catch (Exception JavaDoc ex)
135     {
136       // write execption to the console
137
ex.printStackTrace();
138     }
139     finally
140     {
141       // destroy the registry
142
reg.dispose();
143     }
144   }
145 }
146
147
Popular Tags