Search in sources :

Example 1 with FieldInjectionTarget

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

the class ResourceInjectionAnnotationParsingProcessor method processFieldResource.

protected void processFieldResource(final DeploymentPhaseContext phaseContext, final FieldInfo fieldInfo, final String name, final String type, final EEModuleClassDescription classDescription, final AnnotationInstance annotation, final EEModuleDescription eeModuleDescription, final Module module, final EEApplicationClasses applicationClasses, final PropertyReplacer replacer) throws DeploymentUnitProcessingException {
    final String fieldName = fieldInfo.name();
    final String injectionType = isEmpty(type) || type.equals(Object.class.getName()) ? fieldInfo.type().name().toString() : type;
    final String localContextName = isEmpty(name) ? fieldInfo.declaringClass().name().toString() + "/" + fieldName : name;
    final InjectionTarget targetDescription = new FieldInjectionTarget(fieldInfo.declaringClass().name().toString(), fieldName, fieldInfo.type().name().toString());
    process(phaseContext, classDescription, annotation, injectionType, localContextName, targetDescription, eeModuleDescription, module, applicationClasses, replacer);
}
Also used : FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget) MethodInjectionTarget(org.jboss.as.ee.component.MethodInjectionTarget) InjectionTarget(org.jboss.as.ee.component.InjectionTarget) FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget)

Example 2 with FieldInjectionTarget

use of org.jboss.as.ee.component.FieldInjectionTarget 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() && 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)

Example 3 with FieldInjectionTarget

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

the class EjbResourceInjectionAnnotationProcessor method processField.

private void processField(final DeploymentUnit deploymentUnit, final EJBResourceWrapper annotation, final FieldInfo fieldInfo, final EEModuleDescription eeModuleDescription) {
    final String fieldName = fieldInfo.name();
    final String fieldType = fieldInfo.type().name().toString();
    final InjectionTarget targetDescription = new FieldInjectionTarget(fieldInfo.declaringClass().name().toString(), fieldName, fieldType);
    final String localContextName = isEmpty(annotation.name()) ? fieldInfo.declaringClass().name().toString() + "/" + fieldInfo.name() : annotation.name();
    final String beanInterfaceType = isEmpty(annotation.beanInterface()) || annotation.beanInterface().equals(Object.class.getName()) ? fieldType : annotation.beanInterface();
    process(deploymentUnit, beanInterfaceType, annotation.beanName(), annotation.lookup(), fieldInfo.declaringClass(), targetDescription, localContextName, eeModuleDescription);
}
Also used : FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget) MethodInjectionTarget(org.jboss.as.ee.component.MethodInjectionTarget) InjectionTarget(org.jboss.as.ee.component.InjectionTarget) FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget)

Example 4 with FieldInjectionTarget

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

the class WSRefAnnotationProcessor method processFieldRef.

private static void processFieldRef(final DeploymentUnit unit, final WSRefAnnotationWrapper annotation, final FieldInfo fieldInfo) throws DeploymentUnitProcessingException {
    final String fieldName = fieldInfo.name();
    final String injectionType = isEmpty(annotation.type()) || annotation.type().equals(Object.class.getName()) ? fieldInfo.type().name().toString() : annotation.type();
    final InjectionTarget injectionTarget = new FieldInjectionTarget(fieldInfo.declaringClass().name().toString(), fieldName, injectionType);
    final String bindingName = isEmpty(annotation.name()) ? fieldInfo.declaringClass().name().toString() + "/" + fieldInfo.name() : annotation.name();
    processRef(unit, injectionType, annotation, fieldInfo.declaringClass(), injectionTarget, bindingName);
}
Also used : 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) InjectionUtils.getInjectionTarget(org.jboss.as.ee.utils.InjectionUtils.getInjectionTarget) FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget)

Example 5 with FieldInjectionTarget

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

the class JPAAnnotationProcessor method processField.

private void processField(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final FieldInfo fieldInfo, final EEModuleClassDescription eeModuleClassDescription) throws DeploymentUnitProcessingException {
    final String fieldName = fieldInfo.name();
    final AnnotationValue declaredNameValue = annotation.value("name");
    final String declaredName = declaredNameValue != null ? declaredNameValue.asString() : null;
    final String localContextName;
    if (declaredName == null || declaredName.isEmpty()) {
        localContextName = fieldInfo.declaringClass().name().toString() + "/" + fieldName;
    } else {
        localContextName = declaredName;
    }
    // final AnnotationValue declaredTypeValue = annotation.value("type");
    final DotName declaredTypeDotName = fieldInfo.type().name();
    final DotName injectionTypeDotName = declaredTypeDotName == null || declaredTypeDotName.toString().equals(Object.class.getName()) ? fieldInfo.type().name() : declaredTypeDotName;
    final String injectionType = injectionTypeDotName.toString();
    final InjectionSource bindingSource = this.getBindingSource(deploymentUnit, annotation, injectionType, eeModuleClassDescription);
    if (bindingSource != null) {
        final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, bindingSource);
        eeModuleClassDescription.getBindingConfigurations().add(bindingConfiguration);
        // setup the injection target
        final InjectionTarget injectionTarget = new FieldInjectionTarget(fieldInfo.declaringClass().name().toString(), fieldName, fieldInfo.type().name().toString());
        // source is always local ENC jndi
        final InjectionSource injectionSource = new LookupInjectionSource(localContextName);
        final ResourceInjectionConfiguration injectionConfiguration = new ResourceInjectionConfiguration(injectionTarget, injectionSource);
        eeModuleClassDescription.addResourceInjection(injectionConfiguration);
    }
}
Also used : LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) InjectionSource(org.jboss.as.ee.component.InjectionSource) PersistenceContextInjectionSource(org.jboss.as.jpa.injectors.PersistenceContextInjectionSource) PersistenceUnitInjectionSource(org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource) AnnotationValue(org.jboss.jandex.AnnotationValue) FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget) MethodInjectionTarget(org.jboss.as.ee.component.MethodInjectionTarget) InjectionTarget(org.jboss.as.ee.component.InjectionTarget) FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget) DotName(org.jboss.jandex.DotName) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) ResourceInjectionConfiguration(org.jboss.as.ee.component.ResourceInjectionConfiguration)

Aggregations

FieldInjectionTarget (org.jboss.as.ee.component.FieldInjectionTarget)5 InjectionTarget (org.jboss.as.ee.component.InjectionTarget)5 MethodInjectionTarget (org.jboss.as.ee.component.MethodInjectionTarget)5 AccessibleObject (java.lang.reflect.AccessibleObject)2 ResourceInjectionConfiguration (org.jboss.as.ee.component.ResourceInjectionConfiguration)2 InjectionUtils.getInjectionTarget (org.jboss.as.ee.utils.InjectionUtils.getInjectionTarget)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)1 InjectionSource (org.jboss.as.ee.component.InjectionSource)1 LookupInjectionSource (org.jboss.as.ee.component.LookupInjectionSource)1 ResourceInjectionTarget (org.jboss.as.ee.component.ResourceInjectionTarget)1 PersistenceContextInjectionSource (org.jboss.as.jpa.injectors.PersistenceContextInjectionSource)1 PersistenceUnitInjectionSource (org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource)1 AnnotationValue (org.jboss.jandex.AnnotationValue)1 DotName (org.jboss.jandex.DotName)1 ResourceInjectionTargetMetaData (org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData)1