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