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.DeleteBusiness; 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 DeleteBusinessFunction extends AbstractFunction 40 { 41 private static Log log = LogFactory.getLog(DeleteBusinessFunction.class); 43 44 47 public DeleteBusinessFunction(RegistryEngine registry) 48 { 49 super(registry); 50 } 51 52 55 public RegistryObject execute(RegistryObject regObject) 56 throws RegistryException 57 { 58 DeleteBusiness request = (DeleteBusiness)regObject; 60 String generic = request.getGeneric(); 61 AuthInfo authInfo = request.getAuthInfo(); 62 Vector businessKeyVector = request.getBusinessKeyVector(); 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<businessKeyVector.size(); i++) 77 { 78 String businessKey = (String )businessKeyVector.elementAt(i); 80 81 if ((!dataStore.isValidBusinessKey(businessKey))) 84 throw new InvalidKeyPassedException("delete_business: "+ 85 "businessKey="+businessKey); 86 87 if (!dataStore.isBusinessPublisher(businessKey,publisherID)) 90 throw new UserMismatchException("delete_business: "+ 91 "userID="+publisherID+", "+ 92 "businessKey="+businessKey); 93 } 94 95 for (int i=0; i<businessKeyVector.size(); i++) 97 { 98 String businessKey = (String )businessKeyVector.elementAt(i); 99 dataStore.deleteBusiness(businessKey); 100 101 log.info("Publisher '"+publisherID+"' deleted BusinessEntity with key: "+businessKey); 102 } 103 104 dataStore.commit(); 105 } 106 catch(InvalidKeyPassedException keyex) 107 { 108 try { dataStore.rollback(); } catch(Exception e) { } 109 log.info(keyex.getMessage()); 110 throw (RegistryException)keyex; 111 } 112 catch(UserMismatchException umex) 113 { 114 try { dataStore.rollback(); } catch(Exception e) { } 115 log.info(umex.getMessage()); 116 throw (RegistryException)umex; 117 } 118 catch(RegistryException regex) 119 { 120 try { dataStore.rollback(); } catch(Exception e) { } 121 log.error(regex); 122 throw (RegistryException)regex; 123 } 124 catch(Exception ex) 125 { 126 try { dataStore.rollback(); } catch(Exception e) { } 127 log.error(ex); 128 throw new RegistryException(ex); 129 } 130 finally 131 { 132 if (dataStore != null) 133 dataStore.release(); 134 } 135 136 Result result = new Result(Result.E_SUCCESS); 140 result.setErrCode(Result.lookupErrCode(Result.E_SUCCESS)); 141 DispositionReport dispRpt = new DispositionReport(); 142 dispRpt.setGeneric(generic); 143 dispRpt.setOperator(Config.getOperator()); 144 dispRpt.addResult(result); 145 146 return dispRpt; 147 } 148 149 150 151 152 153 154 155 public static void main(String [] args) 156 { 157 RegistryEngine reg = new RegistryEngine(); 159 reg.init(); 160 161 try 162 { 163 DeleteBusiness request = new DeleteBusiness(); 165 166 DispositionReport response = (DispositionReport)reg.execute(request); 168 System.out.println("errno: "+response.toString()); 169 } 170 catch (Exception ex) 171 { 172 ex.printStackTrace(); 174 } 175 finally 176 { 177 reg.dispose(); 179 } 180 } 181 } | Popular Tags |