Search in sources :

Example 6 with ResourceInjectionConfiguration

use of org.jboss.as.ee.component.ResourceInjectionConfiguration 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

ResourceInjectionConfiguration (org.jboss.as.ee.component.ResourceInjectionConfiguration)6 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)5 InjectionSource (org.jboss.as.ee.component.InjectionSource)5 LookupInjectionSource (org.jboss.as.ee.component.LookupInjectionSource)5 FieldInjectionTarget (org.jboss.as.ee.component.FieldInjectionTarget)3 InjectionTarget (org.jboss.as.ee.component.InjectionTarget)3 MethodInjectionTarget (org.jboss.as.ee.component.MethodInjectionTarget)3 AnnotationValue (org.jboss.jandex.AnnotationValue)3 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)2 PersistenceContextInjectionSource (org.jboss.as.jpa.injectors.PersistenceContextInjectionSource)2 PersistenceUnitInjectionSource (org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource)2 AccessibleObject (java.lang.reflect.AccessibleObject)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)1 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)1 FixedInjectionSource (org.jboss.as.ee.component.FixedInjectionSource)1 ResourceInjectionTarget (org.jboss.as.ee.component.ResourceInjectionTarget)1