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.DeleteTModel; 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 DeleteTModelFunction extends AbstractFunction 40 { 41 private static Log log = LogFactory.getLog(DeleteTModelFunction.class); 43 44 47 public DeleteTModelFunction(RegistryEngine registry) 48 { 49 super(registry); 50 } 51 52 55 public RegistryObject execute(RegistryObject regObject) 56 throws RegistryException 57 { 58 DeleteTModel request = (DeleteTModel)regObject; 60 String generic = request.getGeneric(); 61 AuthInfo authInfo = request.getAuthInfo(); 62 Vector tModelKeyVector = request.getTModelKeyVector(); 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<tModelKeyVector.size(); i++) 77 { 78 String tModelKey = (String )tModelKeyVector.elementAt(i); 80 81 if ((tModelKey == null) || (tModelKey.length() == 0) || 84 (!dataStore.isValidTModelKey(tModelKey))) 85 throw new InvalidKeyPassedException("delete_tModel: "+ 86 "tModelKey="+tModelKey); 87 88 if (!dataStore.isTModelPublisher(tModelKey,publisherID)) 91 throw new UserMismatchException("delete_tModel: "+ 92 "userID="+publisherID+", "+ 93 "tModelKey="+tModelKey); 94 95 dataStore.markTModelAsDeleted(tModelKey); 97 } 98 99 for (int i=0; i<tModelKeyVector.size(); i++) 101 { 102 String tModelKey = (String )tModelKeyVector.elementAt(i); 103 dataStore.deleteTModel(tModelKey); 104 105 log.info("Publisher '"+publisherID+"' deleted TModel with key: "+tModelKey); 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 DeleteTModel request = new DeleteTModel(); 169 170 DispositionReport response = (DispositionReport)(new DeleteTModelFunction(reg).execute(request)); 172 System.out.println("errno: "+response.toString()); 173 } 174 catch (Exception ex) 175 { 176 ex.printStackTrace(); 178 } 179 finally 180 { 181 reg.dispose(); 183 } 184 } 185 } | Popular Tags |