runtime = new ReallySmallRuntime(runtimeClassLoader);
try {
runtime.start();
} catch (ActivationException e) {
throw new ServiceRuntimeException(e);
}
ExtensionPointRegistry registry = runtime.getExtensionPointRegistry();
UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
monitor = monitorFactory.createMonitor();
// 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 scheme = contributionURL.toURI().getScheme();
if (scheme == null || scheme.equalsIgnoreCase("file")) {
final File contributionFile = new File(contributionURL.toURI());
// Allow privileged access to test file. Requires FilePermission in security policy.
Boolean isDirectory = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
public Boolean run() {
return contributionFile.isDirectory();
}
});
if (isDirectory) {
// Allow privileged access to create file list. Requires FilePermission in
// security policy.
String[] contributions = AccessController.doPrivileged(new PrivilegedAction<String[]>() {
public String[] run() {
return contributionFile.list(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
});
}
});
if (contributions != null && contributions.length > 0
&& contributions.length == contributionFile.list().length) {
for (String contribution : contributions) {
addContribution(contributionService, new File(contributionFile, contribution).toURI()
.toURL());
}
} else {
addContribution(contributionService, contributionURL);
}
} else {
addContribution(contributionService, contributionURL);
}
} else {
addContribution(contributionService, contributionURL);
}
} catch (IOException e) {
throw new ServiceRuntimeException(e);
} catch (URISyntaxException 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 (Contribution contribution : contributions) {
for (Artifact 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 (Contribution contribution : contributions) {
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(null);
// Build the SCA composites
for (Composite composite : domainComposite.getIncludes()) {
try {
runtime.buildComposite(composite);
analyseProblems();
} 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 (Exception e) {
throw new ServiceRuntimeException(e);
}
}
for (Composite composite : domainComposite.getIncludes()) {
try {
for (Component component : composite.getComponents()) {
compositeActivator.start(component);
}
} catch (Exception e) {
throw new ServiceRuntimeException(e);
}
}
// Index the top level components
for (Composite composite : domainComposite.getIncludes()) {