runtime = new ReallySmallRuntime(runtimeClassLoader);
try {
runtime.start();
} catch (ActivationException e) {
throw new ServiceRuntimeException(e);
}
// Contribute the given contribution to an in-memory repository
ContributionService contributionService = runtime.getContributionService();
URL contributionURL;
try {
contributionURL = getContributionLocation(applicationClassLoader, contributionLocation, this.composites);
if (contributionURL != null) {
// Make sure the URL is correctly encoded (for example, escape the space characters)
contributionURL = contributionURL.toURI().toURL();
}
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
try {
String contributionURI = FileHelper.getName(contributionURL.getPath());
if (contributionURI == null || contributionURI.length() == 0) {
contributionURI = contributionURL.toString();
}
contribution = contributionService.contribute(contributionURI, contributionURL, false);
} catch (ContributionException e) {
throw new ServiceRuntimeException(e);
} catch (IOException e) {
throw new ServiceRuntimeException(e);
}
// Create an in-memory domain level composite
AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
domainComposite = assemblyFactory.createComposite();
domainComposite.setName(new QName(Constants.SCA10_NS, "domain"));
domainComposite.setURI(domainURI);
//when the deployable composites were specified when initializing the runtime
if (composites != null && composites.length > 0 && composites[0].length() > 0) {
// Include all specified deployable composites in the SCA domain
Map<String, Composite> compositeArtifacts = new HashMap<String, Composite>();
for (DeployedArtifact artifact : contribution.getArtifacts()) {
if (artifact.getModel() instanceof Composite) {
compositeArtifacts.put(artifact.getURI(), (Composite)artifact.getModel());
}
}
for (String compositePath : composites) {
Composite composite = compositeArtifacts.get(compositePath);
if (composite == null) {
throw new ServiceRuntimeException("Composite not found: " + compositePath);
}
domainComposite.getIncludes().add(composite);
}
} else {
// in this case, a sca-contribution.xml should have been specified
for (Composite composite : contribution.getDeployables()) {
domainComposite.getIncludes().add(composite);
}
}
//update the runtime for all SCA Definitions processed from the contribution..
//so that the policyset determination done during 'build' has the all the defined
//intents and policysets
runtime.updateSCADefinitions(contributionService.getContributionSCADefinitions());
// Build the SCA composites
for (Composite composite : domainComposite.getIncludes()) {
try {
runtime.buildComposite(composite);
} catch (CompositeBuilderException e) {
throw new ServiceRuntimeException(e);
}
}
// Activate and start composites
CompositeActivator compositeActivator = runtime.getCompositeActivator();
compositeActivator.setDomainComposite(domainComposite);
for (Composite composite : domainComposite.getIncludes()) {
try {
compositeActivator.activate(composite);
} catch (ActivationException e) {
throw new ServiceRuntimeException(e);
}
}
for (Composite composite : domainComposite.getIncludes()) {
try {
for (Component component : composite.getComponents()) {
compositeActivator.start(component);
}
} catch (ActivationException e) {
throw new ServiceRuntimeException(e);
}
}
// Index the top level components
for (Composite composite : domainComposite.getIncludes()) {