KickJava   Java API By Example, From Geeks To Geeks.

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


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 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   // private reference to jUDDI Logger
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 JavaDoc generic = request.getGeneric();
59
60     // aquire a datastore instance
61
DataStore dataStore = DataStoreFactory.getDataStore();
62
63     try
64     {
65       dataStore.beginTrans();
66
67       // TODO (UDDI v3) Implement save_subscription business logic.
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 JavaDoc e) { }
79       log.info(ex);
80       throw (RegistryException)ex;
81     }
82     catch(UnsupportedException ex)
83     {
84       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
85       log.info(ex);
86       throw (RegistryException)ex;
87     }
88     catch(ResultSetTooLargeException ex)
89     {
90       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
91       log.info(ex);
92       throw (RegistryException)ex;
93     }
94     catch(AccountLimitExceededException ex)
95     {
96       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
97       log.info(ex);
98       throw (RegistryException)ex;
99     }
100     catch(UserMismatchException ex)
101     {
102       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
103       log.info(ex);
104       throw (RegistryException)ex;
105     }
106     catch(RequestDeniedException ex)
107     {
108       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
109       log.info(ex);
110       throw (RegistryException)ex;
111     }
112     catch(RegistryException regex)
113     {
114       try { dataStore.rollback(); } catch(Exception JavaDoc e) { }
115       log.error(regex);
116       throw (RegistryException)regex;
117     }
118     catch(Exception JavaDoc ex)
119     {
120       try { dataStore.rollback(); } catch(Exception JavaDoc 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 JavaDoc[] args)
137   {
138     // initialize the registry
139
RegistryEngine reg = new RegistryEngine();
140     reg.init();
141
142     try
143     {
144     }
145     catch (Exception JavaDoc ex)
146     {
147       // write execption to the console
148
ex.printStackTrace();
149     }
150     finally
151     {
152       // destroy the registry
153
reg.dispose();
154     }
155   }
156 }
157
Popular Tags