{
SaveService request = (SaveService)regObject;
String generic = request.getGeneric();
AuthInfo authInfo = request.getAuthInfo();
Vector serviceVector = request.getBusinessServiceVector();
UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
// aquire a jUDDI datastore instance
DataStore dataStore = DataStoreFactory.getDataStore();
try
{
dataStore.beginTrans();
// validate authentication parameters
Publisher publisher = getPublisher(authInfo,dataStore);
String publisherID = publisher.getPublisherID();
// validate request parameters & execute
for (int i=0; i<serviceVector.size(); i++)
{
// move the BusinessService data into a form we can work with easily
BusinessService service = (BusinessService)serviceVector.elementAt(i);
String businessKey = service.getBusinessKey();
String serviceKey = service.getServiceKey();
// If a BusinessKey wasn't included or it is an invalid BusinessKey then
// throw an InvalidKeyPassedException
if ((businessKey == null) || (businessKey.length() == 0) || (!dataStore.isValidBusinessKey(businessKey)))
throw new InvalidKeyPassedException("businessKey="+businessKey);
// Confirm that 'publisherID' controls the BusinessEntity that this
// BusinessService belongs to. If not then throw a UserMismatchException.
if (!dataStore.isBusinessPublisher(businessKey,publisherID))
throw new UserMismatchException("businessKey="+serviceKey);
// If a ServiceKey was specified then make sure it's a valid one.
if (((serviceKey != null) && (serviceKey.length() > 0)) && (!dataStore.isValidServiceKey(serviceKey)))
throw new InvalidKeyPassedException("serviceKey="+serviceKey);
}
for (int i=0; i<serviceVector.size(); i++)
{
// move the BusinessService data into a form we can work with easily
BusinessService service = (BusinessService)serviceVector.elementAt(i);
String serviceKey = service.getServiceKey();
// If the new BusinessService has a ServiceKey then it must already
// exists so delete the old one. It a ServiceKey isn't specified then
// this is a new BusinessService so create a new ServiceKey for it.
if ((serviceKey != null) && (serviceKey.length() > 0))
dataStore.deleteService(serviceKey);
else
service.setServiceKey(uuidgen.uuidgen());
// everything checks out so let's save it.
dataStore.saveService(service);
}