1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.function;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.apache.juddi.datastore.DataStore;
21 import org.apache.juddi.datastore.DataStoreFactory;
22 import org.apache.juddi.datatype.RegistryObject;
23 import org.apache.juddi.datatype.request.DeleteSubscription;
24 import org.apache.juddi.datatype.response.DispositionReport;
25 import org.apache.juddi.datatype.response.Result;
26 import org.apache.juddi.error.InvalidKeyPassedException;
27 import org.apache.juddi.error.RegistryException;
28 import org.apache.juddi.error.UserMismatchException;
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 DeleteSubscriptionFunction extends AbstractFunction
36 {
37
38 private static Log log = LogFactory.getLog(DeleteSubscriptionFunction.class);
39
40 /***
41 *
42 */
43 public DeleteSubscriptionFunction(RegistryEngine registry)
44 {
45 super(registry);
46 }
47
48 /***
49 * Here are the rules:
50 *
51 * 1. A publisher must have administrative privs to
52 * delete anything.
53 * 2. A publisher cannot delete itself.
54 */
55 public RegistryObject execute(RegistryObject regObject)
56 throws RegistryException
57 {
58
59 DeleteSubscription request = (DeleteSubscription)regObject;
60 String generic = request.getGeneric();
61
62
63
64
65 DataStore dataStore = DataStoreFactory.getDataStore();
66
67 try
68 {
69 dataStore.beginTrans();
70
71
72
73 dataStore.commit();
74 }
75 catch(InvalidKeyPassedException ex)
76 {
77 try { dataStore.rollback(); } catch(Exception e) { }
78 log.info(ex);
79 throw (RegistryException)ex;
80 }
81 catch(UserMismatchException ex)
82 {
83 try { dataStore.rollback(); } catch(Exception e) { }
84 log.info(ex);
85 throw (RegistryException)ex;
86 }
87 catch(RegistryException regex)
88 {
89 try { dataStore.rollback(); } catch(Exception e) { }
90 log.error(regex);
91 throw (RegistryException)regex;
92 }
93 catch(Exception ex)
94 {
95 try { dataStore.rollback(); } catch(Exception e) { }
96 log.error(ex);
97 throw new RegistryException(ex);
98 }
99 finally
100 {
101 if (dataStore != null)
102 dataStore.release();
103 }
104
105
106
107
108 Result result = new Result(Result.E_SUCCESS);
109 result.setErrCode(Result.lookupErrCode(Result.E_SUCCESS));
110 DispositionReport dispRpt = new DispositionReport();
111 dispRpt.setGeneric(generic);
112 dispRpt.setOperator(Config.getOperator());
113 dispRpt.addResult(result);
114
115 return dispRpt;
116 }
117
118
119 /****************************************************************************/
120 /****************************** TEST DRIVER *********************************/
121 /****************************************************************************/
122
123
124 public static void main(String[] args)
125 {
126
127 RegistryEngine reg = new RegistryEngine();
128 reg.init();
129
130 try
131 {
132 }
133 catch (Exception ex)
134 {
135
136 ex.printStackTrace();
137 }
138 finally
139 {
140
141 reg.dispose();
142 }
143 }
144 }