Search in sources :

Example 6 with BindingConfiguration

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

the class ResourceDefinitionAnnotationProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    if (moduleDescription == null) {
        return;
    }
    final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (index == null) {
        return;
    }
    final PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
    final DotName annotationName = getAnnotationDotName();
    for (AnnotationInstance annotationInstance : index.getAnnotations(annotationName)) {
        final List<BindingConfiguration> bindingConfigurations = getAnnotatedClassBindingConfigurations(moduleDescription, annotationInstance);
        final ResourceDefinitionInjectionSource injectionSource = processAnnotation(annotationInstance, propertyReplacer);
        bindingConfigurations.add(new BindingConfiguration(injectionSource.getJndiName(), injectionSource));
    }
    final DotName collectionAnnotationName = getAnnotationCollectionDotName();
    if (collectionAnnotationName != null) {
        for (AnnotationInstance annotationInstance : index.getAnnotations(collectionAnnotationName)) {
            final AnnotationInstance[] nestedAnnotationInstances = annotationInstance.value().asNestedArray();
            if (nestedAnnotationInstances != null && nestedAnnotationInstances.length > 0) {
                final List<BindingConfiguration> bindingConfigurations = getAnnotatedClassBindingConfigurations(moduleDescription, annotationInstance);
                for (AnnotationInstance nestedAnnotationInstance : nestedAnnotationInstances) {
                    final ResourceDefinitionInjectionSource injectionSource = processAnnotation(nestedAnnotationInstance, propertyReplacer);
                    bindingConfigurations.add(new BindingConfiguration(injectionSource.getJndiName(), injectionSource));
                }
            }
        }
    }
}
Also used : EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DotName(org.jboss.jandex.DotName) AnnotationInstance(org.jboss.jandex.AnnotationInstance) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Example 7 with BindingConfiguration

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

the class EjbContextJndiBindingProcessor method processComponentConfig.

protected void processComponentConfig(final DeploymentUnit deploymentUnit, final DeploymentPhaseContext phaseContext, final CompositeIndex index, final ComponentDescription componentDescription) throws DeploymentUnitProcessingException {
    if (!(componentDescription instanceof EJBComponentDescription)) {
        // Only process EJBs
        return;
    }
    // if the EJB is packaged in a .war, then we need to bind the java:comp/EJBContext only once for the entire module
    if (componentDescription.getNamingMode() != ComponentNamingMode.CREATE) {
        // get the module description
        final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
        // the java:module/EJBContext binding configuration
        // Note that we bind to java:module/EJBContext since it's a .war. End users can still lookup java:comp/EJBContext
        // and that will internally get translated to  java:module/EJBContext for .war, since java:comp == java:module in
        // a web ENC. So binding to java:module/EJBContext is OK.
        final BindingConfiguration ejbContextBinding = new BindingConfiguration("java:module/EJBContext", directEjbContextReferenceSource);
        moduleDescription.getBindingConfigurations().add(ejbContextBinding);
    } else {
        // EJB packaged outside of a .war. So process normally.
        // add the binding configuration to the component description
        final BindingConfiguration ejbContextBinding = new BindingConfiguration("java:comp/EJBContext", directEjbContextReferenceSource);
        componentDescription.getBindingConfigurations().add(ejbContextBinding);
    }
}
Also used : EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Example 8 with BindingConfiguration

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

the class TimerServiceJndiBindingProcessor method processComponentConfig.

@Override
protected void processComponentConfig(DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext, CompositeIndex index, ComponentDescription componentDescription) throws DeploymentUnitProcessingException {
    if (!(componentDescription instanceof EJBComponentDescription)) {
        // Only process EJBs
        return;
    }
    // if the EJB is packaged in a .war, then we need to bind the java:comp/TimerService only once for the entire module
    if (componentDescription.getNamingMode() != ComponentNamingMode.CREATE) {
        // get the module description
        final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
        // the java:module/TimerService binding configuration
        // Note that we bind to java:module/TimerService since it's a .war. End users can still lookup java:comp/TimerService
        // and that will internally get translated to  java:module/TimerService for .war, since java:comp == java:module in
        // a web ENC. So binding to java:module/TimerService is OK.
        final BindingConfiguration timerServiceBinding = new BindingConfiguration("java:module/TimerService", new TimerServiceBindingSource());
        moduleDescription.getBindingConfigurations().add(timerServiceBinding);
    } else {
        // EJB packaged outside of a .war. So process normally.
        // add the binding configuration to the component description
        final BindingConfiguration timerServiceBinding = new BindingConfiguration("java:comp/TimerService", new TimerServiceBindingSource());
        componentDescription.getBindingConfigurations().add(timerServiceBinding);
    }
}
Also used : TimerServiceBindingSource(org.jboss.as.ejb3.timerservice.TimerServiceBindingSource) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Example 9 with BindingConfiguration

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

the class EjbResourceInjectionAnnotationProcessor method process.

