public void addEnvEntry(String name,
String type,
String text,
ClassLoader classLoader) throws NamingException, NumberFormatException {
Object value;
if (text == null) {
if ("org.apache.geronimo.kernel.Kernel".equals(type)) {
value = new KernelReference();
} else {
value = null;
}
} else if ("java.lang.String".equals(type)) {
value = text;
} else if ("java.lang.Character".equals(type)) {
value = new Character(text.charAt(0));
} else if ("java.lang.Boolean".equals(type)) {
value = Boolean.valueOf(text);
} else if ("java.lang.Byte".equals(type)) {
value = Byte.valueOf(text);
} else if ("java.lang.Short".equals(type)) {
value = Short.valueOf(text);
} else if ("java.lang.Integer".equals(type)) {
value = Integer.valueOf(text);
} else if ("java.lang.Long".equals(type)) {
value = Long.valueOf(text);
} else if ("java.lang.Float".equals(type)) {
value = Float.valueOf(text);
} else if ("java.lang.Double".equals(type)) {
value = Double.valueOf(text);
} else {
Class clazz = null;
try {
clazz = ClassLoading.loadClass(type, classLoader);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not load class for env-entry " + name + ", " + type);
}
ObjectName objectName = null;
try {
objectName = ObjectName.getInstance(text);
} catch (MalformedObjectNameException e) {
throw new IllegalArgumentException("If env-entry type is not String, Character, Byte, Short, Integer, Long, " +
"Boolean, Double, or Float, the text value must be a valid ObjectName for use in a GBeanProxy:" +
" name= " + name +
", value=" + type +
", text=" + text);
}
value = new GBeanProxyReference(objectName, clazz);
}
context.put(ENV + name, value);
}
|