Object factory = factories.get(factoryInterface);
if (factory == null) {
// Dynamically load a factory class declared under META-INF/services
try {
ServiceDeclaration factoryDeclaration =
registry.getServiceDiscovery().getServiceDeclaration(factoryInterface);
if (factoryDeclaration != null) {
try {
// Constructor taking the extension point registry
factory = newInstance(registry, factoryDeclaration);
} catch (NoSuchMethodException e) {
factory = newInstance(factoryDeclaration.loadClass(), FactoryExtensionPoint.class, this);
}
// Cache the loaded factory
factories.put(factoryInterface, factory);