KickJava   Java API By Example, From Geeks To Geeks.

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


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.KeyedReference;
25 import org.apache.juddi.datatype.Name;
26 import org.apache.juddi.datatype.RegistryObject;
27 import org.apache.juddi.datatype.assertion.PublisherAssertion;
28 import org.apache.juddi.datatype.business.BusinessEntity;
29 import org.apache.juddi.datatype.publisher.Publisher;
30 import org.apache.juddi.datatype.request.AddPublisherAssertions;
31 import org.apache.juddi.datatype.request.AuthInfo;
32 import org.apache.juddi.datatype.request.DeletePublisherAssertions;
33 import org.apache.juddi.datatype.request.GetAuthToken;
34 import org.apache.juddi.datatype.request.SaveBusiness;
35 import org.apache.juddi.datatype.response.AuthToken;
36 import org.apache.juddi.datatype.response.BusinessDetail;
37 import org.apache.juddi.datatype.response.DispositionReport;
38 import org.apache.juddi.datatype.response.Result;
39 import org.apache.juddi.datatype.tmodel.TModel;
40 import org.apache.juddi.error.RegistryException;
41 import org.apache.juddi.registry.RegistryEngine;
42 import org.apache.juddi.util.Config;
43
44 /**
45  * @author Steve Viens (sviens@apache.org)
46  */

47 public class DeletePublisherAssertionsFunction extends AbstractFunction
48 {
49   // private reference to jUDDI Logger
50
private static Log log = LogFactory.getLog(DeletePublisherAssertionsFunction.class);
51
52   /**
53    *
54    */

55   public DeletePublisherAssertionsFunction(RegistryEngine registry)
56   {
57     super(registry);
58   }
59
60   /**
61    *
62    */

63   public RegistryObject execute(RegistryObject regObject)
64     throws RegistryException
65   {
66     // extract individual parameters
67
DeletePublisherAssertions request = (DeletePublisherAssertions)regObject;
68     String JavaDoc generic = request.getGeneric();
69     AuthInfo authInfo = request.getAuthInfo();
70     Vector JavaDoc assertionVector = request.getPublisherAssertionVector();
71
72     // aquire a jUDDI datastore instance
73
DataStore dataStore = DataStoreFactory.getDataStore();
74
75     try
76     {
77       dataStore.beginTrans();
78
79       // validate authentication parameters
80
Publisher publisher = getPublisher(authInfo,dataStore);
81       String JavaDoc publisherID = publisher.getPublisherID();
82
83       // validate request parameters
84
for (int i=0; i<assertionVector.size(); i++)
85       {
86         // nothing that requires validation has been identified
87
}
88
89       // delete the PublisherAssertions
90
dataStore.deleteAssertions(publisherID,assertionVector);
91       dataStore.commit();
92     }
93     catch(RegistryException regex)
94     {
95       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
96       log.error(regex);
97       throw (RegistryException)regex;
98     }
99     catch(Exception JavaDoc ex)
100     {
101       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
102       log.error(ex);
103       throw new RegistryException(ex);
104     }
105     finally
106     {
107       if (dataStore != null)
108         dataStore.release();
109     }
110
111     // We didn't encounter any problems so let's create an
112
// E_SUCCESS Result, embed it in a DispositionReport
113
// and return it.
114
Result result = new Result(Result.E_SUCCESS);
115     result.setErrCode(Result.lookupErrCode(Result.E_SUCCESS));
116     DispositionReport dispRpt = new DispositionReport();
117     dispRpt.setGeneric(generic);
118     dispRpt.setOperator(Config.getOperator());
119     dispRpt.addResult(result);
120     
121     return dispRpt;
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       // generate an AuthToken
139
GetAuthToken authTokenRequest = new GetAuthToken("sviens","password");
140       GetAuthTokenFunction authTokenService = new GetAuthTokenFunction(reg);
141       AuthToken authToken = (AuthToken)authTokenService.execute(authTokenRequest);
142       String JavaDoc authInfo = authToken.getAuthInfo().getValue();
143
144       // create a couple of BusinessEntities
145
BusinessEntity business1 = new BusinessEntity();
146       business1.addName(new Name("Blockbuster","en"));
147
148       BusinessEntity business2 = new BusinessEntity();
149       business2.addName(new Name("Moonlighting","en"));
150
151       Vector JavaDoc businessVector = new Vector JavaDoc(2);
152       businessVector.addElement(business1);
153       businessVector.addElement(business2);
154
155       // create a SaveBusiness request & invoke the server
156
SaveBusiness sbReq = new SaveBusiness();
157       sbReq.setAuthInfo(new AuthInfo(authInfo));
158       sbReq.setBusinessEntityVector(businessVector);
159       BusinessDetail detail = (BusinessDetail)(new SaveBusinessFunction(reg).execute(sbReq));
160       Vector JavaDoc detailVector = detail.getBusinessEntityVector();
161       BusinessEntity b1 = (BusinessEntity)detailVector.elementAt(0);
162       BusinessEntity b2 = (BusinessEntity)detailVector.elementAt(1);
163
164       // create a new PublisherAssertion
165
String JavaDoc fromKey = b1.getBusinessKey();
166       String JavaDoc toKey = b2.getBusinessKey();
167       KeyedReference keyedReference = new KeyedReference ("Partner Company","peer-peer");
168       keyedReference.setTModelKey(TModel.RELATIONSHIPS_TMODEL_KEY);
169       PublisherAssertion assertion = new PublisherAssertion(fromKey,toKey,keyedReference);
170
171       // create a PublisherAssertion Vector
172
Vector JavaDoc assertionVector = new Vector JavaDoc();
173       assertionVector.addElement(assertion);
174
175       // create an AddPublisherAssertions request & invoke the server
176
AddPublisherAssertions apaReq = new AddPublisherAssertions();
177       apaReq.setAuthInfo(new AuthInfo(authInfo));
178       apaReq.setPublisherAssertionVector(assertionVector);
179       DispositionReport dspRpt1 = (DispositionReport)(new AddPublisherAssertionsFunction(reg).execute(apaReq));
180       System.out.println("errno: "+dspRpt1.toString());
181       DispositionReport dspRpt2 = (DispositionReport)(new AddPublisherAssertionsFunction(reg).execute(apaReq));
182       System.out.println("errno: "+dspRpt2.toString());
183
184       // create an DeletePublisherAssertions request & invoke the server
185
DeletePublisherAssertions dpaReq = new DeletePublisherAssertions();
186       dpaReq.setAuthInfo(new AuthInfo(authInfo));
187       dpaReq.setPublisherAssertionVector(assertionVector);
188       DispositionReport response = (DispositionReport)(new DeletePublisherAssertionsFunction(reg).execute(dpaReq));
189       System.out.println("errno: "+response.toString());
190     }
191     catch (Exception JavaDoc ex)
192     {
193       // write execption to the console
194
ex.printStackTrace();
195     }
196     finally
197     {
198       // destroy the registry
199
reg.dispose();
200     }
201   }
202
203 }
Popular Tags