Search in sources :

Example 11 with LookupInjectionSource

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

the class JPAAnnotationProcessor method processMethod.

private void processMethod(final DeploymentUnit deploymentUnit, final AnnotationInstance annotation, final MethodInfo methodInfo, final EEModuleClassDescription eeModuleClassDescription) throws DeploymentUnitProcessingException {
    final String methodName = methodInfo.name();
    if (!methodName.startsWith("set") || methodInfo.args().length != 1) {
        eeModuleClassDescription.setInvalid(JpaLogger.ROOT_LOGGER.setterMethodOnlyAnnotation(annotation.name().toString(), methodInfo));
        return;
    }
    final String contextNameSuffix = methodName.substring(3, 4).toLowerCase(Locale.ENGLISH) + methodName.substring(4);
    final AnnotationValue declaredNameValue = annotation.value("name");
    final String declaredName = declaredNameValue != null ? declaredNameValue.asString() : null;
    final String localContextName;
    if (declaredName == null || declaredName.isEmpty()) {
        localContextName = methodInfo.declaringClass().name().toString() + "/" + contextNameSuffix;
    } else {
        localContextName = declaredName;
    }
    final String injectionType = methodInfo.args()[0].name().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 configuration
        final InjectionTarget injectionTarget = new MethodInjectionTarget(methodInfo.declaringClass().name().toString(), methodName, methodInfo.args()[0].name().toString());
        // source is always local ENC jndi name
        final InjectionSource injectionSource = new LookupInjectionSource(localContextName);
        final ResourceInjectionConfiguration injectionConfiguration = new ResourceInjectionConfiguration(injectionTarget, injectionSource);
        eeModuleClassDescription.addResourceInjection(injectionConfiguration);
    }
}
Also used : MethodInjectionTarget(org.jboss.as.ee.component.MethodInjectionTarget) 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) MethodInjectionTarget(org.jboss.as.ee.component.MethodInjectionTarget) InjectionTarget(org.jboss.as.ee.component.InjectionTarget) FieldInjectionTarget(org.jboss.as.ee.component.FieldInjectionTarget) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) ResourceInjectionConfiguration(org.jboss.as.ee.component.ResourceInjectionConfiguration)

Example 12 with LookupInjectionSource

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

Example 13 with LookupInjectionSource

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

the class EjbRefProcessor method processDescriptorEntries.

/**
     * Resolves ejb-ref and ejb-local-ref elements
     *
     *
     * @param deploymentUnit
     * @param environment               The environment to resolve the elements for
     * @param componentDescription
     *@param classLoader               The deployment class loader
     * @param deploymentReflectionIndex The reflection index
     * @param applicationClasses    @return The bindings for the environment entries
     */
