Search in sources :

Example 1 with ServiceDecorator

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();
}
Also used : ServiceDecorator(org.apache.tapestry5.ioc.ServiceDecorator) ServiceResources(org.apache.tapestry5.ioc.ServiceResources) Logger(org.slf4j.Logger) TapestryIOCModule(org.apache.tapestry5.ioc.modules.TapestryIOCModule) Orderer(org.apache.tapestry5.ioc.internal.util.Orderer)

Example 2 with ServiceDecorator

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;
}
Also used : ServiceDecorator(org.apache.tapestry5.ioc.ServiceDecorator)

Aggregations

ServiceDecorator (org.apache.tapestry5.ioc.ServiceDecorator)2 ServiceResources (org.apache.tapestry5.ioc.ServiceResources)1 Orderer (org.apache.tapestry5.ioc.internal.util.Orderer)1 TapestryIOCModule (org.apache.tapestry5.ioc.modules.TapestryIOCModule)1 Logger (org.slf4j.Logger)1