Search in sources :

Example 21 with BindingConfiguration

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

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

the class ResourceReferenceProcessor method getEnvironmentEntries.

private List<BindingConfiguration> getEnvironmentEntries(final DeploymentDescriptorEnvironment environment, final ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionTarget resourceInjectionTarget) throws DeploymentUnitProcessingException {
    final List<BindingConfiguration> bindings = new ArrayList<BindingConfiguration>();
    final EnvironmentEntriesMetaData envEntries = environment.getEnvironment().getEnvironmentEntries();
    if (envEntries == null) {
        return bindings;
    }
    for (final EnvironmentEntryMetaData envEntry : envEntries) {
        final String name;
        if (envEntry.getName().startsWith("java:")) {
            name = envEntry.getName();
        } else {
            name = environment.getDefaultContext() + envEntry.getEnvEntryName();
        }
        Class<?> classType = null;
        if (envEntry.getType() != null) {
            try {
                classType = this.loadClass(envEntry.getType(), classLoader);
            } catch (ClassNotFoundException e) {
                throw EeLogger.ROOT_LOGGER.cannotLoad(e, envEntry.getType());
            }
        }
        final String value = envEntry.getValue();
        final String lookup = envEntry.getLookupName();
        if (!isEmpty(value) && !isEmpty(lookup)) {
            throw EeLogger.ROOT_LOGGER.cannotSpecifyBoth("<env-entry-value>", "<lookup-name>");
        } else if (isEmpty(lookup) && isEmpty(value)) {
            // (Java ee platform spec 6.0 fr pg 80)
            continue;
        }
        // our injection (source) comes from the local (ENC) lookup, no matter what.
        LookupInjectionSource injectionSource = new LookupInjectionSource(name);
        classType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, envEntry, classType);
        if (classType == null) {
            throw EeLogger.ROOT_LOGGER.cannotDetermineType("<env-entry>", name, "<env-entry-type>");
        }
        final String type = classType.getName();
        final BindingConfiguration bindingConfiguration;
        if (!isEmpty(lookup)) {
            bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
        } else if (type.equals(String.class.getName())) {
            bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(value));
        } else if (type.equals(Integer.class.getName()) || type.equals("int")) {
            bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Integer.valueOf(value)));
        } else if (type.equals(Short.class.getName()) || type.equals("short")) {
            bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Short.valueOf(value)));
        } else if (type.equals(Long.class.getName()) || type.equals("long")) {
            bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Long.valueOf(value)));
        } else if (type.equals(Byte.class.getName()) || type.equals("byte")) {
            bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Byte.valueOf(value)));
        } else if (type.equals(Double.class.getName()) || type.equals("double")) {
            bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Double.valueOf(value)));
        } else if (type.equals(Float.class.getName()) || type.equals("float")) {
            bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Float.valueOf(value)));
        } else if (type.equals(Boolean.class.getName()) || type.equals("boolean")) {
            bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Boolean.valueOf(value)));
        } else if (type.equals(Character.class.getName()) || type.equals("char")) {
            if (value.length() != 1) {
                throw EeLogger.ROOT_LOGGER.invalidCharacterLength("env-entry", value);
            }
            bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(value.charAt(0)));
        } else if (type.equals(Class.class.getName())) {
            try {
                bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(classLoader.loadClass(value)));
            } catch (ClassNotFoundException e) {
                throw EeLogger.ROOT_LOGGER.cannotLoad(value);
            }
        } else if (classType.isEnum() || (classType.getEnclosingClass() != null && classType.getEnclosingClass().isEnum())) {
            bindingConfiguration = new BindingConfiguration(name, new EnvEntryInjectionSource(Enum.valueOf((Class) classType, value)));
        } else {
            throw EeLogger.ROOT_LOGGER.unknownElementType("env-entry", type);
        }
        bindings.add(bindingConfiguration);
    }
    return bindings;
}
Also used : ArrayList(java.util.ArrayList) EnvironmentEntriesMetaData(org.jboss.metadata.javaee.spec.EnvironmentEntriesMetaData) EnvEntryInjectionSource(org.jboss.as.ee.component.EnvEntryInjectionSource) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) EnvironmentEntryMetaData(org.jboss.metadata.javaee.spec.EnvironmentEntryMetaData)

Example 23 with BindingConfiguration

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

the class ResourceReferenceProcessor method getMessageDestinationRefs.

/**
     * TODO: should this be part of the messaging subsystem
     */
