SaveTModel request = (SaveTModel)regObject;
String generic = request.getGeneric();
AuthInfo authInfo = request.getAuthInfo();
Vector tModelVector = request.getTModelVector();
Vector uploadRegVector = request.getUploadRegisterVector();
UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
// UploadRegistry functionality is not currently supported.
if ((uploadRegVector != null) && (uploadRegVector.size() > 0))
throw new UnsupportedException("Saving TModels via " +
"UploadRegistry is not supported.");
// aquire a jUDDI datastore instance
DataStore dataStore = DataStoreFactory.getDataStore();
try
{
dataStore.beginTrans();
// validate authentication parameters
Publisher publisher = getPublisher(authInfo,dataStore);
String publisherID = publisher.getPublisherID();
String authorizedName = publisher.getName();
// validate request parameters
for (int i=0; i<tModelVector.size(); i++)
{
// move the TModel into a form we can work with easily
TModel tModel = (TModel)tModelVector.elementAt(i);
String tModelKey = tModel.getTModelKey();
// If a TModelKey was specified then make sure it's a valid one.
if (((tModelKey != null) && (tModelKey.length() > 0)) && (!dataStore.isValidTModelKey(tModelKey)))
throw new InvalidKeyPassedException("TModelKey: "+tModelKey);
// If a TModelKey was specified then make sure 'publisherID' controls it.
if (((tModelKey != null) && (tModelKey.length() > 0)) && !dataStore.isTModelPublisher(tModelKey,publisherID))
throw new UserMismatchException("TModelKey: "+tModelKey);
}
for (int i=0; i<tModelVector.size(); i++)
{
// move the TModel into a form we can work with easily
TModel tModel = (TModel)tModelVector.elementAt(i);
String tModelKey = tModel.getTModelKey();
// If the new TModel has a TModelKey then it must already exists
// so delete the old one. It a TModelKey isn't specified then
// this is a new TModel so create a new TModelKey for it.
if ((tModelKey != null) && (tModelKey.length() > 0))
dataStore.deleteTModel(tModelKey);
else
tModel.setTModelKey("uuid:"+uuidgen.uuidgen());
// Everything checks out so let's save it. First store
// 'authorizedName' and 'operator' values in each TModel.
tModel.setAuthorizedName(authorizedName);
tModel.setOperator(Config.getOperator());