Search in sources :

Example 11 with ServiceDef

use of org.apache.tapestry5.ioc.def.ServiceDef 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)

Example 12 with ServiceDef

use of org.apache.tapestry5.ioc.def.ServiceDef in project tapestry-5 by apache.

the class RegistryImpl method findAdvisorsForService.

@Override
public List<ServiceAdvisor> findAdvisorsForService(ServiceDef3 serviceDef) {
    lock.check();
    assert serviceDef != null;
    Logger logger = getServiceLogger(serviceDef.getServiceId());
    Orderer<ServiceAdvisor> orderer = new Orderer<ServiceAdvisor>(logger, true);
    for (Module module : moduleToServiceDefs.keySet()) {
        Set<AdvisorDef> advisorDefs = module.findMatchingServiceAdvisors(serviceDef);
        if (advisorDefs.isEmpty())
            continue;
        ServiceResources resources = new ServiceResourcesImpl(this, module, serviceDef, proxyFactory, logger);
        for (AdvisorDef advisorDef : advisorDefs) {
            ServiceAdvisor advisor = advisorDef.createAdvisor(module, resources);
            orderer.add(advisorDef.getAdvisorId(), advisor, advisorDef.getConstraints());
        }
    }
    return orderer.getOrdered();
}
Also used : ServiceResources(org.apache.tapestry5.ioc.ServiceResources) Logger(org.slf4j.Logger) TapestryIOCModule(org.apache.tapestry5.ioc.modules.TapestryIOCModule) ServiceAdvisor(org.apache.tapestry5.ioc.ServiceAdvisor) AdvisorDef(org.apache.tapestry5.ioc.AdvisorDef) Orderer(org.apache.tapestry5.ioc.internal.util.Orderer)

Example 13 with ServiceDef

use of org.apache.tapestry5.ioc.def.ServiceDef in project tapestry-5 by apache.

the class RegistryImpl method getOrderedConfiguration.

@Override
@SuppressWarnings("unchecked")
public <T> List<T> getOrderedConfiguration(ServiceDef3 serviceDef, Class<T> objectType) {
    lock.check();
    String serviceId = serviceDef.getServiceId();
    Logger logger = getServiceLogger(serviceId);
    Orderer<T> orderer = new Orderer<T>(logger);
    Map<String, OrderedConfigurationOverride<T>> overrides = CollectionFactory.newCaseInsensitiveMap();
    // TAP5-2129. NOTICE: if someday an ordering between modules is added, this should be reverted
    // or a notice added to the documentation.
    List<Module> modules = new ArrayList<Module>(moduleToServiceDefs.keySet());
    Collections.sort(modules, new ModuleComparator());
    for (Module m : modules) addToOrderedConfiguration(orderer, overrides, objectType, serviceDef, m);
    if (serviceId.equals("MasterObjectProvider")) {
        ObjectProvider contribution = new ObjectProvider() {

            @Override
            public <T> T provide(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator) {
                return findServiceByMarkerAndType(objectType, annotationProvider, null);
            }
        };
        orderer.add("ServiceByMarker", (T) contribution);
    }
    for (OrderedConfigurationOverride<T> override : overrides.values()) override.apply();
    final List<T> result = orderer.getOrdered();
    if (!isServiceConfigurationListenerServiceDef(serviceDef)) {
        serviceConfigurationListener.onOrderedConfiguration(serviceDef, result);
    }
    return result;
}
Also used : NullAnnotationProvider(org.apache.tapestry5.commons.internal.NullAnnotationProvider) Logger(org.slf4j.Logger) MasterObjectProvider(org.apache.tapestry5.ioc.services.MasterObjectProvider) TapestryIOCModule(org.apache.tapestry5.ioc.modules.TapestryIOCModule) Orderer(org.apache.tapestry5.ioc.internal.util.Orderer)

Aggregations

Logger (org.slf4j.Logger)6 ServiceResources (org.apache.tapestry5.ioc.ServiceResources)5 TapestryIOCModule (org.apache.tapestry5.ioc.modules.TapestryIOCModule)5 ServiceDef (org.apache.tapestry5.ioc.def.ServiceDef)3 Orderer (org.apache.tapestry5.ioc.internal.util.Orderer)3 ServiceAdvisor (org.apache.tapestry5.ioc.ServiceAdvisor)2 ServiceDecorator (org.apache.tapestry5.ioc.ServiceDecorator)2 ServletContext (javax.servlet.ServletContext)1 ObjectCreator (org.apache.tapestry5.commons.ObjectCreator)1 NullAnnotationProvider (org.apache.tapestry5.commons.internal.NullAnnotationProvider)1 AdvisorDef (org.apache.tapestry5.ioc.AdvisorDef)1 ServiceBuilderResources (org.apache.tapestry5.ioc.ServiceBuilderResources)1 AspectInterceptorBuilder (org.apache.tapestry5.ioc.services.AspectInterceptorBuilder)1 MasterObjectProvider (org.apache.tapestry5.ioc.services.MasterObjectProvider)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)1 Test (org.testng.annotations.Test)1