1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.function;
17
18 import java.util.Vector;
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
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 generic = request.getGeneric();
58 Vector businessKeyVector = request.getBusinessKeyVector();
59
60
61 DataStore dataStore = DataStoreFactory.getDataStore();
62
63 try
64 {
65 dataStore.beginTrans();
66
67
68 for (int i=0; i<businessKeyVector.size(); i++)
69 {
70 String businessKey = (String)businessKeyVector.elementAt(i);
71
72
73 if ((businessKey == null) || (businessKey.length() == 0) ||
74 (!dataStore.isValidBusinessKey(businessKey)))
75 throw new InvalidKeyPassedException("get_businessDetailExt: "+
76 "businessKey="+businessKey);
77 }
78
79 Vector businessEntityExtVector = new Vector();
80
81 for (int i=0; i<businessKeyVector.size(); i++)
82 {
83 String businessKey = (String)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
92
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 e) { }
102 log.info(keyex.getMessage());
103 throw (RegistryException)keyex;
104 }
105 catch(RegistryException regex)
106 {
107 try { dataStore.rollback(); } catch(Exception e) { }
108 log.error(regex);
109 throw (RegistryException)regex;
110 }
111 catch(Exception ex)
112 {
113 try { dataStore.rollback(); } catch(Exception 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[] args)
131 {
132
133 RegistryEngine reg = new RegistryEngine();
134 reg.init();
135
136 try
137 {
138 }
139 catch (Exception ex)
140 {
141
142 ex.printStackTrace();
143 }
144 finally
145 {
146
147 reg.dispose();
148 }
149 }
150 }