KickJava   Java API By Example, From Geeks To Geeks.

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


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.AuthInfo;
26 import org.apache.juddi.datatype.request.DeleteSubscription;
27 import org.apache.juddi.datatype.response.DispositionReport;
28 import org.apache.juddi.datatype.response.Result;
29 import org.apache.juddi.error.InvalidKeyPassedException;
30 import org.apache.juddi.error.RegistryException;
31 import org.apache.juddi.error.UserMismatchException;
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 DeleteSubscriptionFunction extends AbstractFunction
39 {
40   // private reference to jUDDI Logger
41
private static Log log = LogFactory.getLog(DeleteSubscriptionFunction.class);
42
43   /**
44    *
45    */

46   public DeleteSubscriptionFunction(RegistryEngine registry)
47   {
48     super(registry);
49   }
50
51   /**
52    * Here are the rules:
53    *
54    * 1. A publisher must have administrative privs to
55    * delete anything.
56    * 2. A publisher cannot delete itself.
57    */

58   public RegistryObject execute(RegistryObject regObject)
59     throws RegistryException
60   {
61     // extract individual parameters
62
DeleteSubscription request = (DeleteSubscription)regObject;
63     String JavaDoc generic = request.getGeneric();
64     AuthInfo authInfo = request.getAuthInfo();
65     Vector JavaDoc bindingKeyVector = request.getSubscriptionKeyVector();
66
67     // aquire a jUDDI datastore instance
68
DataStore dataStore = DataStoreFactory.getDataStore();
69
70     try
71     {
72       dataStore.beginTrans();
73
74       // TODO (UDDI v3) Implement delete_subscription business logic.
75

76       dataStore.commit();
77     }
78     catch(InvalidKeyPassedException ex)
79     {
80       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
81       log.info(ex);
82       throw (RegistryException)ex;
83     }
84     catch(UserMismatchException ex)
85     {
86       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
87       log.info(ex);
88       throw (RegistryException)ex;
89     }
90     catch(RegistryException regex)
91     {
92       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
93       log.error(regex);
94       throw (RegistryException)regex;
95     }
96     catch(Exception JavaDoc ex)
97     {
98       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
99       log.error(ex);
100       throw new RegistryException(ex);
101     }
102     finally
103     {
104       if (dataStore != null)
105         dataStore.release();
106     }
107
108     // We didn't encounter any problems so let's create an
109
// E_SUCCESS Result, embed it in a DispositionReport
110
// and return it.
111
Result result = new Result(Result.E_SUCCESS);
112     result.setErrCode(Result.lookupErrCode(Result.E_SUCCESS));
113     DispositionReport dispRpt = new DispositionReport();
114     dispRpt.setGeneric(generic);
115     dispRpt.setOperator(Config.getOperator());
116     dispRpt.addResult(result);
117     
118     return dispRpt;
119   }
120
121
122   /***************************************************************************/
123   /***************************** TEST DRIVER *********************************/
124   /***************************************************************************/
125
126
127   public static void main(String JavaDoc[] args)
128   {
129     // initialize the registry
130
RegistryEngine reg = new RegistryEngine();
131     reg.init();
132
133     try
134     {
135     }
136     catch (Exception JavaDoc ex)
137     {
138       // write execption to the console
139
ex.printStackTrace();
140     }
141     finally
142     {
143       // destroy the registry
144
reg.dispose();
145     }
146   }
147 }
Popular Tags