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);
}
});
}
}
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);
}
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);
}
});
}
}
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();
}
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);
}
Aggregations