View Javadoc

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.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    // private reference to jUDDI Logger
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      // extract individual parameters
59      DeleteSubscription request = (DeleteSubscription)regObject;
60      String generic = request.getGeneric();
61      // AuthInfo authInfo = request.getAuthInfo();
62      // Vector bindingKeyVector = request.getSubscriptionKeyVector();
63  
64      // aquire a jUDDI datastore instance
65      DataStore dataStore = DataStoreFactory.getDataStore();
66  
67      try
68      {
69        dataStore.beginTrans();
70  
71        // TODO (UDDI v3) Implement delete_subscription business logic.
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     // We didn't encounter any problems so let's create an
106     // E_SUCCESS Result, embed it in a DispositionReport
107     // and return it.
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     // initialize the registry
127     RegistryEngine reg = new RegistryEngine();
128     reg.init();
129 
130     try
131     {
132     }
133     catch (Exception ex)
134     {
135       // write execption to the console
136       ex.printStackTrace();
137     }
138     finally
139     {
140       // destroy the registry
141       reg.dispose();
142     }
143   }
144 }