Search in sources :

Example 1 with ConfigurationType

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);
}
Also used : ConfigurationType(org.apache.tapestry5.ioc.internal.ConfigurationType) ConfigurationType(org.apache.tapestry5.ioc.internal.ConfigurationType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) 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)

Example 2 with ConfigurationType

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);
}
Also used : Optional(org.apache.tapestry5.ioc.annotations.Optional) ContributionDef3(org.apache.tapestry5.ioc.def.ContributionDef3) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Aggregations

ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)1 Optional (org.apache.tapestry5.ioc.annotations.Optional)1 ContributionDef3 (org.apache.tapestry5.ioc.def.ContributionDef3)1 ConfigurationType (org.apache.tapestry5.ioc.internal.ConfigurationType)1 DelegatingInjectionResources (org.apache.tapestry5.ioc.internal.util.DelegatingInjectionResources)1 InjectionResources (org.apache.tapestry5.ioc.internal.util.InjectionResources)1 MapInjectionResources (org.apache.tapestry5.ioc.internal.util.MapInjectionResources)1