01: package net.sourceforge.jaxor.impl;
02:
03: import net.sourceforge.jaxor.api.Mapper;
04: import net.sourceforge.jaxor.api.MapperRegistry;
05: import net.sourceforge.jaxor.mappers.*;
06:
07: import java.util.HashMap;
08: import java.util.Map;
09:
10: /*
11: * User: Mike
12: * Date: Aug 25, 2003
13: * Time: 8:07:47 PM
14: */
15:
16: public class MapperRegistryImpl implements MapperRegistry {
17:
18: private final Map _registry = new HashMap();
19:
20: public MapperRegistryImpl() {
21: Mapper mapper = new StringMapper();
22: register("String", mapper);
23: register(String.class, mapper);
24:
25: mapper = new IntegerMapper();
26: register("int", mapper);
27: register("Integer", mapper);
28: register(Integer.class, mapper);
29:
30: mapper = new LongMapper();
31: register("long", mapper);
32: register("Long", mapper);
33: register(Long.class, mapper);
34:
35: register("java.sql.Timestamp", new TimestampMapper());
36: register("java.sql.Date", new DateMapper());
37:
38: mapper = new BooleanMapper();
39: register("boolean", mapper);
40: register("Boolean", mapper);
41: register(java.lang.Boolean.class, mapper);
42:
43: mapper = new ByteMapper();
44: register("byte", mapper);
45: register(Byte.class, mapper);
46:
47: mapper = new ShortMapper();
48: register("short", mapper);
49: register(Short.class, mapper);
50:
51: mapper = new FloatMapper();
52: register("float", mapper);
53: register(Float.class, mapper);
54:
55: mapper = new DoubleMapper();
56: register("double", mapper);
57: register(Double.class, mapper);
58:
59: mapper = new BigDecimalMapper();
60: register(java.math.BigDecimal.class, mapper);
61: }
62:
63: public void register(Class clazz, Mapper mapper) {
64: register(clazz.getName(), mapper);
65: }
66:
67: public void register(String clazz, Mapper mapper) {
68: _registry.put(clazz, mapper);
69: }
70:
71: public Mapper get(Class clazz) {
72: return get(clazz.getName());
73: }
74:
75: public String getName(String type) {
76: Mapper mapper = get(type);
77: if (mapper == null)
78: return null;
79: return mapper.getClass().getName();
80: }
81:
82: public Mapper get(String type) {
83: return (Mapper) _registry.get(type);
84: }
85:
86: public Mapper getForObject(Object value) {
87: return get(value.getClass());
88: }
89: }
|