use of org.apache.tapestry5.ioc.internal.ConfigurationType in project tapestry-5 by apache.
the class AbstractServiceCreator method createInjectionResources.
/**
* Returns a map (based on injectionResources) that includes (possibly) an additional mapping containing the
* collected configuration data. This involves scanning the parameters and generic types.
*/
protected final InjectionResources createInjectionResources() {
InjectionResources core = new MapInjectionResources(injectionResources);
InjectionResources configurations = new InjectionResources() {
private boolean seenOne;
@Override
public <T> T findResource(Class<T> resourceType, Type genericType) {
ConfigurationType thisType = PARAMETER_TYPE_TO_CONFIGURATION_TYPE.get(resourceType);
if (thisType == null)
return null;
if (seenOne)
throw new RuntimeException(IOCMessages.tooManyConfigurationParameters(creatorDescription));
seenOne = true;
switch(thisType) {
case UNORDERED:
return resourceType.cast(getUnorderedConfiguration(genericType));
case ORDERED:
return resourceType.cast(getOrderedConfiguration(genericType));
case MAPPED:
return resourceType.cast(getMappedConfiguration(genericType));
}
return null;
}
};
return new DelegatingInjectionResources(core, configurations);
}
use of org.apache.tapestry5.ioc.internal.ConfigurationType in project tapestry-5 by apache.
the class DefaultModuleDefImpl method addContributionDef.
private void addContributionDef(Method method) {
Contribute annotation = method.getAnnotation(Contribute.class);
Class serviceInterface = annotation == null ? null : annotation.value();
String serviceId = annotation != null ? null : stripMethodPrefix(method, CONTRIBUTE_METHOD_NAME_PREFIX);
Class returnType = method.getReturnType();
if (!returnType.equals(void.class))
logger.warn(IOCMessages.contributionWrongReturnType(method));
ConfigurationType type = null;
for (Class parameterType : method.getParameterTypes()) {
ConfigurationType thisParameter = PARAMETER_TYPE_TO_CONFIGURATION_TYPE.get(parameterType);
if (thisParameter != null) {
if (type != null)
throw new RuntimeException(IOCMessages.tooManyContributionParameters(method));
type = thisParameter;
}
}
if (type == null)
throw new RuntimeException(IOCMessages.noContributionParameter(method));
Set<Class> markers = extractMarkers(method, Contribute.class, Optional.class);
boolean optional = method.getAnnotation(Optional.class) != null;
ContributionDef3 def = new ContributionDefImpl(serviceId, method, optional, proxyFactory, serviceInterface, markers);
contributionDefs.add(def);
}
Aggregations