KickJava   Java API By Example, From Geeks To Geeks.

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


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.GetPublisherDetail;
26 import org.apache.juddi.datatype.response.PublisherDetail;
27 import org.apache.juddi.error.RegistryException;
28 import org.apache.juddi.error.UnknownUserException;
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 GetPublisherDetailFunction extends AbstractFunction
36 {
37   // private reference to jUDDI Logger
38
private static Log log = LogFactory.getLog(GetPublisherDetailFunction.class);
39
40   /**
41    *
42    */

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

51   public RegistryObject execute(RegistryObject regObject)
52     throws RegistryException
53   {
54     GetPublisherDetail request = (GetPublisherDetail)regObject;
55     String JavaDoc generic = request.getGeneric();
56     Vector JavaDoc idVector = request.getPublisherIDVector();
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<idVector.size(); i++)
66       {
67         String JavaDoc publisherID = (String JavaDoc)idVector.elementAt(i);
68
69         // If the a Publisher doesn't exist hrow an UnknownUserException.
70
if ((publisherID == null) || (publisherID.length() == 0) ||
71             (dataStore.getPublisher(publisherID) == null))
72           throw new UnknownUserException("get_publisher: "+
73               "userID="+publisherID);
74       }
75
76       Vector JavaDoc publisherVector = new Vector JavaDoc();
77
78       for (int i=0; i<idVector.size(); i++)
79       {
80         String JavaDoc publisherID = (String JavaDoc)idVector.elementAt(i);
81         publisherVector.add(dataStore.getPublisher(publisherID));
82       }
83
84       dataStore.commit();
85
86       // create a new PublisherDetail and stuff the new tModelVector into it.
87
PublisherDetail detail = new PublisherDetail();
88       detail.setGeneric(generic);
89       detail.setPublisherVector(publisherVector);
90       detail.setOperator(Config.getOperator());
91       return detail;
92     }
93     catch(UnknownUserException ukuex)
94     {
95       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
96       log.info(ukuex.getMessage());
97       throw (RegistryException)ukuex;
98     }
99     catch(RegistryException regex)
100     {
101       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
102       log.error(regex);
103       throw (RegistryException)regex;
104     }
105     catch(Exception JavaDoc ex)
106     {
107       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
108       log.error(ex);
109       throw new RegistryException(ex);
110     }
111     finally
112     {
113       if (dataStore != null)
114         dataStore.release();
115     }
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 }
Popular Tags