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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */16 package org.apache.juddi.function;17 18 import java.util.Vector ;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 AbstractFunction39 {40 // private reference to jUDDI Logger41 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 to55 * delete anything.56 * 2. A publisher cannot delete itself.57 */58 public RegistryObject execute(RegistryObject regObject)59 throws RegistryException60 {61 // extract individual parameters62 DeleteSubscription request = (DeleteSubscription)regObject;63 String generic = request.getGeneric();64 AuthInfo authInfo = request.getAuthInfo();65 Vector bindingKeyVector = request.getSubscriptionKeyVector();66 67 // aquire a jUDDI datastore instance68 DataStore dataStore = DataStoreFactory.getDataStore();69 70 try71 {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 e) { }81 log.info(ex);82 throw (RegistryException)ex;83 }84 catch(UserMismatchException ex)85 {86 try { dataStore.rollback(); } catch(Exception e) { }87 log.info(ex);88 throw (RegistryException)ex;89 }90 catch(RegistryException regex)91 {92 try { dataStore.rollback(); } catch(Exception e) { }93 log.error(regex);94 throw (RegistryException)regex;95 }96 catch(Exception ex)97 {98 try { dataStore.rollback(); } catch(Exception e) { }99 log.error(ex);100 throw new RegistryException(ex);101 }102 finally103 {104 if (dataStore != null)105 dataStore.release();106 }107 108 // We didn't encounter any problems so let's create an109 // E_SUCCESS Result, embed it in a DispositionReport110 // 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 [] args)128 {129 // initialize the registry130 RegistryEngine reg = new RegistryEngine();131 reg.init();132 133 try134 {135 }136 catch (Exception ex)137 {138 // write execption to the console139 ex.printStackTrace();140 }141 finally142 {143 // destroy the registry144 reg.dispose();145 }146 }147 }