Search in sources :

Example 1 with Orderer

use of org.apache.tapestry5.ioc.internal.util.Orderer in project tapestry-5 by apache.

the class RegistryImpl method addToOrderedConfiguration.

private <T> void addToOrderedConfiguration(Orderer<T> orderer, Map<String, OrderedConfigurationOverride<T>> overrides, Class<T> valueType, ServiceDef3 serviceDef, final Module module) {
    String serviceId = serviceDef.getServiceId();
    Set<ContributionDef2> contributions = module.getContributorDefsForService(serviceDef);
    if (contributions.isEmpty())
        return;
    Logger logger = getServiceLogger(serviceId);
    final ServiceResources resources = new ServiceResourcesImpl(this, module, serviceDef, proxyFactory, logger);
    for (final ContributionDef def : contributions) {
        final OrderedConfiguration<T> validating = new ValidatingOrderedConfigurationWrapper<T>(valueType, resources, typeCoercerProxy, orderer, overrides, def);
        String description = "Invoking " + def;
        logger.debug(description);
        operationTracker.run(description, new Runnable() {

            @Override
            public void run() {
                def.contribute(module, resources, validating);
            }
        });
    }
}
Also used : ServiceResources(org.apache.tapestry5.ioc.ServiceResources) Logger(org.slf4j.Logger)

Example 2 with Orderer

use of org.apache.tapestry5.ioc.internal.util.Orderer 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 3 with Orderer

use of org.apache.tapestry5.ioc.internal.util.Orderer 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 4 with Orderer

use of org.apache.tapestry5.ioc.internal.util.Orderer 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)4 ServiceResources (org.apache.tapestry5.ioc.ServiceResources)3 Orderer (org.apache.tapestry5.ioc.internal.util.Orderer)3 TapestryIOCModule (org.apache.tapestry5.ioc.modules.TapestryIOCModule)3 NullAnnotationProvider (org.apache.tapestry5.commons.internal.NullAnnotationProvider)1 AdvisorDef (org.apache.tapestry5.ioc.AdvisorDef)1 ServiceAdvisor (org.apache.tapestry5.ioc.ServiceAdvisor)1 ServiceDecorator (org.apache.tapestry5.ioc.ServiceDecorator)1 MasterObjectProvider (org.apache.tapestry5.ioc.services.MasterObjectProvider)1