@Override
public BasicSubsystem run() {
// Initialization of a null coordination must be privileged and,
// therefore, occur in the run() method rather than in the constructor.
Coordination coordination = this.coordination;
if (coordination == null)
coordination = Utils.createCoordination(parent);
BasicSubsystem result = null;
try {
TargetRegion region = new TargetRegion(parent);
SubsystemResource ssr = createSubsystemResource(location, content, parent);
result = Activator.getInstance().getSubsystems().getSubsystemByLocation(location);
if (result != null) {
checkLifecyclePermission(result);
if (!region.contains(result))
throw new SubsystemException("Location already exists but existing subsystem is not part of target region: " + location);
if (!(result.getSymbolicName().equals(ssr.getSubsystemManifest().getSubsystemSymbolicNameHeader().getSymbolicName())
&& result.getVersion().equals(ssr.getSubsystemManifest().getSubsystemVersionHeader().getVersion())
&& result.getType().equals(ssr.getSubsystemManifest().getSubsystemTypeHeader().getType())))
throw new SubsystemException("Location already exists but symbolic name, version, and type are not the same: " + location);
return (BasicSubsystem)ResourceInstaller.newInstance(coordination, result, parent).install();
}
result = (BasicSubsystem)region.find(
ssr.getSubsystemManifest().getSubsystemSymbolicNameHeader().getSymbolicName(),
ssr.getSubsystemManifest().getSubsystemVersionHeader().getVersion());
if (result != null) {
checkLifecyclePermission(result);
if (!result.getType().equals(ssr.getSubsystemManifest().getSubsystemTypeHeader().getType()))
throw new SubsystemException("Subsystem already exists in target region but has a different type: " + location);
return (BasicSubsystem)ResourceInstaller.newInstance(coordination, result, parent).install();
}
result = createSubsystem(ssr);
checkLifecyclePermission(result);
return (BasicSubsystem)ResourceInstaller.newInstance(coordination, result, parent).install();
}
catch (Throwable t) {
coordination.fail(t);
}
finally {
if (!embedded) {
try {
coordination.end();
}
catch (CoordinationException e) {
Throwable t = e.getCause();
if (t instanceof SubsystemException)
throw (SubsystemException)t;