{
if (defaultFactories == null) scanDefaultFactories();
Class<? extends ComponentFactory> cfClass = defaultFactories.get(componentClass);
if (cfClass == null)
{
throw new ConfigurationException("No registered default factory for component " + componentClass + " found!");
}
// a component factory is a component too! See if one has been created and exists in the registry
ComponentFactory cf = getComponent(cfClass);
if (cf == null)
{
// hasn't yet been created. Create and put in registry
cf = instantiateFactory(cfClass);
if (cf == null)
{
throw new ConfigurationException("Unable to locate component factory for component " + componentClass);
}
// we simply register this factory. Registration will take care of constructing any dependencies.
registerComponent(cf, cfClass);
}
// ensure the component factory is in the STARTED state!
Component c = componentLookup.get(cfClass.getName());
if (c.instance != cf)
{
throw new ConfigurationException("Component factory " + cfClass + " incorrectly registered!");
}
return cf;
}