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.KeyedReference; 25 import org.apache.juddi.datatype.Name; 26 import org.apache.juddi.datatype.RegistryObject; 27 import org.apache.juddi.datatype.assertion.PublisherAssertion; 28 import org.apache.juddi.datatype.business.BusinessEntity; 29 import org.apache.juddi.datatype.publisher.Publisher; 30 import org.apache.juddi.datatype.request.AddPublisherAssertions; 31 import org.apache.juddi.datatype.request.AuthInfo; 32 import org.apache.juddi.datatype.request.DeletePublisherAssertions; 33 import org.apache.juddi.datatype.request.GetAuthToken; 34 import org.apache.juddi.datatype.request.SaveBusiness; 35 import org.apache.juddi.datatype.response.AuthToken; 36 import org.apache.juddi.datatype.response.BusinessDetail; 37 import org.apache.juddi.datatype.response.DispositionReport; 38 import org.apache.juddi.datatype.response.Result; 39 import org.apache.juddi.datatype.tmodel.TModel; 40 import org.apache.juddi.error.RegistryException; 41 import org.apache.juddi.registry.RegistryEngine; 42 import org.apache.juddi.util.Config; 43 44 47 public class DeletePublisherAssertionsFunction extends AbstractFunction 48 { 49 private static Log log = LogFactory.getLog(DeletePublisherAssertionsFunction.class); 51 52 55 public DeletePublisherAssertionsFunction(RegistryEngine registry) 56 { 57 super(registry); 58 } 59 60 63 public RegistryObject execute(RegistryObject regObject) 64 throws RegistryException 65 { 66 DeletePublisherAssertions request = (DeletePublisherAssertions)regObject; 68 String generic = request.getGeneric(); 69 AuthInfo authInfo = request.getAuthInfo(); 70 Vector assertionVector = request.getPublisherAssertionVector(); 71 72 DataStore dataStore = DataStoreFactory.getDataStore(); 74 75 try 76 { 77 dataStore.beginTrans(); 78 79 Publisher publisher = getPublisher(authInfo,dataStore); 81 String publisherID = publisher.getPublisherID(); 82 83 for (int i=0; i<assertionVector.size(); i++) 85 { 86 } 88 89 dataStore.deleteAssertions(publisherID,assertionVector); 91 dataStore.commit(); 92 } 93 catch(RegistryException regex) 94 { 95 try { dataStore.rollback(); } catch(Exception e) { } 96 log.error(regex); 97 throw (RegistryException)regex; 98 } 99 catch(Exception ex) 100 { 101 try { dataStore.rollback(); } catch(Exception e) { } 102 log.error(ex); 103 throw new RegistryException(ex); 104 } 105 finally 106 { 107 if (dataStore != null) 108 dataStore.release(); 109 } 110 111 Result result = new Result(Result.E_SUCCESS); 115 result.setErrCode(Result.lookupErrCode(Result.E_SUCCESS)); 116 DispositionReport dispRpt = new DispositionReport(); 117 dispRpt.setGeneric(generic); 118 dispRpt.setOperator(Config.getOperator()); 119 dispRpt.addResult(result); 120 121 return dispRpt; 122 } 123 124 125 126 127 128 129 130 public static void main(String [] args) 131 { 132 RegistryEngine reg = new RegistryEngine(); 134 reg.init(); 135 136 try 137 { 138 GetAuthToken authTokenRequest = new GetAuthToken("sviens","password"); 140 GetAuthTokenFunction authTokenService = new GetAuthTokenFunction(reg); 141 AuthToken authToken = (AuthToken)authTokenService.execute(authTokenRequest); 142 String authInfo = authToken.getAuthInfo().getValue(); 143 144 BusinessEntity business1 = new BusinessEntity(); 146 business1.addName(new Name("Blockbuster","en")); 147 148 BusinessEntity business2 = new BusinessEntity(); 149 business2.addName(new Name("Moonlighting","en")); 150 151 Vector businessVector = new Vector (2); 152 businessVector.addElement(business1); 153 businessVector.addElement(business2); 154 155 SaveBusiness sbReq = new SaveBusiness(); 157 sbReq.setAuthInfo(new AuthInfo(authInfo)); 158 sbReq.setBusinessEntityVector(businessVector); 159 BusinessDetail detail = (BusinessDetail)(new SaveBusinessFunction(reg).execute(sbReq)); 160 Vector detailVector = detail.getBusinessEntityVector(); 161 BusinessEntity b1 = (BusinessEntity)detailVector.elementAt(0); 162 BusinessEntity b2 = (BusinessEntity)detailVector.elementAt(1); 163 164 String fromKey = b1.getBusinessKey(); 166 String toKey = b2.getBusinessKey(); 167 KeyedReference keyedReference = new KeyedReference ("Partner Company","peer-peer"); 168 keyedReference.setTModelKey(TModel.RELATIONSHIPS_TMODEL_KEY); 169 PublisherAssertion assertion = new PublisherAssertion(fromKey,toKey,keyedReference); 170 171 Vector assertionVector = new Vector (); 173 assertionVector.addElement(assertion); 174 175 AddPublisherAssertions apaReq = new AddPublisherAssertions(); 177 apaReq.setAuthInfo(new AuthInfo(authInfo)); 178 apaReq.setPublisherAssertionVector(assertionVector); 179 DispositionReport dspRpt1 = (DispositionReport)(new AddPublisherAssertionsFunction(reg).execute(apaReq)); 180 System.out.println("errno: "+dspRpt1.toString()); 181 DispositionReport dspRpt2 = (DispositionReport)(new AddPublisherAssertionsFunction(reg).execute(apaReq)); 182 System.out.println("errno: "+dspRpt2.toString()); 183 184 DeletePublisherAssertions dpaReq = new DeletePublisherAssertions(); 186 dpaReq.setAuthInfo(new AuthInfo(authInfo)); 187 dpaReq.setPublisherAssertionVector(assertionVector); 188 DispositionReport response = (DispositionReport)(new DeletePublisherAssertionsFunction(reg).execute(dpaReq)); 189 System.out.println("errno: "+response.toString()); 190 } 191 catch (Exception ex) 192 { 193 ex.printStackTrace(); 195 } 196 finally 197 { 198 reg.dispose(); 200 } 201 } 202 203 } | Popular Tags |