1 /*2 * Copyright 2001-2004 The Apache Software Foundation.3 * 4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */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.business.BusinessEntity;26 import org.apache.juddi.datatype.business.BusinessEntityExt;27 import org.apache.juddi.datatype.request.GetBusinessDetailExt;28 import org.apache.juddi.datatype.response.BusinessDetailExt;29 import org.apache.juddi.error.InvalidKeyPassedException;30 import org.apache.juddi.error.RegistryException;31 import org.apache.juddi.registry.RegistryEngine;32 import org.apache.juddi.util.Config;33 34 /**35 * @author Steve Viens (sviens@apache.org)36 */37 public class GetBusinessDetailExtFunction extends AbstractFunction38 {39 // private reference to jUDDI Logger40 private static Log log = LogFactory.getLog(GetBusinessDetailExtFunction.class);41 42 /**43 *44 */45 public GetBusinessDetailExtFunction(RegistryEngine registry)46 {47 super(registry);48 }49 50 /**51 *52 */53 public RegistryObject execute(RegistryObject regObject)54 throws RegistryException55 {56 GetBusinessDetailExt request = (GetBusinessDetailExt)regObject;57 String generic = request.getGeneric();58 Vector businessKeyVector = request.getBusinessKeyVector();59 60 // aquire a jUDDI datastore instance61 DataStore dataStore = DataStoreFactory.getDataStore();62 63 try64 {65 dataStore.beginTrans();66 67 // verify68 for (int i=0; i<businessKeyVector.size(); i++)69 {70 String businessKey = (String )businessKeyVector.elementAt(i);71 72 // If the a BusinessEntity doesn't exist hrow an InvalidKeyPassedException.73 if ((businessKey == null) || (businessKey.length() == 0) ||74 (!dataStore.isValidBusinessKey(businessKey)))75 throw new InvalidKeyPassedException("get_businessDetailExt: "+76 "businessKey="+businessKey);77 }78 79 Vector businessEntityExtVector = new Vector ();80 81 for (int i=0; i<businessKeyVector.size(); i++)82 {83 String businessKey = (String )businessKeyVector.elementAt(i);84 BusinessEntity business = dataStore.fetchBusiness(businessKey);85 BusinessEntityExt businessExt = new BusinessEntityExt(business);86 businessEntityExtVector.addElement(businessExt);87 }88 89 dataStore.commit();90 91 // create a new BusinessDetailExt and stuff the Vector of92 // new BusinessEntityExt instances into it.93 BusinessDetailExt detailExt = new BusinessDetailExt();94 detailExt.setGeneric(generic);95 detailExt.setOperator(Config.getOperator());96 detailExt.setBusinessEntityExtVector(businessEntityExtVector);97 return detailExt;98 }99 catch(InvalidKeyPassedException keyex)100 {101 try { dataStore.rollback(); } catch(Exception e) { }102 log.info(keyex.getMessage());103 throw (RegistryException)keyex;104 }105 catch(RegistryException regex)106 {107 try { dataStore.rollback(); } catch(Exception e) { }108 log.error(regex);109 throw (RegistryException)regex;110 }111 catch(Exception ex)112 {113 try { dataStore.rollback(); } catch(Exception e) { }114 log.error(ex);115 throw new RegistryException(ex);116 }117 finally118 {119 if (dataStore != null)120 dataStore.release();121 }122 }123 124 125 /***************************************************************************/126 /***************************** TEST DRIVER *********************************/127 /***************************************************************************/128 129 130 public static void main(String [] args)131 {132 // initialize the registry133 RegistryEngine reg = new RegistryEngine();134 reg.init();135 136 try137 {138 }139 catch (Exception ex)140 {141 // write execption to the console142 ex.printStackTrace();143 }144 finally145 {146 // destroy the registry147 reg.dispose();148 }149 }150 }