* Builds a registry that contains a single service that is intercepted by logging interceptor.
*/
private Registry createRegistryWithInterceptedService(String serviceName, String serviceInterface, String implementationClass,
final List interceptedMethods)
{
ModuleDefinitionImpl module = createModuleDefinition("hivemind.test.services");
ModuleDefinitionHelper helper = new ModuleDefinitionHelper(module);
ServicePointDefinition sp = helper.addServicePoint(serviceName, serviceInterface);
helper.addSimpleServiceImplementation(sp, implementationClass, ServiceModel.SINGLETON);
// Add logging interceptor
InterceptorConstructor constructor = new AbstractServiceInterceptorConstructor(module.getLocation()) {
public void constructServiceInterceptor(InterceptorStack interceptorStack, Module contributingModule)
{
ClassFactory cf = (ClassFactory) contributingModule.getService(ClassFactory.class);
// Create the interceptor with the LoggingInterceptorClassFactory which is quite uncomfortable
// in the moment
LoggingInterceptorClassFactory f = new LoggingInterceptorClassFactory(cf);
Class interceptorClass = f.constructInterceptorClass(interceptorStack, Collections.EMPTY_LIST);
Constructor c = interceptorClass.getConstructors()[0];
Object interceptor;
try
{
interceptor = c.newInstance(new Object[] { interceptorStack.getServiceLog(), interceptorStack.peek() });
}
catch (Exception e) {
throw new ApplicationRuntimeException(e);
}
interceptorStack.push(interceptor);
}};
InterceptorDefinition interceptor = new InterceptorDefinitionImpl(module, "hivemind.LoggingInterceptor", module.getLocation(), constructor);
sp.addInterceptor(interceptor);
return buildFrameworkRegistry(module);
}