URI tmpURI;
try {
tmpURI = new URI(domainModel.getDomainURI());
domainModel.setDomainURL(tmpURI.toURL().toExternalForm());
} catch(Exception ex) {
throw new ActivationException("domain uri " +
domainModel.getDomainURI() +
" must be a valid url");
}
// create a runtime for the domain management services to run on
domainManagementRuntime = new ReallySmallRuntime(domainClassLoader);
domainManagementRuntime.start();
// Configure the default server port and path
int port = URI.create(domainModel.getDomainURI()).getPort();
String path = URI.create(domainModel.getDomainURI()).getPath();
if (port != -1) {
ServletHostExtensionPoint servletHosts = domainManagementRuntime.getExtensionPointRegistry().getExtensionPoint(ServletHostExtensionPoint.class);
for (ServletHost servletHost: servletHosts.getServletHosts()) {
servletHost.setDefaultPort(port);
if (path != null && path.length() > 0 && !path.equals("/")) {
servletHost.setContextPath(path);
}
}
}
// Create an in-memory domain level management composite
AssemblyFactory assemblyFactory = domainManagementRuntime.getAssemblyFactory();
domainManagementComposite = assemblyFactory.createComposite();
domainManagementComposite.setName(new QName(Constants.SCA10_NS, "domainManagement"));
domainManagementComposite.setURI(domainModel.getDomainURI() + "/management");
// Create an in-memory domain level composite
domainComposite = assemblyFactory.createComposite();
domainComposite.setName(new QName(Constants.SCA10_NS, "domain"));
domainComposite.setURI(domainModel.getDomainURI() + "/domain");
domainModel.setDomainLeveComposite(domainComposite);
// Set up the domain so that local callable references can find
// service out there in the domain
SCADummyNodeImpl node = new SCADummyNodeImpl(this);
ModelFactoryExtensionPoint factories = domainManagementRuntime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
nodeFactory = new NodeFactoryImpl(node);
factories.addFactory(nodeFactory);
// Find the composite that will configure the domain
String domainCompositeName = "domain.composite";
URL contributionURL = SCAContributionUtil.findContributionFromResource(domainClassLoader, domainCompositeName);
if ( contributionURL != null ){
logger.log(Level.INFO, "Domain management configured from " + contributionURL);
// add node composite to the management domain
domainManagementContributionService = domainManagementRuntime.getContributionService();
Contribution contribution = null;
contribution = domainManagementContributionService.contribute(domainModel.getDomainURI(),
contributionURL,
false);
//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
domainManagementRuntime.updateSCADefinitions(domainManagementContributionService.getContributionSCADefinitions());
//get the domain builder
domainBuilder = domainManagementRuntime.getDomainBuilder();
Composite composite = null;
for (DeployedArtifact artifact: contribution.getArtifacts()) {
if (domainCompositeName.equals(artifact.getURI())) {
composite = (Composite)artifact.getModel();
}
}
if (composite != null) {
domainManagementComposite.getIncludes().add(composite);
domainManagementRuntime.buildComposite(composite);
domainManagementRuntime.getCompositeActivator().activate(composite);
domainManagementRuntime.getCompositeActivator().start(composite);
// get the management components out of the domain so that they
// can be configured/used.
domainManagerInitService = getService(SCADomainManagerInitService.class,
"SCADomainManagerComponent/SCADomainManagerInitService",
domainManagementRuntime,
domainManagementComposite);
domainManagerInitService.setDomain(this);
domainManagerInitService.setDomainSPI((SCADomainSPI)this);
domainManagerInitService.setDomainEventService((SCADomainEventService)this);
} else {
throw new ActivationException("Domain management contribution " +
contributionURL +
" found but could not be loaded");
}
} else {
throw new ActivationException("Domain management contribution " +
domainCompositeName +
" not found on the classpath");
}