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.DeleteBinding; 28 import org.apache.juddi.datatype.request.GetAuthToken; 29 import org.apache.juddi.datatype.response.AuthToken; 30 import org.apache.juddi.datatype.response.DispositionReport; 31 import org.apache.juddi.datatype.response.Result; 32 import org.apache.juddi.error.InvalidKeyPassedException; 33 import org.apache.juddi.error.RegistryException; 34 import org.apache.juddi.error.UserMismatchException; 35 import org.apache.juddi.registry.RegistryEngine; 36 import org.apache.juddi.util.Config; 37 38 41 public class DeleteBindingFunction extends AbstractFunction 42 { 43 private static Log log = LogFactory.getLog(DeleteBindingFunction.class); 45 46 49 public DeleteBindingFunction(RegistryEngine registry) 50 { 51 super(registry); 52 } 53 54 57 public RegistryObject execute(RegistryObject regObject) 58 throws RegistryException 59 { 60 DeleteBinding request = (DeleteBinding)regObject; 62 String generic = request.getGeneric(); 63 AuthInfo authInfo = request.getAuthInfo(); 64 Vector bindingKeyVector = request.getBindingKeyVector(); 65 66 DataStore dataStore = DataStoreFactory.getDataStore(); 68 69 try 70 { 71 dataStore.beginTrans(); 72 73 Publisher publisher = getPublisher(authInfo,dataStore); 75 String publisherID = publisher.getPublisherID(); 76 77 for (int i=0; i<bindingKeyVector.size(); i++) 79 { 80 String bindingKey = (String )bindingKeyVector.elementAt(i); 82 83 if ((bindingKey == null) || (bindingKey.length() == 0) || 86 (!dataStore.isValidBindingKey(bindingKey))) 87 throw new InvalidKeyPassedException("delete_binding: "+ 88 "bindingKey="+bindingKey); 89 90 if (!dataStore.isBindingPublisher(bindingKey,publisherID)) 94 throw new UserMismatchException("delete_binding: "+ 95 "userID="+publisherID+", "+ 96 "bindingKey="+bindingKey); 97 } 98 99 for (int i=0; i<bindingKeyVector.size(); i++) 101 { 102 String bindingKey = (String )bindingKeyVector.elementAt(i); 103 dataStore.deleteBinding(bindingKey); 104 105 log.info("Publisher '"+publisherID+"' deleted BindingTemplate with key: "+bindingKey); 106 } 107 108 dataStore.commit(); 109 } 110 catch(InvalidKeyPassedException keyex) 111 { 112 try { dataStore.rollback(); } catch(Exception e) { } 113 log.info(keyex.getMessage()); 114 throw (RegistryException)keyex; 115 } 116 catch(UserMismatchException umex) 117 { 118 try { dataStore.rollback(); } catch(Exception e) { } 119 log.info(umex.getMessage()); 120 throw (RegistryException)umex; 121 } 122 catch(RegistryException regex) 123 { 124 try { dataStore.rollback(); } catch(Exception e) { } 125 log.error(regex); 126 throw (RegistryException)regex; 127 } 128 catch(Exception ex) 129 { 130 try { dataStore.rollback(); } catch(Exception e) { } 131 log.error(ex); 132 throw new RegistryException(ex); 133 } 134 finally 135 { 136 if (dataStore != null) 137 dataStore.release(); 138 } 139 140 Result result = new Result(Result.E_SUCCESS); 144 result.setErrCode(Result.lookupErrCode(Result.E_SUCCESS)); 145 DispositionReport dispRpt = new DispositionReport(); 146 dispRpt.setGeneric(generic); 147 dispRpt.setOperator(Config.getOperator()); 148 dispRpt.addResult(result); 149 150 return dispRpt; 151 } 152 153 154 155 156 157 158 159 public static void main(String [] args) 160 { 161 RegistryEngine reg = new RegistryEngine(); 163 reg.init(); 164 165 try 166 { 167 GetAuthToken authTokenRequest = new GetAuthToken("sviens","password"); 169 AuthToken authToken = (AuthToken)reg.execute(authTokenRequest); 170 AuthInfo authInfo = authToken.getAuthInfo(); 171 172 DeleteBinding request = new DeleteBinding(); 174 request.setAuthInfo(authInfo); 175 DispositionReport response = (DispositionReport)reg.execute(request); 176 System.out.println("errno: "+response.toString()); 177 } 178 catch (Exception ex) 179 { 180 ex.printStackTrace(); 182 } 183 finally 184 { 185 reg.dispose(); 187 } 188 } 189 190 } | Popular Tags |