Search in sources :

Example 1 with ResourceInjectionConfiguration

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

the class WSRefAnnotationProcessor method processRef.

private static void processRef(final DeploymentUnit unit, final String type, final WSRefAnnotationWrapper annotation, final ClassInfo classInfo, final InjectionTarget injectionTarget, final String bindingName) throws DeploymentUnitProcessingException {
    final EEModuleDescription moduleDescription = unit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final AnnotatedElement target = createAnnotatedElement(unit, classInfo, injectionTarget);
    final String componentClassName = classInfo.name().toString();
    final Map<String, String> bindingMap = new HashMap<String, String>();
    boolean isEJB = false;
    for (final ComponentDescription componentDescription : moduleDescription.getComponentsByClassName(componentClassName)) {
        if (componentDescription instanceof SessionBeanComponentDescription) {
            isEJB = true;
            bindingMap.put(componentDescription.getComponentName() + "/" + bindingName, bindingName);
        }
    }
    if (!isEJB) {
        bindingMap.put(bindingName, bindingName);
    }
    for (String refKey : bindingMap.keySet()) {
        String refName = bindingMap.get(refKey);
        ManagedReferenceFactory factory = WebServiceReferences.createWebServiceFactory(unit, type, annotation, target, refName, refKey);
        final EEModuleClassDescription classDescription = moduleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
        // Create the binding from whence our injection comes.
        final InjectionSource serviceRefSource = new FixedInjectionSource(factory, factory);
        final BindingConfiguration bindingConfiguration = new BindingConfiguration(refName, serviceRefSource);
        classDescription.getBindingConfigurations().add(bindingConfiguration);
        // our injection comes from the local lookup, no matter what.
        final ResourceInjectionConfiguration injectionConfiguration = injectionTarget != null ? new ResourceInjectionConfiguration(injectionTarget, new LookupInjectionSource(refName)) : null;
        if (injectionConfiguration != null) {
            classDescription.addResourceInjection(injectionConfiguration);
        }
    }
}
Also used : SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) HashMap(java.util.HashMap) AnnotatedElement(java.lang.reflect.AnnotatedElement) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) InjectionSource(org.jboss.as.ee.component.InjectionSource) FixedInjectionSource(org.jboss.as.ee.component.FixedInjectionSource) FixedInjectionSource(org.jboss.as.ee.component.FixedInjectionSource) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) ResourceInjectionConfiguration(org.jboss.as.ee.component.ResourceInjectionConfiguration)

Example 2 with ResourceInjectionConfiguration

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

the class ResourceInjectionAnnotationParsingProcessor method process.

protected void process(final DeploymentPhaseContext phaseContext, final EEModuleClassDescription classDescription, final AnnotationInstance annotation, final String injectionType, final String localContextName, final InjectionTarget targetDescription, final EEModuleDescription eeModuleDescription, final Module module, final EEApplicationClasses applicationClasses, final PropertyReplacer replacer) throws DeploymentUnitProcessingException {
    final EEResourceReferenceProcessorRegistry registry = phaseContext.getDeploymentUnit().getAttachment(Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
    final AnnotationValue lookupAnnotation = annotation.value("lookup");
    String lookup = (lookupAnnotation == null) ? null : replacer.replaceProperties(lookupAnnotation.asString());
    // if "lookup" hasn't been specified then fallback on "mappedName" which we treat the same as "lookup"
    if (isEmpty(lookup)) {
        final AnnotationValue mappedNameAnnotationValue = annotation.value("mappedName");
        lookup = (mappedNameAnnotationValue == null) ? null : replacer.replaceProperties(mappedNameAnnotationValue.asString());
    }
    if (isEmpty(lookup) && FIXED_LOCATIONS.containsKey(injectionType)) {
        lookup = FIXED_LOCATIONS.get(injectionType);
    }
    InjectionSource valueSource = null;
    final boolean isEnvEntryType = this.isEnvEntryType(injectionType, module);
    if (!isEmpty(lookup)) {
        valueSource = new LookupInjectionSource(lookup, JAVAX_NAMING_CONTEXT.equals(injectionType));
    } else if (isEnvEntryType) {
    // if it's an env-entry type then we do *not* create a BindingConfiguration to bind to the ENC
    // since the binding (value) for env-entry is always driven from a deployment descriptor.
    // The deployment descriptor processing and subsequent binding in the ENC is taken care off by a
    // different Deployment unit processor. If the value isn't specified in the deployment descriptor,
    // then there will be no binding the ENC and that's what is expected by the Java EE 6 spec. Furthermore,
    // if the @Resource is an env-entry binding then the injection target will be optional since in the absence of
    // an env-entry-value, there won't be a binding and effectively no injection. This again is as expected by spec.
    } else {
        //otherwise we just try and handle it
        //if we don't have a value source we will try and inject from a lookup
        //and the user has to configure the value in a deployment descriptor
        final EEResourceReferenceProcessor resourceReferenceProcessor = registry.getResourceReferenceProcessor(injectionType);
        if (resourceReferenceProcessor != null) {
            valueSource = resourceReferenceProcessor.getResourceReferenceBindingSource();
        }
    }
    if (valueSource == null) {
        // the ResourceInjectionConfiguration is created by LazyResourceInjection
        if (targetDescription != null) {
            final LookupInjectionSource optionalInjection = new LookupInjectionSource(localContextName, true);
            final ResourceInjectionConfiguration injectionConfiguration = new ResourceInjectionConfiguration(targetDescription, optionalInjection, true);
            classDescription.addResourceInjection(injectionConfiguration);
        }
    } else {
        // our injection comes from the local lookup, no matter what.
        final InjectionSource injectionSource = new LookupInjectionSource(localContextName);
        final ResourceInjectionConfiguration injectionConfiguration = targetDescription != null ? new ResourceInjectionConfiguration(targetDescription, injectionSource) : null;
        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) AnnotationValue(org.jboss.jandex.AnnotationValue) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) ResourceInjectionConfiguration(org.jboss.as.ee.component.ResourceInjectionConfiguration)

Example 3 with ResourceInjectionConfiguration

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

Example 4 with ResourceInjectionConfiguration

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

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

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