KickJava   Java API By Example, From Geeks To Geeks.

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


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.business.BusinessEntity;
26 import org.apache.juddi.datatype.business.BusinessEntityExt;
27 import org.apache.juddi.datatype.request.GetBusinessDetailExt;
28 import org.apache.juddi.datatype.response.BusinessDetailExt;
29 import org.apache.juddi.error.InvalidKeyPassedException;
30 import org.apache.juddi.error.RegistryException;
31 import org.apache.juddi.registry.RegistryEngine;
32 import org.apache.juddi.util.Config;
33
34 /**
35  * @author Steve Viens (sviens@apache.org)
36  */

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

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

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