use of org.apache.tapestry5.ioc.ServiceDecorator in project tapestry-5 by apache.
the class RegistryImpl method findDecoratorsForService.
@Override
public List<ServiceDecorator> findDecoratorsForService(ServiceDef3 serviceDef) {
lock.check();
assert serviceDef != null;
Logger logger = getServiceLogger(serviceDef.getServiceId());
Orderer<ServiceDecorator> orderer = new Orderer<ServiceDecorator>(logger, true);
for (Module module : moduleToServiceDefs.keySet()) {
Set<DecoratorDef> decoratorDefs = module.findMatchingDecoratorDefs(serviceDef);
if (decoratorDefs.isEmpty())
continue;
ServiceResources resources = new ServiceResourcesImpl(this, module, serviceDef, proxyFactory, logger);
for (DecoratorDef decoratorDef : decoratorDefs) {
ServiceDecorator decorator = decoratorDef.createDecorator(module, resources);
try {
orderer.add(decoratorDef.getDecoratorId(), decorator, decoratorDef.getConstraints());
} catch (IllegalArgumentException e) {
throw new RuntimeException(String.format("Service %s has two different decorators methods named decorate%s in different module classes. " + "You can solve this by renaming one of them and annotating it with @Match(\"%2$s\").", serviceDef.getServiceId(), decoratorDef.getDecoratorId()));
}
}
}
return orderer.getOrdered();
}
use of org.apache.tapestry5.ioc.ServiceDecorator in project tapestry-5 by apache.
the class InterceptorStackBuilder method createObject.
@Override
public Object createObject() {
Object current = delegate.createObject();
List<ServiceDecorator> decorators = registry.findDecoratorsForService(serviceDef);
// We get the decorators ordered according to their dependencies. However, we want to
// process from the last interceptor to the first, so we reverse the list.
Collections.reverse(decorators);
for (final ServiceDecorator decorator : decorators) {
final Object delegate = current;
Object interceptor = registry.invoke("Invoking " + decorator, new Invokable<Object>() {
@Override
public Object invoke() {
return decorator.createInterceptor(delegate);
}
});
if (interceptor != null)
current = interceptor;
}
return current;
}
Aggregations