use of org.apache.tapestry5.ioc.internal.util.WrongConfigurationTypeGuard 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);
}
Aggregations