01: package com.jeta.forms.store.jml;
02:
03: import java.awt.Insets;
04: import java.util.ArrayList;
05: import java.util.HashMap;
06: import java.util.LinkedList;
07:
08: import com.jeta.forms.store.JETAPersistable;
09: import com.jeta.forms.store.properties.ColorHolder;
10: import com.jeta.forms.store.support.PropertyMap;
11:
12: public class JMLSerializerFactory {
13:
14: public static final String COMPONENT_ID = null;
15:
16: private HashMap m_serializers = new HashMap();
17:
18: private JMLSerializer m_persistable_serializer = new JMLObjectOutput.XMLObjectOutputSerializer();
19: private JMLSerializer m_null_serializer = new NullSerializer();
20:
21: private JMLSerializerFactory() {
22: initialize();
23: }
24:
25: public static JMLSerializerFactory getInstance() {
26: return new JMLSerializerFactory();
27: }
28:
29: private void registerSerializer(Class c, JMLSerializer serializer) {
30: m_serializers.put(c, serializer);
31: }
32:
33: private void initialize() {
34: registerSerializer(PropertyMap.class,
35: new PropertyMapSerializer());
36: registerSerializer(HashMap.class, new HashMapSerializer());
37: registerSerializer(LinkedList.class, new ListSerializer(
38: LinkedList.class));
39: registerSerializer(ArrayList.class, new ListSerializer(
40: ArrayList.class));
41: registerSerializer(Boolean.class, new PrimitiveSerializer());
42: registerSerializer(Byte.class, new PrimitiveSerializer());
43: registerSerializer(Character.class, new PrimitiveSerializer());
44: registerSerializer(Short.class, new PrimitiveSerializer());
45: registerSerializer(Integer.class, new PrimitiveSerializer());
46: registerSerializer(Long.class, new PrimitiveSerializer());
47: registerSerializer(Float.class, new PrimitiveSerializer());
48: registerSerializer(Double.class, new PrimitiveSerializer());
49: registerSerializer(String.class, new StringSerializer());
50: registerSerializer(Insets.class, new InsetsSerializer());
51: registerSerializer(ColorHolder.class,
52: new ColorHolderSerializer());
53: registerSerializer(Object[].class, new ObjectArraySerializer());
54: registerSerializer(PrimitiveHolder.class,
55: new PrimitiveSerializer());
56: }
57:
58: /**
59: *
60: * @param obj
61: * @return
62: */
63: public JMLSerializer createSerializer(Object obj) {
64: JMLSerializer result = null;
65: if (obj == null) {
66: result = m_null_serializer;
67: } else {
68: result = (JMLSerializer) m_serializers.get(obj.getClass());
69: if (result == null && obj instanceof JETAPersistable) {
70: result = m_persistable_serializer;
71: }
72: }
73:
74: if (result == null) {
75: System.out
76: .println("JMLSerializerFactory.createSerializer failed: "
77: + obj.getClass());
78: assert (false);
79: }
80:
81: return result;
82: }
83:
84: }
|