01: package com.jeta.forms.store.xml.parser;
02:
03: import com.jeta.forms.store.jml.dom.JMLAttributes;
04:
05: public class PrimitiveHandler extends ObjectHandler {
06:
07: protected Object instantiateObject(JMLAttributes attribs)
08: throws InstantiationException, IllegalAccessException,
09: ClassNotFoundException {
10: String className = attribs.getValue("classname");
11: String value = attribs.getValue("value");
12:
13: if ("Boolean".equalsIgnoreCase(className)
14: || ("java.lang.Boolean").equalsIgnoreCase(className)) {
15: return Boolean.valueOf(value);
16: } else if ("Byte".equalsIgnoreCase(className)
17: || ("java.lang.Byte").equalsIgnoreCase(className)) {
18: return Byte.valueOf(value);
19: } else if ("Character".equalsIgnoreCase(className)
20: || ("java.lang.Character").equalsIgnoreCase(className)) {
21: return new Character(value.charAt(0));
22: } else if ("Short".equalsIgnoreCase(className)
23: || ("java.lang.Short").equalsIgnoreCase(className)) {
24: return Short.valueOf(value);
25: } else if ("Integer".equalsIgnoreCase(className)
26: || ("java.lang.Integer").equalsIgnoreCase(className)) {
27: return Integer.valueOf(value);
28: } else if ("Long".equalsIgnoreCase(className)
29: || ("java.lang.Long").equalsIgnoreCase(className)) {
30: return Long.valueOf(value);
31: } else if ("Float".equalsIgnoreCase(className)
32: || ("java.lang.Float").equalsIgnoreCase(className)) {
33: return Float.valueOf(value);
34: } else if ("Double".equalsIgnoreCase(className)
35: || ("java.lang.Double").equalsIgnoreCase(className)) {
36: return Double.valueOf(value);
37: } else {
38: throw new InstantiationException(
39: "PrimitiveHandler found invalid classname: "
40: + className);
41: }
42: }
43:
44: }
|