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.BusinessKey; 25 import org.apache.juddi.datatype.KeyedReference; 26 import org.apache.juddi.datatype.RegistryObject; 27 import org.apache.juddi.datatype.request.FindQualifiers; 28 import org.apache.juddi.datatype.request.FindRelatedBusinesses; 29 import org.apache.juddi.datatype.response.RelatedBusinessInfos; 30 import org.apache.juddi.datatype.response.RelatedBusinessesList; 31 import org.apache.juddi.error.RegistryException; 32 import org.apache.juddi.registry.RegistryEngine; 33 import org.apache.juddi.util.Config; 34 35 38 public class FindRelatedBusinessesFunction extends AbstractFunction 39 { 40 private static Log log = LogFactory.getLog(FindRelatedBusinessesFunction.class); 42 43 46 public FindRelatedBusinessesFunction(RegistryEngine registry) 47 { 48 super(registry); 49 } 50 51 54 public RegistryObject execute(RegistryObject regObject) 55 throws RegistryException 56 { 57 FindRelatedBusinesses request = (FindRelatedBusinesses)regObject; 58 String generic = request.getGeneric(); 59 String businessKey = request.getBusinessKey(); 60 KeyedReference keyedRef = request.getKeyedReference(); 61 FindQualifiers qualifiers = request.getFindQualifiers(); 62 int maxRows = request.getMaxRows(); 63 64 DataStore dataStore = DataStoreFactory.getDataStore(); 66 67 try 68 { 69 dataStore.beginTrans(); 70 71 Vector infoVector = null; 72 boolean truncatedResults = false; 73 74 77 infoVector = dataStore.findRelatedBusinesses(businessKey,keyedRef,qualifiers); 79 if ((infoVector != null) && (infoVector.size() > 0)) 80 { 81 int rowCount = infoVector.size(); 83 if ((maxRows > 0) && (maxRows < rowCount)) 84 { 85 rowCount = maxRows; 86 truncatedResults = true; 87 } 88 } 89 90 RelatedBusinessInfos infos = new RelatedBusinessInfos(); 93 infos.setRelatedBusinessInfoVector(infoVector); 94 95 dataStore.commit(); 96 97 RelatedBusinessesList list = new RelatedBusinessesList(); 100 list.setGeneric(generic); 101 list.setOperator(Config.getOperator()); 102 list.setTruncated(truncatedResults); 103 list.setBusinessKey(new BusinessKey(businessKey)); 104 list.setRelatedBusinessInfos(infos); 105 return list; 106 } 107 catch(RegistryException regex) 108 { 109 try { dataStore.rollback(); } catch(Exception e) { } 110 log.error(regex); 111 throw (RegistryException)regex; 112 } 113 catch(Exception ex) 114 { 115 try { dataStore.rollback(); } catch(Exception e) { } 116 log.error(ex); 117 throw new RegistryException(ex); 118 } 119 finally 120 { 121 if (dataStore != null) 122 dataStore.release(); 123 } 124 } 125 126 127 128 129 130 131 132 public static void main(String [] args) 133 { 134 RegistryEngine reg = new RegistryEngine(); 136 reg.init(); 137 138 try 139 { 140 } 141 catch (Exception ex) 142 { 143 ex.printStackTrace(); 145 } 146 finally 147 { 148 reg.dispose(); 150 } 151 } 152 } | Popular Tags |