Search in sources :

Example 1 with ResourceEnvironmentReferencesMetaData

use of org.jboss.metadata.javaee.spec.ResourceEnvironmentReferencesMetaData 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

ArrayList (java.util.ArrayList)1 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)1 EnvEntryInjectionSource (org.jboss.as.ee.component.EnvEntryInjectionSource)1 FixedInjectionSource (org.jboss.as.ee.component.FixedInjectionSource)1 InjectionSource (org.jboss.as.ee.component.InjectionSource)1 LookupInjectionSource (org.jboss.as.ee.component.LookupInjectionSource)1 ResourceEnvironmentReferenceMetaData (org.jboss.metadata.javaee.spec.ResourceEnvironmentReferenceMetaData)1 ResourceEnvironmentReferencesMetaData (org.jboss.metadata.javaee.spec.ResourceEnvironmentReferencesMetaData)1