01: package com.jeta.forms.store.jml;
02:
03: import com.jeta.forms.store.jml.dom.JMLDocument;
04: import com.jeta.forms.store.jml.dom.JMLNode;
05:
06: /**
07: * This class is used to serializer Java primitive object types to JML node.
08: *
09: * @author Jeff Tassin
10: */
11: public class PrimitiveSerializer implements JMLSerializer {
12:
13: public JMLNode serialize(JMLDocument document, Object obj)
14: throws JMLException {
15:
16: if (obj instanceof PrimitiveHolder)
17: obj = ((PrimitiveHolder) obj).getPrimitive();
18:
19: if (obj instanceof Boolean || obj instanceof Byte
20: || obj instanceof Character || obj instanceof Short
21: || obj instanceof Integer || obj instanceof Long
22: || obj instanceof Float || obj instanceof Double
23: || obj == null) {
24:
25: String className = obj.getClass().getName();
26: className = className.substring("java.lang.".length());
27: JMLNode objnode = JMLUtils.createObjectNode2(document,
28: className);
29: objnode.setAttribute("value", obj == null ? "" : obj
30: .toString());
31: return objnode;
32: }
33: throw new JMLException(
34: "PrimitiveSerializer.serialize non primitive object encountered: "
35: + obj.getClass());
36: }
37:
38: }
|