Search in sources :

Example 1 with ResourceInjectionTarget

use of org.jboss.as.ee.component.ResourceInjectionTarget in project wildfly by wildfly.

the class AbstractDeploymentDescriptorBindingsProcessor method processInjectionTargets.

/**
     * Processes the injection targets of a resource binding
     *
     *
     * @param injectionSource           The injection source for the injection target
     * @param classLoader               The module class loader
     * @param deploymentReflectionIndex The deployment reflection index
     * @param entry                     The resource with injection targets
     * @param classType                 The expected type of the injection point, may be null if this is to be inferred from the injection target
     * @return The actual class type of the injection point
     * @throws DeploymentUnitProcessingException
     *          If the injection points could not be resolved
     */
protected Class<?> processInjectionTargets(final ResourceInjectionTarget resourceInjectionTarget, InjectionSource injectionSource, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionMetaData entry, Class<?> classType) throws DeploymentUnitProcessingException {
    if (entry.getInjectionTargets() != null) {
        for (ResourceInjectionTargetMetaData injectionTarget : entry.getInjectionTargets()) {
            final String injectionTargetClassName = injectionTarget.getInjectionTargetClass();
            final String injectionTargetName = injectionTarget.getInjectionTargetName();
            final AccessibleObject fieldOrMethod = getInjectionTarget(injectionTargetClassName, injectionTargetName, classLoader, deploymentReflectionIndex);
            final Class<?> injectionTargetType = fieldOrMethod instanceof Field ? ((Field) fieldOrMethod).getType() : ((Method) fieldOrMethod).getParameterTypes()[0];
            final String memberName = fieldOrMethod instanceof Field ? ((Field) fieldOrMethod).getName() : ((Method) fieldOrMethod).getName();
            if (classType != null) {
                if (!injectionTargetType.isAssignableFrom(classType)) {
                    boolean ok = false;
                    if (classType.isPrimitive()) {
                        if (BOXED_TYPES.get(classType).equals(injectionTargetType)) {
                            ok = true;
                        }
                    } else if (injectionTargetType.isPrimitive()) {
                        if (BOXED_TYPES.get(injectionTargetType).equals(classType)) {
                            ok = true;
                        }
                    }
                    if (!ok) {
                        throw EeLogger.ROOT_LOGGER.invalidInjectionTarget(injectionTarget.getInjectionTargetName(), injectionTarget.getInjectionTargetClass(), classType);
                    }
                    classType = injectionTargetType;
                }
            } else {
                classType = injectionTargetType;
            }
            final InjectionTarget injectionTargetDescription = fieldOrMethod instanceof Field ? new FieldInjectionTarget(injectionTargetClassName, memberName, classType.getName()) : new MethodInjectionTarget(injectionTargetClassName, memberName, classType.getName());
            final ResourceInjectionConfiguration injectionConfiguration = new ResourceInjectionConfiguration(injectionTargetDescription, injectionSource);
            resourceInjectionTarget.addResourceInjection(injectionConfiguration);
        }
    }
    return classType;
}
Also used : MethodInjectionTarget(org.jboss.as.ee.component.MethodInjectionTarget) Field(java.lang.reflect.Field) ResourceInjectionTargetMetaData(org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData) FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget) AccessibleObject(java.lang.reflect.AccessibleObject) MethodInjectionTarget(org.jboss.as.ee.component.MethodInjectionTarget) InjectionTarget(org.jboss.as.ee.component.InjectionTarget) ResourceInjectionTarget(org.jboss.as.ee.component.ResourceInjectionTarget) InjectionUtils.getInjectionTarget(org.jboss.as.ee.utils.InjectionUtils.getInjectionTarget) FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget) Method(java.lang.reflect.Method) ResourceInjectionConfiguration(org.jboss.as.ee.component.ResourceInjectionConfiguration)

Aggregations

AccessibleObject (java.lang.reflect.AccessibleObject)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 FieldInjectionTarget (org.jboss.as.ee.component.FieldInjectionTarget)1 InjectionTarget (org.jboss.as.ee.component.InjectionTarget)1 MethodInjectionTarget (org.jboss.as.ee.component.MethodInjectionTarget)1 ResourceInjectionConfiguration (org.jboss.as.ee.component.ResourceInjectionConfiguration)1 ResourceInjectionTarget (org.jboss.as.ee.component.ResourceInjectionTarget)1 InjectionUtils.getInjectionTarget (org.jboss.as.ee.utils.InjectionUtils.getInjectionTarget)1 ResourceInjectionTargetMetaData (org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData)1