1 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.publisher.Publisher; 26 import org.apache.juddi.datatype.request.AuthInfo; 27 import org.apache.juddi.datatype.request.DeleteService; 28 import org.apache.juddi.datatype.response.DispositionReport; 29 import org.apache.juddi.datatype.response.Result; 30 import org.apache.juddi.error.InvalidKeyPassedException; 31 import org.apache.juddi.error.RegistryException; 32 import org.apache.juddi.error.UserMismatchException; 33 import org.apache.juddi.registry.RegistryEngine; 34 import org.apache.juddi.util.Config; 35 36 39 public class DeleteServiceFunction extends AbstractFunction 40 { 41 private static Log log = LogFactory.getLog(DeleteServiceFunction.class); 43 44 47 public DeleteServiceFunction(RegistryEngine registry) 48 { 49 super(registry); 50 } 51 52 55 public RegistryObject execute(RegistryObject regObject) 56 throws RegistryException 57 { 58 DeleteService request = (DeleteService)regObject; 60 String generic = request.getGeneric(); 61 AuthInfo authInfo = request.getAuthInfo(); 62 Vector serviceKeyVector = request.getServiceKeyVector(); 63 64 DataStore dataStore = DataStoreFactory.getDataStore(); 66 67 try 68 { 69 dataStore.beginTrans(); 70 71 Publisher publisher = getPublisher(authInfo,dataStore); 73 String publisherID = publisher.getPublisherID(); 74 75 for (int i=0; i<serviceKeyVector.size(); i++) 77 { 78 String serviceKey = (String )serviceKeyVector.elementAt(i); 80 81 if ((serviceKey == null) || (serviceKey.length() == 0) || 84 (!dataStore.isValidServiceKey(serviceKey))) 85 throw new InvalidKeyPassedException("delete_service: "+ 86 "serviceKey="+serviceKey); 87 88 if (!dataStore.isServicePublisher(serviceKey,publisherID)) 92 throw new UserMismatchException("delete_service: "+ 93 "userID="+publisherID+", "+ 94 "serviceKey="+serviceKey); 95 } 96 97 for (int i=0; i<serviceKeyVector.size(); i++) 99 { 100 String serviceKey = (String )serviceKeyVector.elementAt(i); 101 dataStore.deleteService(serviceKey); 102 103 log.info("Publisher '"+publisherID+"' deleted BusinessService with key: "+serviceKey); 104 } 105 106 dataStore.commit(); 107 } 108 catch(InvalidKeyPassedException keyex) 109 { 110 try { dataStore.rollback(); } catch(Exception e) { } 111 log.info(keyex.getMessage()); 112 throw (RegistryException)keyex; 113 } 114 catch(UserMismatchException umex) 115 { 116 try { dataStore.rollback(); } catch(Exception e) { } 117 log.info(umex.getMessage()); 118 throw (RegistryException)umex; 119 } 120 catch(RegistryException regex) 121 { 122 try { dataStore.rollback(); } catch(Exception e) { } 123 log.error(regex); 124 throw (RegistryException)regex; 125 } 126 catch(Exception ex) 127 { 128 try { dataStore.rollback(); } catch(Exception e) { } 129 log.error(ex); 130 throw new RegistryException(ex); 131 } 132 finally 133 { 134 if (dataStore != null) 135 dataStore.release(); 136 } 137 138 Result result = new Result(Result.E_SUCCESS); 142 result.setErrCode(Result.lookupErrCode(Result.E_SUCCESS)); 143 DispositionReport dispRpt = new DispositionReport(); 144 dispRpt.setGeneric(generic); 145 dispRpt.setOperator(Config.getOperator()); 146 dispRpt.addResult(result); 147 148 return dispRpt; 149 } 150 151 152 153 154 155 156 157 public static void main(String [] args) 158 { 159 RegistryEngine reg = new RegistryEngine(); 161 reg.init(); 162 163 try 164 { 165 DeleteService request = new DeleteService(); 167 168 DispositionReport response = (DispositionReport)(new DeleteServiceFunction(reg).execute(request)); 170 System.out.println("errno: "+response.toString()); 171 } 172 catch (Exception ex) 173 { 174 ex.printStackTrace(); 176 } 177 finally 178 { 179 reg.dispose(); 181 } 182 } 183 } | Popular Tags |