} else {
currentNamespace = CommonUtil.getServiceNamespace(serviceElement);
}
ServiceManager serviceManager = new ServiceManager(registry);
Service service = serviceManager.newService(serviceElement);
String lifeCycleName = service.getAttribute("serviceLifecycle_lifecycleName");
String finalPath="";
if ("Edit".equals(operation)) {
// this is an edit operation, retrieve the old namespace and name
String currentPath = "";
if (serviceElement.getChildrenWithLocalName("newServicePath").hasNext()) {
Iterator OmElementIterator = serviceElement.getChildrenWithLocalName("newServicePath");
while (OmElementIterator.hasNext()) {
OMElement next = (OMElement) OmElementIterator.next();
currentPath = next.getText();
break;
}
}else{
currentPath = registry.getRegistryContext().getServicePath() +
CommonUtil.derivePathFragmentFromNamespace(currentNamespace) + currentName;
}
currentPath = RegistryUtils.getRelativePathToOriginal(currentPath,
RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH);
finalPath = new String(currentPath);
String version = service.getAttribute("overview_version");
if (version == null ) {
currentPath = CommonUtil.computeServicePathWithVersion(currentPath, "1.0.0-SNAPSHOT");
}else{
currentPath = CommonUtil.computeServicePathWithVersion(currentPath, version);
}
if (registry.resourceExists(currentPath)) {
GovernanceArtifact oldArtifact =
GovernanceUtils.retrieveGovernanceArtifactByPath(registry, currentPath);
if (!(oldArtifact instanceof Service)) {
String msg = "The updated path is occupied by a non-service. path: " +
currentPath + ".";
log.error(msg);
throw new Exception(msg);
}
// id is used to differentiate the service
String id = oldArtifact.getId();
service.setId(id);
serviceManager.updateService(service);
Resource serviceResource = registry.get(service.getPath());
String oldLifeCycleName = serviceResource.getProperty("registry.LC.name");
if (lifeCycleName == null) {
removeAspect(registry, service.getPath(), oldLifeCycleName);
}
if (lifeCycleName != null) {
if (oldLifeCycleName == null || !oldLifeCycleName.equals(lifeCycleName)) {
// if user select a different lifecycle for the service, first delete
// the previous one and then associate the new one.
removeAspect(registry, service.getPath(), oldLifeCycleName);
registry.associateAspect(service.getPath(), lifeCycleName);
}
}
return true;
}
}
serviceManager.addService(service);
if (lifeCycleName != null) {
registry.associateAspect(service.getPath(), lifeCycleName);
}
/*if (!"".equals(finalPath)) {
if(service.getPath().startsWith(RegistryConstants.PATH_SEPARATOR+ TRUNK)){
Association[] allAssociations = registry.getAllAssociations(finalPath);