private void process(final DeploymentUnit deploymentUnit, final String beanInterface, final String beanName, final String lookup, final ClassInfo classInfo, final InjectionTarget targetDescription, final String localContextName, final EEModuleDescription eeModuleDescription) {
    if (!isEmpty(lookup) && !isEmpty(beanName)) {
        EjbLogger.DEPLOYMENT_LOGGER.debugf("Both beanName = %s and lookup = %s have been specified in @EJB annotation. Lookup will be given preference. Class: %s", beanName, lookup, classInfo.name());
    }
    final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
    final InjectionSource valueSource;
    EjbInjectionSource ejbInjectionSource = null;
    //give preference to lookup
    if (!isEmpty(lookup)) {
        if (!lookup.startsWith("java:")) {
            valueSource = new EjbLookupInjectionSource(lookup, targetDescription == null ? null : targetDescription.getDeclaredValueClassName());
        } else {
            valueSource = createLookup(lookup, appclient);
        }
    } else if (!isEmpty(beanName)) {
        valueSource = ejbInjectionSource = new EjbInjectionSource(beanName, beanInterface, localContextName, deploymentUnit, appclient);
    } else {
        valueSource = ejbInjectionSource = new EjbInjectionSource(beanInterface, localContextName, deploymentUnit, appclient);
    }
    if (ejbInjectionSource != null) {
        deploymentUnit.addToAttachmentList(EjbDeploymentAttachmentKeys.EJB_INJECTIONS, ejbInjectionSource);
    }
    // our injection comes from the local lookup, no matter what.
    final ResourceInjectionConfiguration injectionConfiguration = targetDescription != null ? new ResourceInjectionConfiguration(targetDescription, createLookup(localContextName, appclient)) : null;
    // Create the binding from whence our injection comes.
    final BindingConfiguration bindingConfiguration = new BindingConfiguration(localContextName, valueSource);
    classDescription.getBindingConfigurations().add(bindingConfiguration);
    if (injectionConfiguration != null) {
        classDescription.addResourceInjection(injectionConfiguration);
    }
}
Also used : LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) InjectionSource(org.jboss.as.ee.component.InjectionSource) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) ResourceInjectionConfiguration(org.jboss.as.ee.component.ResourceInjectionConfiguration)

Example 10 with BindingConfiguration

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

the class WSRefDDProcessor method processDescriptorEntries.

@Override
protected List<BindingConfiguration> processDescriptorEntries(final DeploymentUnit unit, final DeploymentDescriptorEnvironment environment, final ResourceInjectionTarget resourceInjectionTarget, final ComponentDescription componentDescription, final ClassLoader classLoader, final DeploymentReflectionIndex deploymentReflectionIndex, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
    final ServiceReferencesMetaData serviceRefsMD = environment.getEnvironment().getServiceReferences();
    if (serviceRefsMD == null) {
        return Collections.<BindingConfiguration>emptyList();
    }
    final List<BindingConfiguration> bindingDescriptions = new LinkedList<BindingConfiguration>();
    for (final ServiceReferenceMetaData serviceRefMD : serviceRefsMD) {
        final UnifiedServiceRefMetaData serviceRefUMDM = getServiceRef(unit, componentDescription, serviceRefMD);
        final Module module = unit.getAttachment(Attachments.MODULE);
        WebServiceManagedReferenceFactory factory = new WebServiceManagedReferenceFactory(serviceRefUMDM, module.getClassLoader());
        final FixedInjectionSource valueSource = new FixedInjectionSource(factory, factory);
        final BindingConfiguration bindingConfiguration = new BindingConfiguration(serviceRefUMDM.getServiceRefName(), valueSource);
        bindingDescriptions.add(bindingConfiguration);
        final String serviceRefTypeName = serviceRefUMDM.getServiceRefType();
        final Class<?> serviceRefType = getClass(classLoader, serviceRefTypeName);
        processInjectionTargets(resourceInjectionTarget, valueSource, classLoader, deploymentReflectionIndex, serviceRefMD, serviceRefType);
    }
    return bindingDescriptions;
}
Also used : FixedInjectionSource(org.jboss.as.ee.component.FixedInjectionSource) ServiceReferencesMetaData(org.jboss.metadata.javaee.spec.ServiceReferencesMetaData) UnifiedServiceRefMetaData(org.jboss.wsf.spi.metadata.j2ee.serviceref.UnifiedServiceRefMetaData) Module(org.jboss.modules.Module) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LinkedList(java.util.LinkedList) ServiceReferenceMetaData(org.jboss.metadata.javaee.spec.ServiceReferenceMetaData)

Aggregations

BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)25 LookupInjectionSource (org.jboss.as.ee.component.LookupInjectionSource)15 InjectionSource (org.jboss.as.ee.component.InjectionSource)12 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)10 ArrayList (java.util.ArrayList)7 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)6 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)5 ResourceInjectionConfiguration (org.jboss.as.ee.component.ResourceInjectionConfiguration)5 PersistenceContextInjectionSource (org.jboss.as.jpa.injectors.PersistenceContextInjectionSource)5 PersistenceUnitInjectionSource (org.jboss.as.jpa.injectors.PersistenceUnitInjectionSource)5 ManagedReferenceFactory (org.jboss.as.naming.ManagedReferenceFactory)5 FixedInjectionSource (org.jboss.as.ee.component.FixedInjectionSource)4 AnnotationValue (org.jboss.jandex.AnnotationValue)4 Module (org.jboss.modules.Module)4 HashMap (java.util.HashMap)3 DeploymentDescriptorEnvironment (org.jboss.as.ee.component.DeploymentDescriptorEnvironment)3 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)3 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)3 EnvEntryInjectionSource (org.jboss.as.ee.component.EnvEntryInjectionSource)3 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)3