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.CategoryBag; 25 import org.apache.juddi.datatype.KeyedReference; 26 import org.apache.juddi.datatype.RegistryObject; 27 import org.apache.juddi.datatype.TModelBag; 28 import org.apache.juddi.datatype.request.FindBinding; 29 import org.apache.juddi.datatype.request.FindQualifier; 30 import org.apache.juddi.datatype.request.FindQualifiers; 31 import org.apache.juddi.datatype.response.BindingDetail; 32 import org.apache.juddi.datatype.tmodel.TModel; 33 import org.apache.juddi.error.InvalidKeyPassedException; 34 import org.apache.juddi.error.RegistryException; 35 import org.apache.juddi.error.UnsupportedException; 36 import org.apache.juddi.registry.RegistryEngine; 37 import org.apache.juddi.util.Config; 38 39 43 public class FindBindingFunction extends AbstractFunction 44 { 45 private static Log log = LogFactory.getLog(FindBindingFunction.class); 47 48 51 public FindBindingFunction(RegistryEngine registry) 52 { 53 super(registry); 54 } 55 56 59 public RegistryObject execute(RegistryObject regObject) 60 throws RegistryException 61 { 62 FindBinding request = (FindBinding)regObject; 64 String generic = request.getGeneric(); 65 String serviceKey = request.getServiceKey(); 66 CategoryBag categoryBag = request.getCategoryBag(); 67 TModelBag tModelBag = request.getTModelBag(); 68 FindQualifiers qualifiers = request.getFindQualifiers(); 69 int maxRows = request.getMaxRows(); 70 71 if(((serviceKey == null) || (serviceKey.length() == 0)) && 75 ((categoryBag == null) || (categoryBag.size() == 0)) && 76 ((tModelBag == null) || (tModelBag.size() == 0))) 77 { 78 BindingDetail detail = new BindingDetail(); 79 detail.setGeneric(generic); 80 detail.setBindingTemplateVector(null); 81 detail.setOperator(Config.getOperator()); 82 detail.setTruncated(false); 83 return detail; 84 } 85 86 if (categoryBag != null) 88 { 89 Vector keyedRefVector = categoryBag.getKeyedReferenceVector(); 90 if (keyedRefVector != null) 91 { 92 int vectorSize = keyedRefVector.size(); 93 if (vectorSize > 0) 94 { 95 for (int i=0; i<vectorSize; i++) 96 { 97 KeyedReference keyedRef = (KeyedReference)keyedRefVector.elementAt(i); 98 String key = keyedRef.getTModelKey(); 99 100 if ((key == null) || (key.trim().length() == 0)) 105 keyedRef.setTModelKey(TModel.GENERAL_KEYWORDS_TMODEL_KEY); 106 } 107 } 108 } 109 } 110 111 DataStore dataStore = DataStoreFactory.getDataStore(); 113 114 try 115 { 116 dataStore.beginTrans(); 117 118 if ((serviceKey == null) || (serviceKey.length() == 0)) 120 throw new InvalidKeyPassedException("find_binding: "+ 121 "serviceKey="+serviceKey); 122 123 if (qualifiers != null) 126 { 127 Vector qVector = qualifiers.getFindQualifierVector(); 128 if ((qVector!=null) && (qVector.size() > 0)) 129 { 130 for (int i=0; i<qVector.size(); i++) 131 { 132 FindQualifier qualifier = (FindQualifier)qVector.elementAt(i); 133 String qValue = qualifier.getValue(); 134 135 if ((!qValue.equals(FindQualifier.EXACT_NAME_MATCH)) && 136 (!qValue.equals(FindQualifier.CASE_SENSITIVE_MATCH)) && 137 (!qValue.equals(FindQualifier.OR_ALL_KEYS)) && 138 (!qValue.equals(FindQualifier.OR_LIKE_KEYS)) && 139 (!qValue.equals(FindQualifier.AND_ALL_KEYS)) && 140 (!qValue.equals(FindQualifier.SORT_BY_NAME_ASC)) && 141 (!qValue.equals(FindQualifier.SORT_BY_NAME_DESC)) && 142 (!qValue.equals(FindQualifier.SORT_BY_DATE_ASC)) && 143 (!qValue.equals(FindQualifier.SORT_BY_DATE_DESC)) && 144 (!qValue.equals(FindQualifier.SERVICE_SUBSET)) && 145 (!qValue.equals(FindQualifier.COMBINE_CATEGORY_BAGS))) 146 throw new UnsupportedException("find_binding: "+ 147 "findQualifier="+qValue); 148 } 149 } 150 } 151 152 Vector bindingVector = null; 153 boolean truncatedResults = false; 154 155 Vector keyVector = dataStore.findBinding(serviceKey,categoryBag,tModelBag,qualifiers); 157 if ((keyVector != null) && (keyVector.size() > 0)) 158 { 159 int rowCount = keyVector.size(); 163 if ((maxRows > 0) && (maxRows < rowCount)) 164 { 165 rowCount = maxRows; 166 truncatedResults = true; 167 } 168 169 bindingVector = new Vector (rowCount); 172 for (int i=0; i<rowCount; i++) 173 bindingVector.addElement(dataStore.fetchBinding((String )keyVector.elementAt(i))); 174 } 175 176 dataStore.commit(); 177 178 BindingDetail detail = new BindingDetail(); 181 detail.setBindingTemplateVector(bindingVector); 182 detail.setGeneric(generic); 183 detail.setOperator(Config.getOperator()); 184 detail.setTruncated(truncatedResults); 185 return detail; 186 } 187 catch(InvalidKeyPassedException keyex) 188 { 189 try { dataStore.rollback(); } catch(Exception e) { } 190 log.info(keyex.getMessage()); 191 throw (RegistryException)keyex; 192 } 193 catch(UnsupportedException suppex) 194 { 195 try { dataStore.rollback(); } catch(Exception e) { } 196 log.info(suppex.getMessage()); 197 throw (RegistryException)suppex; 198 } 199 catch(RegistryException regex) 200 { 201 try { dataStore.rollback(); } catch(Exception e) { } 202 log.error(regex); 203 throw (RegistryException)regex; 204 } 205 catch(Exception ex) 206 { 207 try { dataStore.rollback(); } catch(Exception e) { } 208 log.error(ex); 209 throw new RegistryException(ex); 210 } 211 finally 212 { 213 if (dataStore != null) 214 dataStore.release(); 215 } 216 } 217 218 219 220 221 222 223 224 public static void main(String [] args) 225 { 226 RegistryEngine reg = new RegistryEngine(); 228 reg.init(); 229 230 try 231 { 232 } 233 catch (Exception ex) 234 { 235 ex.printStackTrace(); 237 } 238 finally 239 { 240 reg.dispose(); 242 } 243 } 244 } | Popular Tags |