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.RegistryObject; 25 import org.apache.juddi.datatype.request.FindPublisher; 26 import org.apache.juddi.datatype.request.FindQualifier; 27 import org.apache.juddi.datatype.request.FindQualifiers; 28 import org.apache.juddi.datatype.response.PublisherInfos; 29 import org.apache.juddi.datatype.response.PublisherList; 30 import org.apache.juddi.error.NameTooLongException; 31 import org.apache.juddi.error.RegistryException; 32 import org.apache.juddi.error.UnsupportedException; 33 import org.apache.juddi.registry.RegistryEngine; 34 import org.apache.juddi.util.Config; 35 36 51 public class FindPublisherFunction extends AbstractFunction 52 { 53 private static Log log = LogFactory.getLog(FindPublisherFunction.class); 55 56 59 public FindPublisherFunction(RegistryEngine registry) 60 { 61 super(registry); 62 } 63 64 67 public RegistryObject execute(RegistryObject regObject) 68 throws RegistryException 69 { 70 FindPublisher request = (FindPublisher)regObject; 71 String generic = request.getGeneric(); 72 String name = request.getNameString(); 73 FindQualifiers qualifiers = request.getFindQualifiers(); 74 int maxRows = request.getMaxRows(); 75 76 if ((name == null) || (name.length() == 0)) 80 { 81 PublisherList list = new PublisherList(); 82 list.setGeneric(generic); 83 list.setPublisherInfos(new PublisherInfos()); 84 list.setOperator(Config.getOperator()); 85 list.setTruncated(false); 86 return list; 87 } 88 89 DataStore dataStore = DataStoreFactory.getDataStore(); 91 92 try 93 { 94 dataStore.beginTrans(); 95 96 if (name != null) 99 { 100 int maxNameLength = Config.getMaxNameLengthAllowed(); 104 if (name.length() > maxNameLength) 105 throw new NameTooLongException("find_publisher: "+ 106 "name="+name+", "+ 107 "length="+name.length()+", "+ 108 "maxNameLength="+maxNameLength); 109 } 110 111 if (qualifiers != null) 114 { 115 Vector qVector = qualifiers.getFindQualifierVector(); 116 if ((qVector!=null) && (qVector.size() > 0)) 117 { 118 for (int i=0; i<qVector.size(); i++) 119 { 120 FindQualifier qualifier = (FindQualifier)qVector.elementAt(i); 121 String qValue = qualifier.getValue(); 122 123 if ((!qValue.equals(FindQualifier.EXACT_NAME_MATCH)) && 124 (!qValue.equals(FindQualifier.CASE_SENSITIVE_MATCH)) && 125 (!qValue.equals(FindQualifier.OR_ALL_KEYS)) && 126 (!qValue.equals(FindQualifier.OR_LIKE_KEYS)) && 127 (!qValue.equals(FindQualifier.AND_ALL_KEYS)) && 128 (!qValue.equals(FindQualifier.SORT_BY_NAME_ASC)) && 129 (!qValue.equals(FindQualifier.SORT_BY_NAME_DESC)) && 130 (!qValue.equals(FindQualifier.SORT_BY_DATE_ASC)) && 131 (!qValue.equals(FindQualifier.SORT_BY_DATE_DESC)) && 132 (!qValue.equals(FindQualifier.SERVICE_SUBSET)) && 133 (!qValue.equals(FindQualifier.COMBINE_CATEGORY_BAGS))) 134 throw new UnsupportedException("find_publisher: "+ 135 "findQualifier="+qValue); 136 } 137 } 138 } 139 140 Vector infoVector = null; 141 boolean truncatedResults = false; 142 143 Vector idVector = dataStore.findPublisher(name,qualifiers); 145 if ((idVector != null) && (idVector.size() > 0)) 146 { 147 int rowCount = idVector.size(); 151 if ((maxRows > 0) && (maxRows < rowCount)) 152 { 153 rowCount = maxRows; 154 truncatedResults = true; 155 } 156 157 infoVector = new Vector (rowCount); 160 for (int i=0; i<rowCount; i++) 161 infoVector.addElement(dataStore.fetchPublisherInfo((String )idVector.elementAt(i))); 162 } 163 164 dataStore.commit(); 165 166 PublisherInfos infos = new PublisherInfos(); 169 infos.setPublisherInfoVector(infoVector); 170 171 PublisherList list = new PublisherList(); 174 list.setGeneric(generic); 175 list.setPublisherInfos(infos); 176 list.setOperator(Config.getOperator()); 177 list.setTruncated(truncatedResults); 178 return list; 179 } 180 catch(NameTooLongException ntlex) 181 { 182 try { dataStore.rollback(); } catch(Exception e) { } 183 log.info(ntlex.getMessage()); 184 throw (RegistryException)ntlex; 185 } 186 catch(UnsupportedException suppex) 187 { 188 try { dataStore.rollback(); } catch(Exception e) { } 189 log.info(suppex.getMessage()); 190 throw (RegistryException)suppex; 191 } 192 catch(RegistryException regex) 193 { 194 try { dataStore.rollback(); } catch(Exception e) { } 195 log.error(regex); 196 throw (RegistryException)regex; 197 } 198 catch(Exception ex) 199 { 200 try { dataStore.rollback(); } catch(Exception e) { } 201 log.error(ex); 202 throw new RegistryException(ex); 203 } 204 finally 205 { 206 if (dataStore != null) 207 dataStore.release(); 208 } 209 } 210 211 212 213 214 215 public static void main(String [] args) 216 { 217 RegistryEngine reg = new RegistryEngine(); 219 reg.init(); 220 221 try 222 { 223 } 224 catch (Exception ex) 225 { 226 ex.printStackTrace(); 228 } 229 finally 230 { 231 reg.dispose(); 233 } 234 } 235 } | Popular Tags |