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.publisher.Publisher; 28 import org.apache.juddi.datatype.request.AuthInfo; 29 import org.apache.juddi.datatype.request.SaveTModel; 30 import org.apache.juddi.datatype.response.TModelDetail; 31 import org.apache.juddi.datatype.tmodel.TModel; 32 import org.apache.juddi.error.InvalidKeyPassedException; 33 import org.apache.juddi.error.RegistryException; 34 import org.apache.juddi.error.UnsupportedException; 35 import org.apache.juddi.error.UserMismatchException; 36 import org.apache.juddi.registry.RegistryEngine; 37 import org.apache.juddi.util.Config; 38 import org.apache.juddi.uuidgen.UUIDGen; 39 import org.apache.juddi.uuidgen.UUIDGenFactory; 40 41 44 public class SaveTModelFunction extends AbstractFunction 45 { 46 private static Log log = LogFactory.getLog(SaveTModelFunction.class); 48 49 52 public SaveTModelFunction(RegistryEngine registry) 53 { 54 super(registry); 55 } 56 57 60 public RegistryObject execute(RegistryObject regObject) 61 throws RegistryException 62 { 63 SaveTModel request = (SaveTModel)regObject; 64 String generic = request.getGeneric(); 65 AuthInfo authInfo = request.getAuthInfo(); 66 Vector tModelVector = request.getTModelVector(); 67 Vector uploadRegVector = request.getUploadRegisterVector(); 68 UUIDGen uuidgen = UUIDGenFactory.getUUIDGen(); 69 70 if ((uploadRegVector != null) && (uploadRegVector.size() > 0)) 72 throw new UnsupportedException("Saving TModels via " + 73 "UploadRegistry is not supported."); 74 75 DataStore dataStore = DataStoreFactory.getDataStore(); 77 78 try 79 { 80 dataStore.beginTrans(); 81 82 Publisher publisher = getPublisher(authInfo,dataStore); 84 String publisherID = publisher.getPublisherID(); 85 String authorizedName = publisher.getName(); 86 87 for (int i=0; i<tModelVector.size(); i++) 89 { 90 TModel tModel = (TModel)tModelVector.elementAt(i); 92 String tModelKey = tModel.getTModelKey(); 93 94 if (((tModelKey != null) && (tModelKey.length() > 0)) && (!dataStore.isValidTModelKey(tModelKey))) 96 throw new InvalidKeyPassedException("save_tModel: "+ 97 "tModelKey="+tModelKey); 98 99 if (((tModelKey != null) && (tModelKey.length() > 0)) && !dataStore.isTModelPublisher(tModelKey,publisherID)) 101 throw new UserMismatchException("save_tModel: "+ 102 "userID="+publisherID+", "+ 103 "tModelKey="+tModelKey); 104 105 CategoryBag categoryBag = tModel.getCategoryBag(); 114 if (categoryBag != null) 115 { 116 Vector keyedRefVector = categoryBag.getKeyedReferenceVector(); 117 if (keyedRefVector != null) 118 { 119 int vectorSize = keyedRefVector.size(); 120 if (vectorSize > 0) 121 { 122 for (int j=0; j<vectorSize; j++) 123 { 124 KeyedReference keyedRef = (KeyedReference)keyedRefVector.elementAt(j); 125 String key = keyedRef.getTModelKey(); 126 127 if ((key == null) || (key.trim().length() == 0)) 132 keyedRef.setTModelKey(TModel.GENERAL_KEYWORDS_TMODEL_KEY); 133 } 134 } 135 } 136 } 137 } 138 139 for (int i=0; i<tModelVector.size(); i++) 140 { 141 TModel tModel = (TModel)tModelVector.elementAt(i); 143 String tModelKey = tModel.getTModelKey(); 144 145 if ((tModelKey != null) && (tModelKey.length() > 0)) 149 dataStore.deleteTModel(tModelKey); 150 else 151 tModel.setTModelKey("uuid:"+uuidgen.uuidgen()); 152 153 tModel.setAuthorizedName(authorizedName); 156 tModel.setOperator(Config.getOperator()); 157 dataStore.saveTModel(tModel,publisherID); 158 } 159 160 dataStore.commit(); 161 162 TModelDetail detail = new TModelDetail(); 163 detail.setGeneric(generic); 164 detail.setOperator(Config.getOperator()); 165 detail.setTruncated(false); 166 detail.setTModelVector(tModelVector); 167 return detail; 168 } 169 catch(UnsupportedException suppex) 170 { 171 try { dataStore.rollback(); } catch(Exception e) { } 172 log.info(suppex); 173 throw (RegistryException)suppex; 174 } 175 catch(InvalidKeyPassedException ikpex) 176 { 177 try { dataStore.rollback(); } catch(Exception e) { } 178 log.info(ikpex); 179 throw (RegistryException)ikpex; 180 } 181 catch(UserMismatchException umex) 182 { 183 try { dataStore.rollback(); } catch(Exception e) { } 184 log.info(umex); 185 throw (RegistryException)umex; 186 } 187 catch(RegistryException regex) 188 { 189 try { dataStore.rollback(); } catch(Exception e) { } 190 log.error(regex); 191 throw (RegistryException)regex; 192 } 193 catch(Exception ex) 194 { 195 try { dataStore.rollback(); } catch(Exception e) { } 196 log.error(ex); 197 throw new RegistryException(ex); 198 } 199 finally 200 { 201 if (dataStore != null) 202 dataStore.release(); 203 } 204 } 205 206 207 208 209 210 211 212 public static void main(String [] args) 213 { 214 RegistryEngine reg = new RegistryEngine(); 216 reg.init(); 217 218 try 219 { 220 } 221 catch (Exception ex) 222 { 223 ex.printStackTrace(); 225 } 226 finally 227 { 228 reg.dispose(); 230 } 231 } 232 } 233 234 235 | Popular Tags |