protected void registerConfiguration(ContextFactory<Context> factory) throws ConfigurationException {
factory.prepare(this);
if (lifecycleState == RUNNING) {
if (scopeIndex.get(factory.getName()) != null) {
throw new DuplicateNameException(factory.getName());
}
try {
ScopeContext scope = scopeContexts.get(factory.getScope());
if (scope == null) {
ConfigurationException e = new MissingScopeException("Component has an unknown scope");
e.addContextName(factory.getName());
e.addContextName(getName());
throw e;
}
scope.registerFactory(factory);
scopeIndex.put(factory.getName(), scope);
} catch (TuscanyRuntimeException e) {
e.addContextName(getName());
throw e;
}
configurations.put(factory.getName(), factory); // xcv
} else {
if (configurations.get(factory.getName()) != null) {
throw new DuplicateNameException(factory.getName());
}
configurations.put(factory.getName(), factory);
}
}