public void addService(Service service) throws GovernanceException {
// adding the attributes for name, namespace + service
if (service.getQName() == null) {
String msg = "Name is not set. It have to be set as an qname.";
log.error(msg);
throw new GovernanceException(msg);
}
String serviceName = service.getQName().getLocalPart();
service.setAttributes(GovernanceConstants.SERVICE_NAME_ATTRIBUTE,
new String[]{serviceName});
// namespace can be null
String serviceNamespace = service.getQName().getNamespaceURI();
service.setAttributes(GovernanceConstants.SERVICE_NAMESPACE_ATTRIBUTE,
new String[]{serviceNamespace});
service.associateRegistry(registry);
boolean succeeded = false;
try {
registry.beginTransaction();
String serviceId = service.getId();
Resource serviceResource = registry.newResource();
serviceResource.setMediaType(serviceMediaType);
setContent(service, serviceResource);
serviceResource.setProperty(GovernanceConstants.ARTIFACT_ID_PROP_KEY, serviceId);
// the service will not actually stored in the tmp path.
String tmpPath = "/" + serviceName;
registry.put(tmpPath, serviceResource);
// GovernanceUtils.writeOwnerAssociations(registry, service);
// GovernanceUtils.writeConsumerAssociations(registry, service);
succeeded = true;
} catch (RegistryException e) {
String msg = "Failed to add artifact: artifact id: " + service.getId() +
", path: " + service.getPath() + ". " + e.getMessage();
log.error(msg, e);
throw new GovernanceException(msg, e);
} finally {
if (succeeded) {
try {
registry.commitTransaction();
} catch (RegistryException e) {