Search in sources :

Example 1 with ResourceInjectionTargetMetaData

use of org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData in project wildfly by wildfly.

the class WSRefDDProcessor method processWSFeatures.

private static void processWSFeatures(final DeploymentUnit unit, final Set<ResourceInjectionTargetMetaData> injectionTargets, final UnifiedServiceRefMetaData serviceRefUMDM) throws DeploymentUnitProcessingException {
    if (injectionTargets == null || injectionTargets.size() == 0)
        return;
    if (injectionTargets.size() > 1) {
    // TODO: We should validate all the injection targets whether they're compatible.
    // This means all the injection targets must be assignable or equivalent.
    // If there are @Addressing, @RespectBinding or @MTOM annotations present on injection targets,
    // these annotations must be equivalent for all the injection targets.
    }
    final Module module = unit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final DeploymentReflectionIndex deploymentReflectionIndex = unit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
    final ResourceInjectionTargetMetaData injectionTarget = injectionTargets.iterator().next();
    final String injectionTargetClassName = injectionTarget.getInjectionTargetClass();
    final String injectionTargetName = injectionTarget.getInjectionTargetName();
    final AccessibleObject fieldOrMethod = getInjectionTarget(injectionTargetClassName, injectionTargetName, module.getClassLoader(), deploymentReflectionIndex);
    processAnnotatedElement(fieldOrMethod, serviceRefUMDM);
}
Also used : ResourceInjectionTargetMetaData(org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData) AccessibleObject(java.lang.reflect.AccessibleObject) Module(org.jboss.modules.Module) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)

Example 2 with ResourceInjectionTargetMetaData

use of org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData 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)2 ResourceInjectionTargetMetaData (org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData)2 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 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)1 Module (org.jboss.modules.Module)1