Search in sources :

Example 1 with EnvironmentEntryMetaData

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

Aggregations

ArrayList (java.util.ArrayList)1 BindingConfiguration (org.jboss.as.ee.component.BindingConfiguration)1 EnvEntryInjectionSource (org.jboss.as.ee.component.EnvEntryInjectionSource)1 LookupInjectionSource (org.jboss.as.ee.component.LookupInjectionSource)1 EnvironmentEntriesMetaData (org.jboss.metadata.javaee.spec.EnvironmentEntriesMetaData)1 EnvironmentEntryMetaData (org.jboss.metadata.javaee.spec.EnvironmentEntryMetaData)1