Bundle bundle = module.getEarContext().getDeploymentBundle();
XmlObject[] gerEnvEntryUntyped = plan == null ? NO_REFS : plan.selectChildren(GER_ENV_ENTRY_QNAME_SET);
Map<String, String> envEntryMap = mapEnvEntries(gerEnvEntryUntyped);
for (Map.Entry<String, EnvEntry> entry : specDD.getEnvEntryMap().entrySet()) {
String name = entry.getKey();
EnvEntry envEntry = entry.getValue();
if (lookupJndiContextMap(module, name) != null) {
// some other builder handled this entry already
addInjections(normalize(name), ReferenceType.ENV_ENTRY, envEntry.getInjectionTarget(), NamingBuilder.INJECTION_KEY.get(sharedContext));
continue;
}
String type = getStringValue(envEntry.getEnvEntryType());
Object value = null;
String strValueOverride = envEntryMap.remove(name);
String strValue = null;
if (strValueOverride == null) {
strValue = envEntry.getEnvEntryValue();
String lookupName = getStringValue(envEntry.getLookupName());
if (strValue != null && lookupName != null) {
throw new DeploymentException("You must specify an environment entry value or lookup name but not both. Component: " + module.toString() + ", name: " + name + ", env-entry-value: " + strValue + ", lookup-name: " + lookupName + "");
}
if (lookupName != null) {
//TODO better circular reference checking
if (lookupName.equals(getJndiName(name))) {
throw new DeploymentException("env-entry lookup name refers to itself");
}
value = new JndiReference(lookupName);
}
} else {
strValue = strValueOverride;
}
type = inferAndCheckType(module, bundle, envEntry.getInjectionTarget(), name, type);
if (value == null) {
if (strValue == null) {
if ("org.apache.geronimo.kernel.Kernel".equals(type)) {
value = new KernelReference();
}
} else {
Class<?> typeClass;
try {
typeClass = bundle.loadClass(type);
} catch (ClassNotFoundException e) {
throw new DeploymentException("Could not env-entry type class " + type, e);
}
try {
if (String.class.equals(typeClass)) {
value = strValue;
} else if (Character.class.equals(typeClass)) {
if (strValue.length() == 1) {
value = strValue.charAt(0);
} else {
log.warn("invalid character value: {} for name {}", strValue, name);
value = ' ';
}
} else if (Boolean.class.equals(typeClass)) {
value = Boolean.valueOf(strValue);
} else if (Byte.class.equals(typeClass)) {
value = Byte.valueOf(strValue);
} else if (Short.class.equals(typeClass)) {
value = Short.valueOf(strValue);
} else if (Integer.class.equals(typeClass)) {
value = Integer.valueOf(strValue);
} else if (Long.class.equals(typeClass)) {
value = Long.valueOf(strValue);
} else if (Float.class.equals(typeClass)) {
value = Float.valueOf(strValue);
} else if (Double.class.equals(typeClass)) {
value = Double.valueOf(strValue);
} else if (Class.class.equals(typeClass)) {
value = new ClassReference(strValue);
} else if (typeClass.isEnum()) {
value = Enum.valueOf(typeClass.asSubclass(Enum.class), strValue);
} else {
throw new DeploymentException("Unrecognized env-entry type: " + type);
}
} catch (NumberFormatException e) {
throw new DeploymentException("Invalid env-entry value for name: " + name, e);
}
}
}
// perform resource injection only if there is a value specified
// see Java EE 5 spec, section EE.5.4.1.3
if (value != null) {
put(name, value, ReferenceType.ENV_ENTRY, module.getJndiContext(), envEntry.getInjectionTarget(), sharedContext);
} else if(isSharableJndiNamespace(name)) {
//Even the value is configured, while it is belong to those shareable namespace, it is still to be added to the injection list
addInjections(normalize(name), ReferenceType.ENV_ENTRY, envEntry.getInjectionTarget(), NamingBuilder.INJECTION_KEY.get(sharedContext));
}
}
if (!envEntryMap.isEmpty()) {
throw new DeploymentException("Unknown env-entry elements in geronimo plan: " + envEntryMap);