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.SaveSubscription;
24 import org.apache.juddi.datatype.response.Subscriptions;
25 import org.apache.juddi.error.AccountLimitExceededException;
26 import org.apache.juddi.error.InvalidKeyPassedException;
27 import org.apache.juddi.error.RegistryException;
28 import org.apache.juddi.error.RequestDeniedException;
29 import org.apache.juddi.error.ResultSetTooLargeException;
30 import org.apache.juddi.error.UnsupportedException;
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 SaveSubscriptionFunction extends AbstractFunction
39 {
40
41 private static Log log = LogFactory.getLog(SaveSubscriptionFunction.class);
42
43 /***
44 *
45 */
46 public SaveSubscriptionFunction(RegistryEngine registry)
47 {
48 super(registry);
49 }
50
51 /***
52 *
53 */
54 public RegistryObject execute(RegistryObject regObject)
55 throws RegistryException
56 {
57 SaveSubscription request = (SaveSubscription)regObject;
58 String generic = request.getGeneric();
59
60
61 DataStore dataStore = DataStoreFactory.getDataStore();
62
63 try
64 {
65 dataStore.beginTrans();
66
67
68
69 dataStore.commit();
70
71 Subscriptions subs = new Subscriptions();
72 subs.setGeneric(generic);
73 subs.setOperator(Config.getOperator());
74 return subs;
75 }
76 catch(InvalidKeyPassedException ex)
77 {
78 try { dataStore.rollback(); } catch(Exception e) { }
79 log.info(ex);
80 throw (RegistryException)ex;
81 }
82 catch(UnsupportedException ex)
83 {
84 try { dataStore.rollback(); } catch(Exception e) { }
85 log.info(ex);
86 throw (RegistryException)ex;
87 }
88 catch(ResultSetTooLargeException ex)
89 {
90 try { dataStore.rollback(); } catch(Exception e) { }
91 log.info(ex);
92 throw (RegistryException)ex;
93 }
94 catch(AccountLimitExceededException ex)
95 {
96 try { dataStore.rollback(); } catch(Exception e) { }
97 log.info(ex);
98 throw (RegistryException)ex;
99 }
100 catch(UserMismatchException ex)
101 {
102 try { dataStore.rollback(); } catch(Exception e) { }
103 log.info(ex);
104 throw (RegistryException)ex;
105 }
106 catch(RequestDeniedException ex)
107 {
108 try { dataStore.rollback(); } catch(Exception e) { }
109 log.info(ex);
110 throw (RegistryException)ex;
111 }
112 catch(RegistryException regex)
113 {
114 try { dataStore.rollback(); } catch(Exception e) { }
115 log.error(regex);
116 throw (RegistryException)regex;
117 }
118 catch(Exception ex)
119 {
120 try { dataStore.rollback(); } catch(Exception e) { }
121 log.error(ex);
122 throw new RegistryException(ex);
123 }
124 finally
125 {
126 if (dataStore != null)
127 dataStore.release();
128 }
129 }
130
131 /****************************************************************************/
132 /****************************** TEST DRIVER *********************************/
133 /****************************************************************************/
134
135
136 public static void main(String[] args)
137 {
138
139 RegistryEngine reg = new RegistryEngine();
140 reg.init();
141
142 try
143 {
144 }
145 catch (Exception ex)
146 {
147
148 ex.printStackTrace();
149 }
150 finally
151 {
152
153 reg.dispose();
154 }
155 }
156 }