}
}
private static NodeConfiguration getNodeConfiguration(WebContextConfigurator configurator) throws IOException,
URISyntaxException {
NodeConfiguration configuration = null;
String nodeConfigURI = configurator.getInitParameter(NODE_CONFIGURATION);
ServletContext servletContext = configurator.getServletContext();
if (nodeConfigURI != null) {
URL url = getResource(servletContext, nodeConfigURI);
configuration = factory.loadConfiguration(url.openStream(), url);
} else {
configuration = factory.createNodeConfiguration();
boolean explicitContributions = false;
Enumeration<String> names = configurator.getInitParameterNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
if (name.equals(CONTRIBUTION) || name.startsWith(CONTRIBUTION + ".")) {
explicitContributions = true;
// We need to have a way to select one or more folders within the webapp as the contributions
String listOfValues = configurator.getInitParameter(name);
if (listOfValues != null) {
for (String path : parse(listOfValues)) {
if ("".equals(path)) {
continue;
}
File f = new File(getResource(servletContext, path).toURI());
configuration.addContribution(f.toURI().toURL());
}
}
} else if (name.equals(CONTRIBUTIONS) || name.startsWith(CONTRIBUTIONS + ".")) {
explicitContributions = true;
String listOfValues = (String)configurator.getInitParameter(name);
if (listOfValues != null) {
for (String path : parse(listOfValues)) {
if ("".equals(path)) {
continue;
}
File f = new File(getResource(servletContext, path).toURI());
if (f.isDirectory()) {
for (File n : f.listFiles()) {
configuration.addContribution(n.toURI().toURL());
}
} else {
configuration.addContribution(f.toURI().toURL());
}
}
}
}
}
String compositeURI = configurator.getInitParameter(COMPOSITE_URI);
if (compositeURI == null) {
compositeURI = getDefaultComposite(configurator);
}
URL composite = getResource(servletContext, compositeURI);
if (configuration.getContributions().isEmpty() || (!explicitContributions && composite != null)) {
if ("".equals(configurator.getName())) {
// Add the root of the web application
configuration.addContribution(getResource(servletContext, ROOT));
} else {
// Add a dummy contribution
configuration.addContribution(URI.create("sca:contributions/" + configurator.getName()), null);
}
}
if (composite != null) {
configuration.getContributions().get(0).addDeploymentComposite(composite);
}
if (!explicitContributions) {
URL url = getResource(servletContext, DEFAULT_CONTRIBUTIONS);
if (url != null) {
File f = new File(url.toURI());
if (f.isDirectory()) {
for (File n : f.listFiles()) {
configuration.addContribution(n.toURI().toURL());
}
}
}
}
String nodeURI = configurator.getInitParameter(NODE_URI);
if (nodeURI == null) {
nodeURI = getResource(servletContext, ROOT).getPath() + configurator.getName();
}
configuration.setURI(nodeURI);
String domainURI = configurator.getInitParameter(DOMAIN_URI);
if (domainURI != null) {
configuration.setDomainURI(domainURI);
} else {
domainURI = configurator.getInitParameter("org.apache.tuscany.sca.defaultDomainURI");
if (domainURI == null) {
domainURI = System.getProperty(DOMAIN_URI_PROP);
}
if (domainURI != null) {
configuration.setDomainURI(getDomainName(domainURI));
configuration.setDomainRegistryURI(domainURI);
}
}
String domainRegistryURI = configurator.getInitParameter(DOMAIN_REGISTRY_URI);
if (domainRegistryURI != null) {
configuration.setDomainRegistryURI(domainRegistryURI);
}
}
configuration.setAttribute(ServletContext.class.getName(), servletContext);
if(configurator instanceof ServletConfigurator) {
configuration.setAttribute(Servlet.class.getName(), ((ServletConfigurator) configurator).servlet);
}
return configuration;
}