private ConfiguredNodeImplementation findNodeConfiguration(final String compositeURI, ClassLoader classLoader)
throws Exception {
NodeImplementationFactory nodeImplementationFactory =
modelFactories.getFactory(NodeImplementationFactory.class);
ConfiguredNodeImplementation config = nodeImplementationFactory.createConfiguredNodeImplementation();
if (classLoader == null) {
classLoader = Thread.currentThread().getContextClassLoader();
}
String contributionArtifactPath = compositeURI;
URL contributionArtifactURL = null;
if (compositeURI != null) {
contributionArtifactURL = getResource(classLoader, compositeURI);
if (contributionArtifactURL == null) {
throw new IllegalArgumentException("Composite not found: " + contributionArtifactPath);
}
composite = createComposite(contributionArtifactURL.toString());
config.setComposite(composite);
} else {
// Here the SCADomain was started without any reference to a composite file
// We are going to look for an sca-contribution.xml or sca-contribution-generated.xml
// Look for META-INF/sca-contribution.xml
contributionArtifactPath = Contribution.SCA_CONTRIBUTION_META;
contributionArtifactURL = getResource(classLoader, contributionArtifactPath);
// Look for META-INF/sca-contribution-generated.xml
if (contributionArtifactURL == null) {
contributionArtifactPath = Contribution.SCA_CONTRIBUTION_GENERATED_META;
contributionArtifactURL = getResource(classLoader, contributionArtifactPath);
}
// Look for META-INF/sca-deployables directory
if (contributionArtifactURL == null) {
contributionArtifactPath = Contribution.SCA_CONTRIBUTION_DEPLOYABLES;
contributionArtifactURL = getResource(classLoader, contributionArtifactPath);
} else {
StAXArtifactProcessor<ContributionMetadata> processor =
artifactProcessors.getProcessor(ContributionMetadata.class);
XMLStreamReader reader = inputFactory.createXMLStreamReader(contributionArtifactURL.openStream());
metadata = processor.read(reader);
reader.close();
if (metadata.getDeployables().isEmpty()) {
throw new IllegalArgumentException(
"No deployable composite is declared in " + contributionArtifactPath);
}
}
}
if (contributionArtifactURL == null) {
throw new IllegalArgumentException(
"Can't determine contribution deployables. Either specify a composite file, or use an sca-contribution.xml file to specify the deployables.");
}
Contribution c = getContribution(contributionArtifactURL, contributionArtifactPath);
config.getContributions().add(c);
return config;
}