KickJava   Java API By Example, From Geeks To Geeks.

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


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.publisher.Publisher;
26 import org.apache.juddi.datatype.request.AuthInfo;
27 import org.apache.juddi.datatype.request.GetRegisteredInfo;
28 import org.apache.juddi.datatype.response.BusinessInfos;
29 import org.apache.juddi.datatype.response.RegisteredInfo;
30 import org.apache.juddi.datatype.response.TModelInfos;
31 import org.apache.juddi.error.RegistryException;
32 import org.apache.juddi.registry.RegistryEngine;
33 import org.apache.juddi.util.Config;
34
35 /**
36  * @author Steve Viens (sviens@apache.org)
37  */

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

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

54   public RegistryObject execute(RegistryObject regObject)
55     throws RegistryException
56   {
57     GetRegisteredInfo request = (GetRegisteredInfo)regObject;
58     String JavaDoc generic = request.getGeneric();
59     AuthInfo authInfo = request.getAuthInfo();
60
61     // aquire a jUDDI datastore instance
62
DataStore dataStore = DataStoreFactory.getDataStore();
63
64     try
65     {
66       dataStore.beginTrans();
67
68       // validate authentication parameters
69
Publisher publisher = getPublisher(authInfo,dataStore);
70       String JavaDoc publisherID = publisher.getPublisherID();
71
72       // validate request parameters
73
// nothing that requires validation has been identified
74

75       // declare some 'work' variables
76
BusinessInfos businessInfos = new BusinessInfos();
77       TModelInfos tModelInfos = new TModelInfos();
78       Vector JavaDoc keyVector = null;
79       Vector JavaDoc infoVector = null;
80
81       // perform the search for BusinessEntities registered to publisherID
82
keyVector = dataStore.findRegisteredBusinesses(publisherID);
83       if ((keyVector != null) && (keyVector.size() > 0))
84       {
85         int rowCount = keyVector.size();
86
87         // iterate through the business entity keys fetching each associated BusinessInfo.
88
infoVector = new Vector JavaDoc(rowCount);
89         for (int i=0; i<rowCount; i++)
90           infoVector.addElement(dataStore.fetchBusinessInfo((String JavaDoc)keyVector.elementAt(i)));
91
92         businessInfos.setBusinessInfoVector(infoVector);
93       }
94
95       // perform the search for TModels registered to publisherID
96
keyVector = dataStore.findRegisteredTModels(publisherID);
97       if ((keyVector != null) && (keyVector.size() > 0))
98       {
99         int rowCount = keyVector.size();
100
101         // iterate through the tModel keys fetching each associated TModelInfo.
102
infoVector = new Vector JavaDoc(rowCount);
103         for (int i=0; i<rowCount; i++)
104           infoVector.addElement(dataStore.fetchTModelInfo((String JavaDoc)keyVector.elementAt(i)));
105
106         tModelInfos.setTModelInfoVector(infoVector);
107       }
108
109       dataStore.commit();
110
111       // create a new BusinessInfos instance and stuff
112
// the new Vector of BusinessInfos into it.
113
RegisteredInfo info = new RegisteredInfo();
114       info.setGeneric(generic);
115       info.setOperator(Config.getOperator());
116       info.setBusinessInfos(businessInfos);
117       info.setTModelInfos(tModelInfos);
118       return info;
119     }
120     catch(RegistryException regex)
121     {
122       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
123       log.error(regex);
124       throw (RegistryException)regex;
125     }
126     catch(Exception JavaDoc ex)
127     {
128       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
129       log.error(ex);
130       throw new RegistryException(ex);
131     }
132     finally
133     {
134       if (dataStore != null)
135         dataStore.release();
136     }
137   }
138
139
140   /***************************************************************************/
141   /***************************** TEST DRIVER *********************************/
142   /***************************************************************************/
143
144
145   public static void main(String JavaDoc[] args)
146   {
147     // initialize the registry
148
RegistryEngine reg = new RegistryEngine();
149     reg.init();
150
151     try
152     {
153     }
154     catch (Exception JavaDoc ex)
155     {
156       // write execption to the console
157
ex.printStackTrace();
158     }
159     finally
160     {
161       // destroy the registry
162
reg.dispose();
163     }
164   }
165 }
Popular Tags