private List<BindingConfiguration> getMessageDestinationRefs(final DeploymentDescriptorEnvironment environment, final ClassLoader classLoader, final DeploymentReflectionIndex deploymentReflectionIndex, final ResourceInjectionTarget resourceInjectionTarget, final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    final List<BindingConfiguration> bindings = new ArrayList<BindingConfiguration>();
    final MessageDestinationReferencesMetaData messageDestinationReferences = environment.getEnvironment().getMessageDestinationReferences();
    if (messageDestinationReferences == null) {
        return bindings;
    }
    for (final MessageDestinationReferenceMetaData messageRef : messageDestinationReferences) {
        final String name;
        if (messageRef.getName().startsWith("java:")) {
            name = messageRef.getName();
        } else {
            name = environment.getDefaultContext() + messageRef.getName();
        }
        Class<?> classType = null;
        if (messageRef.getType() != null) {
            try {
                classType = classLoader.loadClass(messageRef.getType());
            } catch (ClassNotFoundException e) {
                throw EeLogger.ROOT_LOGGER.cannotLoad(e, messageRef.getType());
            }
        }
        // our injection (source) comes from the local (ENC) lookup, no matter what.
        final LookupInjectionSource injectionSource = new LookupInjectionSource(name);
        classType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, messageRef, classType);
        final BindingConfiguration bindingConfiguration;
        if (!isEmpty(messageRef.getLookupName())) {
            bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(messageRef.getLookupName()));
            bindings.add(bindingConfiguration);
        } else if (!isEmpty(messageRef.getMappedName())) {
            bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(messageRef.getMappedName()));
            bindings.add(bindingConfiguration);
        } else if (!isEmpty(messageRef.getLink())) {
            final MessageDestinationInjectionSource messageDestinationInjectionSource = new MessageDestinationInjectionSource(messageRef.getLink(), name);
            bindingConfiguration = new BindingConfiguration(name, messageDestinationInjectionSource);
            deploymentUnit.addToAttachmentList(Attachments.MESSAGE_DESTINATIONS, messageDestinationInjectionSource);
            bindings.add(bindingConfiguration);
        } else {
            ROOT_LOGGER.cannotResolve("message-destination-ref", name);
        }
    }
    return bindings;
}
Also used : ArrayList(java.util.ArrayList) MessageDestinationReferencesMetaData(org.jboss.metadata.javaee.spec.MessageDestinationReferencesMetaData) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) MessageDestinationReferenceMetaData(org.jboss.metadata.javaee.spec.MessageDestinationReferenceMetaData)

Example 24 with BindingConfiguration

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

the class ResourceReferenceProcessor method getResourceRefEntries.

private List<BindingConfiguration> getResourceRefEntries(final DeploymentUnit deploymentUnit, DeploymentDescriptorEnvironment environment, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionTarget resourceInjectionTarget) throws DeploymentUnitProcessingException {
    List<BindingConfiguration> bindings = new ArrayList<BindingConfiguration>();
    final EEResourceReferenceProcessorRegistry registry = deploymentUnit.getAttachment(Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
    final ResourceReferencesMetaData resourceRefs = environment.getEnvironment().getResourceReferences();
    if (resourceRefs == null) {
        return bindings;
    }
    for (final ResourceReferenceMetaData resourceRef : resourceRefs) {
        final String name;
        if (resourceRef.getName().startsWith("java:")) {
            name = resourceRef.getName();
        } else {
            name = environment.getDefaultContext() + resourceRef.getName();
        }
        Class<?> classType = null;
        if (resourceRef.getType() != null) {
            try {
                classType = classLoader.loadClass(resourceRef.getType());
            } catch (ClassNotFoundException e) {
                throw EeLogger.ROOT_LOGGER.cannotLoad(e, resourceRef.getType());
            }
        }
        // our injection (source) comes from the local (ENC) lookup, no matter what.
        InjectionSource injectionSource = new LookupInjectionSource(name);
        classType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, resourceRef, classType);
        if (!isEmpty(resourceRef.getLookupName())) {
            injectionSource = new LookupInjectionSource(resourceRef.getLookupName(), classType != null && JAVAX_NAMING_CONTEXT.equals(classType.getName()));
        } else if (!isEmpty(resourceRef.getResUrl())) {
            final String url = resourceRef.getResUrl();
            if (classType != null && classType.equals(URI.class)) {
                try {
                    //we need a newURI every time
                    injectionSource = new FixedInjectionSource(new ManagedReferenceFactory() {

                        @Override
                        public ManagedReference getReference() {
                            try {
                                return new ImmediateManagedReference(new URI(url));
                            } catch (URISyntaxException e) {
                                throw new RuntimeException(e);
                            }
                        }
                    }, new URI(url));
                } catch (URISyntaxException e) {
                    throw EeLogger.ROOT_LOGGER.cannotParseResourceRefUri(e, resourceRef.getResUrl());
                }
            } else {
                try {
                    injectionSource = new FixedInjectionSource(new ManagedReferenceFactory() {

                        @Override
                        public ManagedReference getReference() {
                            try {
                                return new ImmediateManagedReference(new URL(url));
                            } catch (MalformedURLException e) {
                                throw new RuntimeException(e);
                            }
                        }
                    }, new URL(url));
                } catch (MalformedURLException e) {
                    throw EeLogger.ROOT_LOGGER.cannotParseResourceRefUri(e, resourceRef.getResUrl());
                }
            }
        } else {
            if (classType == null) {
                throw EeLogger.ROOT_LOGGER.cannotDetermineType(name);
            }
            //check if it is a well known type
            final String lookup = ResourceInjectionAnnotationParsingProcessor.FIXED_LOCATIONS.get(classType.getName());
            if (lookup != null) {
                injectionSource = new LookupInjectionSource(lookup);
            } else {
                final EEResourceReferenceProcessor resourceReferenceProcessor = registry.getResourceReferenceProcessor(classType.getName());
                if (resourceReferenceProcessor != null) {
                    injectionSource = resourceReferenceProcessor.getResourceReferenceBindingSource();
                } else if (!resourceRef.getResourceRefName().startsWith("java:")) {
                    injectionSource = new LookupInjectionSource("java:jboss/resources/" + resourceRef.getResourceRefName());
                } else {
                    //if we cannot resolve it just log
                    ROOT_LOGGER.cannotResolve("resource-env-ref", name);
                    continue;
                }
            }
        }
        bindings.add(new BindingConfiguration(name, injectionSource));
    }
    return bindings;
}
Also used : ResourceReferencesMetaData(org.jboss.metadata.javaee.spec.ResourceReferencesMetaData) MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) ManagedReference(org.jboss.as.naming.ManagedReference) ImmediateManagedReference(org.jboss.as.naming.ImmediateManagedReference) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) InjectionSource(org.jboss.as.ee.component.InjectionSource) FixedInjectionSource(org.jboss.as.ee.component.FixedInjectionSource) EnvEntryInjectionSource(org.jboss.as.ee.component.EnvEntryInjectionSource) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ResourceReferenceMetaData(org.jboss.metadata.javaee.spec.ResourceReferenceMetaData) FixedInjectionSource(org.jboss.as.ee.component.FixedInjectionSource) ImmediateManagedReference(org.jboss.as.naming.ImmediateManagedReference) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource)

