Search in sources :

Example 6 with LookupInjectionSource

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

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

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

Example 9 with LookupInjectionSource

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

the class DefaultDataSourceBindingProcessor method deploy.

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (DeploymentTypeMarker.isType(EAR, deploymentUnit)) {
        return;
    }
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    if (moduleDescription == null) {
        return;
    }
    final String defaultDataSource = moduleDescription.getDefaultResourceJndiNames().getDataSource();
    if (defaultDataSource == null) {
        return;
    }
    final LookupInjectionSource injectionSource = new LookupInjectionSource(defaultDataSource);
    if (DeploymentTypeMarker.isType(WAR, deploymentUnit)) {
        moduleDescription.getBindingConfigurations().add(new BindingConfiguration(MODULE_DEFAULT_DATASOURCE_JNDI_NAME, injectionSource));
    } else {
        if (DeploymentTypeMarker.isType(APPLICATION_CLIENT, deploymentUnit)) {
            moduleDescription.getBindingConfigurations().add(new BindingConfiguration(COMP_DEFAULT_DATASOURCE_JNDI_NAME, injectionSource));
        }
        for (ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
            if (componentDescription.getNamingMode() == ComponentNamingMode.CREATE) {
                componentDescription.getBindingConfigurations().add(new BindingConfiguration(COMP_DEFAULT_DATASOURCE_JNDI_NAME, injectionSource));
            }
        }
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) LookupInjectionSource(org.jboss.as.ee.component.LookupInjectionSource) BindingConfiguration(org.jboss.as.ee.component.BindingConfiguration)

Example 10 with LookupInjectionSource

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

the class PersistenceRefProcessor method getPersistenceUnitRefs.

/**
     * Resolves persistence-unit-ref
     *
     * @param environment               The environment to resolve the elements for
     * @param classLoader               The deployment class loader
     * @param deploymentReflectionIndex The reflection index
     * @return The bindings for the environment entries
     */
private List<BindingConfiguration> getPersistenceUnitRefs(DeploymentUnit deploymentUnit, DeploymentDescriptorEnvironment environment, ClassLoader classLoader, DeploymentReflectionIndex deploymentReflectionIndex, ResourceInjectionTarget resourceInjectionTarget) throws DeploymentUnitProcessingException {
    final List<BindingConfiguration> bindingConfigurations = new ArrayList<BindingConfiguration>();
    if (environment.getEnvironment() == null) {
        return bindingConfigurations;
    }
    PersistenceUnitReferencesMetaData persistenceUnitRefs = environment.getEnvironment().getPersistenceUnitRefs();
    if (persistenceUnitRefs != null) {
        if (persistenceUnitRefs.size() > 0) {
            JPADeploymentMarker.mark(deploymentUnit);
        }
        for (PersistenceUnitReferenceMetaData puRef : persistenceUnitRefs) {
            String name = puRef.getName();
            String persistenceUnitName = puRef.getPersistenceUnitName();
            String lookup = puRef.getLookupName();
            if (!isEmpty(lookup) && !isEmpty(persistenceUnitName)) {
                throw JpaLogger.ROOT_LOGGER.cannotSpecifyBoth("<lookup-name>", lookup, "persistence-unit-name", persistenceUnitName, "<persistence-unit-ref/>", resourceInjectionTarget);
            }
            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
            processInjectionTargets(resourceInjectionTarget, injectionSource, classLoader, deploymentReflectionIndex, puRef, EntityManagerFactory.class);
            BindingConfiguration bindingConfiguration = null;
            if (!isEmpty(lookup)) {
                bindingConfiguration = new BindingConfiguration(name, new LookupInjectionSource(lookup));
            } else {
                InjectionSource puBindingSource = this.getPersistenceUnitBindingSource(deploymentUnit, persistenceUnitName);
                bindingConfiguration = new BindingConfiguration(name, puBindingSource);
            }
            bindingConfigurations.add(bindingConfiguration);
        }
    }
    return bindingConfigurations;
}
Also used : PersistenceUnitReferenceMetaData(org.jboss.metadata.javaee.spec.PersistenceUnitReferenceMetaData) PersistenceUnitReferencesMetaData(org.jboss.metadata.javaee.spec.PersistenceUnitReferencesMetaData) 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) 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)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