"DomainCreation");
glassFishProperties.setProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY,
domDir.getAbsolutePath());
glassFishProperties.setProperty("-domain", domainConfig.getDomainName());
GlassFish glassfish = runtime.newGlassFish(glassFishProperties);
glassfish.start();
// Will always need DAS's name & config. No harm using the name 'server'
// to fetch <server-config>
com.sun.enterprise.config.serverbeans.Server serverConfig =
glassfish.getService(com.sun.enterprise.config.serverbeans.Server.class,
"server");
Config config = glassfish.getService(
Config.class, serverConfig.getConfigRef());
// Create a context object for this domain creation to enable the new
// modules to make decisions
DomainContext ctx = new DomainContext();
ctx.setDomainType("dev"); //TODO : Whenever clustering/HA is supported
// this setting needs to be fixed. Domain type can be dev/ha/cluster and
// this type needs to be extracted possibly using an api from installer
// bnevins 12/20/12 -- I'm not touching this ancient getLogger call.
// because it looks risky.
ctx.setLogger(LogDomains.getLogger(
DomainInitializer.class, LogDomains.SERVER_LOGGER));
// now for every such Inhabitant, fetch the actual initial config and
// insert it into the module that initial config was targeted for.
ServiceLocator habitat = glassfish.getService(ServiceLocator.class);
Collection<DomainInitializer> inits =
habitat.getAllServices(DomainInitializer.class);
if (inits.isEmpty()) {
logger.info(strings.get("NoCustomization"));
}
for (DomainInitializer inhabitant : habitat.<DomainInitializer>getAllServices(
DomainInitializer.class)) {
logger.info(strings.get("InvokeInitializer",
inhabitant.getClass()));
Container newContainerConfig = inhabitant.getInitialConfig(ctx);
try {
ConfigSupport.apply((new ConfigCode() {
@Override
@SuppressWarnings("unchecked")
public Object run(ConfigBeanProxy... objects) throws PropertyVetoException, TransactionFailure {
((Config) objects[0]).getContainers().add((Container) objects[1]);
return Boolean.TRUE;
}
}), new ConfigBeanProxy[]{config, newContainerConfig});
}
catch (TransactionFailure e) {
logger.severe(strings.get("InitializerTransactionFailure",
inhabitant.getClass()));
}
}
glassfish.dispose();
}