Class serviceInterface = _servicePoint.getServiceInterface();
Class declaredInterface = _servicePoint.getDeclaredInterface();
ImplementationDefinition implementationDefinition = _servicePoint.getImplementationDefinition();
ImplementationConstructor constructor = implementationDefinition.getServiceConstructor();
// Get a reference to the module that provided the implementation
String definingModuleId = implementationDefinition.getModuleId();
Module definingModule = getRegistry().getModule(definingModuleId);
ImplementationConstructionContext context = new ImplementationConstructionContextImpl(definingModule,
_servicePoint);
Object result = constructor.constructCoreServiceImplementation(context);
if (result == null)
throw new ApplicationRuntimeException(ServiceModelMessages
.factoryReturnedNull(_servicePoint), constructor.getLocation(), null);
// The factory should provice something that either implements the service interface
// or the declared interface. Again, they are normally the same, but with services
// defined in terms of a class (not an interface), the service interface is
// synthetic, and the declared interface is the actual class.
if (!(serviceInterface.isInstance(result) || declaredInterface.isInstance(result)))
throw new ApplicationRuntimeException(ServiceModelMessages.factoryWrongInterface(
_servicePoint,
result,
serviceInterface), constructor.getLocation(), null);
HiveMind.setLocation(result, constructor.getLocation());
return result;
}