}
}
ContextFactory<Context> configuration;
if (model instanceof Module) {
// merge new module definition with the existing one
Module oldModule = module;
Module newModule = (Module) model;
module = newModule;
for (Component component : newModule.getComponents()) {
Implementation componentImplementation = component.getImplementation();
if (componentImplementation == null) {
ConfigurationException e = new MissingImplementationException("Component implementation not set");
e.addContextName(component.getName());
e.addContextName(getName());
throw e;
}
configuration = (ContextFactory<Context>) component.getContextFactory();
if (configuration == null) {
ConfigurationException e = new MissingContextFactoryException("Context factory not set");
e.addContextName(component.getName());
e.addContextName(getName());
throw e;
}
registerConfiguration(configuration);
if (component instanceof ModuleComponent) {
registerAutowire((ModuleComponent) component);
} else {
registerAutowire(component);
}
}
for (EntryPoint ep : newModule.getEntryPoints()) {
configuration = (ContextFactory<Context>) ep.getContextFactory();
if (configuration == null) {
ConfigurationException e = new MissingContextFactoryException("Context factory not set");
e.setIdentifier(ep.getName());
e.addContextName(getName());
throw e;
}
registerConfiguration(configuration);
registerAutowire(ep);
}
for (ExternalService service : newModule.getExternalServices()) {
configuration = (ContextFactory<Context>) service.getContextFactory();
if (configuration == null) {
ConfigurationException e = new MissingContextFactoryException("Context factory not set");
e.setIdentifier(service.getName());
e.addContextName(getName());
throw e;
}
registerConfiguration(configuration);
registerAutowire(service);
}
if (lifecycleState == RUNNING) {
for (Component component : newModule.getComponents()) {
ContextFactory<Context> contextFactory = (ContextFactory<Context>) component.getContextFactory();
wireSource(contextFactory);
buildTarget(contextFactory);
contextFactory.prepare(this);
try {
if (contextFactory.getSourceWireFactories() != null) {
for (SourceWireFactory sourceWireFactory : contextFactory.getSourceWireFactories())
{
sourceWireFactory.initialize();
}
}
if (contextFactory.getTargetWireFactories() != null) {
for (TargetWireFactory targetWireFactory : contextFactory.getTargetWireFactories()
.values()) {
targetWireFactory.initialize();
}
}
} catch (WireFactoryInitException e) {
ProxyConfigurationException ce = new ProxyConfigurationException(e);
ce.addContextName(getName());
throw ce;
}
}
for (EntryPoint ep : newModule.getEntryPoints()) {
ContextFactory<Context> contextFactory = (ContextFactory<Context>) ep.getContextFactory();
wireSource(contextFactory);
buildTarget(contextFactory);
contextFactory.prepare(this);
try {
if (contextFactory.getSourceWireFactories() != null) {
for (SourceWireFactory sourceWireFactory : contextFactory.getSourceWireFactories())
{
sourceWireFactory.initialize();
}
}
if (contextFactory.getTargetWireFactories() != null) {
for (TargetWireFactory targetWireFactory : contextFactory.getTargetWireFactories()
.values()) {
targetWireFactory.initialize();
}
}
} catch (WireFactoryInitException e) {
ProxyConfigurationException ce = new ProxyConfigurationException(e);
ce.addContextName(getName());
throw ce;
}
}
for (ExternalService es : newModule.getExternalServices()) {
ContextFactory<Context> contextFactory = (ContextFactory<Context>) es.getContextFactory();
wireSource(contextFactory);
buildTarget(contextFactory);
contextFactory.prepare(this);
try {