Search in sources :

Example 1 with ServiceResources

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

the class RegistryImpl method addToMappedConfiguration.

private <K, V> void addToMappedConfiguration(Map<K, V> map, Map<K, MappedConfigurationOverride<K, V>> overrides, Map<K, ContributionDef> keyToContribution, Class<K> keyClass, Class<V> 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 MappedConfiguration<K, V> validating = new ValidatingMappedConfigurationWrapper<K, V>(valueType, resources, typeCoercerProxy, map, overrides, serviceId, def, keyClass, keyToContribution);
        String description = "Invoking " + def;
        logger.debug(description);
        operationTracker.run(description, new Runnable() {

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

Example 2 with ServiceResources

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

the class ContributionDefImpl method invokeMethod.

private <T> void invokeMethod(ModuleBuilderSource source, ServiceResources resources, Class<T> parameterType, T parameterValue) {
    Map<Class, Object> resourceMap = CollectionFactory.newMap();
    resourceMap.put(parameterType, parameterValue);
    resourceMap.put(ObjectLocator.class, resources);
    resourceMap.put(Logger.class, resources.getLogger());
    InjectionResources injectionResources = new MapInjectionResources(resourceMap);
    for (Class t : CONFIGURATION_TYPES) {
        if (parameterType != t) {
            injectionResources = new DelegatingInjectionResources(new WrongConfigurationTypeGuard(resources.getServiceId(), t, parameterType), injectionResources);
        }
    }
    Throwable fail = null;
    Object moduleInstance = InternalUtils.isStatic(contributorMethod) ? null : source.getModuleBuilder();
    try {
        ObjectCreator[] parameters = InternalUtils.calculateParametersForMethod(contributorMethod, resources, injectionResources, resources.getTracker());
        contributorMethod.invoke(moduleInstance, InternalUtils.realizeObjects(parameters));
    } catch (InvocationTargetException ex) {
        fail = ex.getTargetException();
    } catch (Exception ex) {
        fail = ex;
    }
    if (fail != null)
        throw new RuntimeException(IOCMessages.contributionMethodError(contributorMethod, fail), fail);
}
Also used : WrongConfigurationTypeGuard(org.apache.tapestry5.ioc.internal.util.WrongConfigurationTypeGuard) MapInjectionResources(org.apache.tapestry5.ioc.internal.util.MapInjectionResources) InjectionResources(org.apache.tapestry5.ioc.internal.util.InjectionResources) DelegatingInjectionResources(org.apache.tapestry5.ioc.internal.util.DelegatingInjectionResources) DelegatingInjectionResources(org.apache.tapestry5.ioc.internal.util.DelegatingInjectionResources) MapInjectionResources(org.apache.tapestry5.ioc.internal.util.MapInjectionResources) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with ServiceResources

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

use of org.apache.tapestry5.ioc.ServiceResources 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 5 with ServiceResources

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

the class DefaultRequestExceptionHandlerTest method setup_tests.

@BeforeMethod
public void setup_tests() throws Exception {
    mockConfiguration.clear();
    pageCache = mockRequestPageCache();
    renderer = mockPageResponseRenderer();
    logger = mockLogger();
    request = mockRequest();
    response = mockResponse();
    componentClassResolver = mockComponentClassResolver();
    linkSource = mockLinkSource();
    serviceResources = mockServiceResources();
    mockConfiguration.put(AccessControlException.class, MyPage.class);
    mockConfiguration.put(MyContextAwareException.class, new ExceptionHandlerAssistant() {

        public Object handleRequestException(Throwable exception, List<Object> exceptionContext) throws IOException {
            return null;
        }
    });
    ExceptionReporter noopExceptionReporter = new ExceptionReporter() {

        @Override
        public void reportException(Throwable exception) {
        }
    };
    exceptionHandler = new DefaultRequestExceptionHandler(pageCache, renderer, logger, "exceptionpage", request, response, componentClassResolver, linkSource, serviceResources, noopExceptionReporter, false, mockConfiguration);
}
Also used : ExceptionHandlerAssistant(org.apache.tapestry5.ExceptionHandlerAssistant) ExceptionReporter(org.apache.tapestry5.services.ExceptionReporter) IOException(java.io.IOException) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ServiceResources (org.apache.tapestry5.ioc.ServiceResources)7 Logger (org.slf4j.Logger)5 Orderer (org.apache.tapestry5.ioc.internal.util.Orderer)2 TapestryIOCModule (org.apache.tapestry5.ioc.modules.TapestryIOCModule)2 MethodAdvice (org.apache.tapestry5.plastic.MethodAdvice)2 MethodInvocation (org.apache.tapestry5.plastic.MethodInvocation)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Map (java.util.Map)1 ExceptionHandlerAssistant (org.apache.tapestry5.ExceptionHandlerAssistant)1 ObjectCreator (org.apache.tapestry5.commons.ObjectCreator)1 AbstractContributionDef (org.apache.tapestry5.http.internal.AbstractContributionDef)1 AdvisorDef (org.apache.tapestry5.ioc.AdvisorDef)1 ModuleBuilderSource (org.apache.tapestry5.ioc.ModuleBuilderSource)1 OperationTracker (org.apache.tapestry5.ioc.OperationTracker)1 ServiceAdvisor (org.apache.tapestry5.ioc.ServiceAdvisor)1 ServiceDecorator (org.apache.tapestry5.ioc.ServiceDecorator)1 ContributionDef (org.apache.tapestry5.ioc.def.ContributionDef)1 DelegatingInjectionResources (org.apache.tapestry5.ioc.internal.util.DelegatingInjectionResources)1 InjectionResources (org.apache.tapestry5.ioc.internal.util.InjectionResources)1