Example 25 with BindingConfiguration

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

the class ResourceReferenceProcessor method getResourceEnvRefEntries.

private List<BindingConfiguration> getResourceEnvRefEntries(final DeploymentUnit deploymentUnit, final DeploymentDescriptorEnvironment environment, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionTarget resourceInjectionTarget) throws DeploymentUnitProcessingException {
    List<BindingConfiguration> bindings = new ArrayList<BindingConfiguration>();
    final ResourceEnvironmentReferencesMetaData resourceEnvRefs = environment.getEnvironment().getResourceEnvironmentReferences();
    final EEResourceReferenceProcessorRegistry registry = deploymentUnit.getAttachment(Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
    if (resourceEnvRefs == null) {
        return bindings;
    }
    for (ResourceEnvironmentReferenceMetaData resourceEnvRef : resourceEnvRefs) {
        final String name;
        if (resourceEnvRef.getName().startsWith("java:")) {
            name = resourceEnvRef.getName();
        } else {
            name = environment.getDefaultContext() + resourceEnvRef.getName();
        }
        Class<?> classType = null;
        if (resourceEnvRef.getType() != null) {
            try {
                classType = classLoader.loadClass(resourceEnvRef.getType());
            } catch (ClassNotFoundException e) {
                throw EeLogger.ROOT_LOGGER.cannotLoad(e, resourceEnvRef.getType());
            }
        }
        // our injection (source) comes from the local (ENC) lookup, no matter what.
        InjectionSource injectionSource = new LookupInjectionSource(name);
        classType = processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, resourceEnvRef, classType);
        if (!isEmpty(resourceEnvRef.getLookupName())) {
            injectionSource = new LookupInjectionSource(resourceEnvRef.getLookupName(), classType != null && JAVAX_NAMING_CONTEXT.equals(classType.getName()));
        } else {
            if (classType == null) {
                throw EeLogger.ROOT_LOGGER.cannotDetermineType(name);
            }
            //check if it is a well known type
            final String lookup = ResourceInjectionAnnotationParsingProcessor.FIXED_LOCATIONS.get(classType.getName());
            if (lookup != null) {
                injectionSource = new LookupInjectionSource(lookup);
            } else {
                final EEResourceReferenceProcessor resourceReferenceProcessor = registry.getResourceReferenceProcessor(classType.getName());
                if (resourceReferenceProcessor != null) {
                    injectionSource = resourceReferenceProcessor.getResourceReferenceBindingSource();
                } else {
                    //TODO: how are we going to handle these? Previously they would have been handled by jboss-*.xml
                    if (resourceEnvRef.getResourceEnvRefName().startsWith("java:")) {
                        ROOT_LOGGER.cannotResolve("resource-env-ref", name);
                        continue;
                    } else {
                        injectionSource = new LookupInjectionSource("java:jboss/resources/" + resourceEnvRef.getResourceEnvRefName());
                    }
                }
            }
        }
        bindings.add(new BindingConfiguration(name, injectionSource));
    }
    return bindings;
}
Also used : ResourceEnvironmentReferencesMetaData(org.jboss.metadata.javaee.spec.ResourceEnvironmentReferencesMetaData) ResourceEnvironmentReferenceMetaData(org.jboss.metadata.javaee.spec.ResourceEnvironmentReferenceMetaData) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) InjectionSource(org.jboss.as.ee.component.InjectionSource) FixedInjectionSource(org.jboss.as.ee.component.FixedInjectionSource) EnvEntryInjectionSource(org.jboss.as.ee.component.EnvEntryInjectionSource) ArrayList(java.util.ArrayList) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource)

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