KickJava   Java API By Example, From Geeks To Geeks.

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


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.GetBindingDetail;
26 import org.apache.juddi.datatype.response.BindingDetail;
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  * @author Steve Viens (sviens@apache.org)
34  */

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

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

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