protected List<BindingConfiguration> processDescriptorEntries(DeploymentUnit deploymentUnit, DeploymentDescriptorEnvironment environment, ResourceInjectionTarget resourceInjectionTarget, final ComponentDescription componentDescription, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
    final RemoteEnvironment remoteEnvironment = environment.getEnvironment();
    List<BindingConfiguration> bindingDescriptions = new ArrayList<BindingConfiguration>();
    EJBReferencesMetaData ejbRefs = remoteEnvironment.getEjbReferences();
    if (ejbRefs != null) {
        for (EJBReferenceMetaData ejbRef : ejbRefs) {
            String name = ejbRef.getEjbRefName();
            String ejbName = ejbRef.getLink();
            String lookup = ejbRef.getLookupName() != null ? ejbRef.getLookupName() : ejbRef.getMappedName();
            String remoteInterface = ejbRef.getRemote();
            String home = ejbRef.getHome();
            Class<?> remoteInterfaceType = null;
            //if a home is specified this is the type that is bound
            if (!isEmpty(home)) {
                try {
                    remoteInterfaceType = ClassLoadingUtils.loadClass(home, deploymentUnit);
                } catch (ClassNotFoundException e) {
                    throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, home);
                }
            } else if (!isEmpty(remoteInterface)) {
                try {
                    remoteInterfaceType = ClassLoadingUtils.loadClass(remoteInterface, deploymentUnit);
                } catch (ClassNotFoundException e) {
                    throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, remoteInterface);
                }
            }
            if (!name.startsWith("java:")) {
                name = environment.getDefaultContext() + name;
            }
            // our injection (source) comes from the local (ENC) lookup, no matter what.
            LookupInjectionSource injectionSource = new LookupInjectionSource(name);
            //add any injection targets
            remoteInterfaceType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, ejbRef, remoteInterfaceType);
            final BindingConfiguration bindingConfiguration;
            EjbInjectionSource ejbInjectionSource = null;
            if (!isEmpty(lookup)) {
                if (!lookup.startsWith("java:")) {
                    bindingConfiguration = new BindingConfiguration(name, new EjbLookupInjectionSource(lookup, remoteInterfaceType));
                } else {
                    bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
                }
            } else {
                if (remoteInterfaceType == null) {
                    throw EjbLogger.ROOT_LOGGER.couldNotDetermineEjbRefForInjectionTarget(name, resourceInjectionTarget);
                }
                if (!isEmpty(ejbName)) {
                    bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(ejbName, remoteInterfaceType.getName(), name, deploymentUnit, appclient));
                } else {
                    bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(remoteInterfaceType.getName(), name, deploymentUnit, appclient));
                }
            }
            if (ejbInjectionSource != null) {
                deploymentUnit.addToAttachmentList(EjbDeploymentAttachmentKeys.EJB_INJECTIONS, ejbInjectionSource);
            }
            bindingDescriptions.add(bindingConfiguration);
        }
    }
    if (remoteEnvironment instanceof Environment && !appclient) {
        EJBLocalReferencesMetaData ejbLocalRefs = ((Environment) remoteEnvironment).getEjbLocalReferences();
        if (ejbLocalRefs != null) {
            for (EJBLocalReferenceMetaData ejbRef : ejbLocalRefs) {
                String name = ejbRef.getEjbRefName();
                String ejbName = ejbRef.getLink();
                String lookup = ejbRef.getLookupName() != null ? ejbRef.getLookupName() : ejbRef.getMappedName();
                String localInterface = ejbRef.getLocal();
                String localHome = ejbRef.getLocalHome();
                Class<?> localInterfaceType = null;
                //if a home is specified this is the type that is bound
                if (!isEmpty(localHome)) {
                    try {
                        localInterfaceType = ClassLoadingUtils.loadClass(localHome, deploymentUnit);
                    } catch (ClassNotFoundException e) {
                        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, localHome);
                    }
                } else if (!isEmpty(localInterface)) {
                    try {
                        localInterfaceType = ClassLoadingUtils.loadClass(localInterface, deploymentUnit);
                    } catch (ClassNotFoundException e) {
                        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClass(e, localInterface);
                    }
                }
                if (!name.startsWith("java:")) {
                    name = environment.getDefaultContext() + name;
                }
                // our injection (source) comes from the local (ENC) lookup, no matter what.
                LookupInjectionSource injectionSource = new LookupInjectionSource(name);
                //add any injection targets
                localInterfaceType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, ejbRef, localInterfaceType);
                if (localInterfaceType == null) {
                    throw EjbLogger.ROOT_LOGGER.couldNotDetermineEjbLocalRefForInjectionTarget(name, resourceInjectionTarget);
                }
                final BindingConfiguration bindingConfiguration;
                EjbInjectionSource ejbInjectionSource = null;
                if (!isEmpty(lookup)) {
                    if (!lookup.startsWith("java:")) {
                        bindingConfiguration = new BindingConfiguration(name, new EjbLookupInjectionSource(lookup, localInterfaceType));
                    } else {
                        bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
                    }
                } else if (!isEmpty(ejbName)) {
                    bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(ejbName, localInterfaceType.getName(), name, deploymentUnit, appclient));
                } else {
                    bindingConfiguration = new BindingConfiguration(name, ejbInjectionSource = new EjbInjectionSource(localInterfaceType.getName(), name, deploymentUnit, appclient));
                }
                if (ejbInjectionSource != null) {
                    deploymentUnit.addToAttachmentList(EjbDeploymentAttachmentKeys.EJB_INJECTIONS, ejbInjectionSource);
                }
                bindingDescriptions.add(bindingConfiguration);
            }
        }
    }
    return bindingDescriptions;
}
Also used : RemoteEnvironment(org.jboss.metadata.javaee.spec.RemoteEnvironment) EJBLocalReferenceMetaData(org.jboss.metadata.javaee.spec.EJBLocalReferenceMetaData) ArrayList(java.util.ArrayList) EJBReferenceMetaData(org.jboss.metadata.javaee.spec.EJBReferenceMetaData) Environment(org.jboss.metadata.javaee.spec.Environment) RemoteEnvironment(org.jboss.metadata.javaee.spec.RemoteEnvironment) DeploymentDescriptorEnvironment(org.jboss.as.ee.component.DeploymentDescriptorEnvironment) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) EJBReferencesMetaData(org.jboss.metadata.javaee.spec.EJBReferencesMetaData) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) EJBLocalReferencesMetaData(org.jboss.metadata.javaee.spec.EJBLocalReferencesMetaData)

Aggregations

BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)13 LookupInjectionSource (org.jboss.as.ee.component.LookupInjectionSource)13 InjectionSource (org.jboss.as.ee.component.InjectionSource)8 ArrayList (java.util.ArrayList)7 ResourceInjectionConfiguration (org.jboss.as.ee.component.ResourceInjectionConfiguration)4 PersistenceContextInjectionSource (org.jboss.as.jpa.injectors.PersistenceContextInjectionSource)4 PersistenceUnitInjectionSource (org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource)4 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)3 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)3 EnvEntryInjectionSource (org.jboss.as.ee.component.EnvEntryInjectionSource)3 FixedInjectionSource (org.jboss.as.ee.component.FixedInjectionSource)3 AnnotationValue (org.jboss.jandex.AnnotationValue)3 HashMap (java.util.HashMap)2 DeploymentDescriptorEnvironment (org.jboss.as.ee.component.DeploymentDescriptorEnvironment)2 FieldInjectionTarget (org.jboss.as.ee.component.FieldInjectionTarget)2 InjectionTarget (org.jboss.as.ee.component.InjectionTarget)2 MethodInjectionTarget (org.jboss.as.ee.component.MethodInjectionTarget)2 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 Environment (org.jboss.metadata.javaee.spec.Environment)2