01: /*
02: $Header: /cvsroot/xorm/xorm/src/org/xorm/datastore/xml/XMLType.java,v 1.1 2002/12/10 07:18:30 wbiggs Exp $
03:
04: This file is part of XORM.
05:
06: XORM is free software; you can redistribute it and/or modify
07: it under the terms of the GNU General Public License as published by
08: the Free Software Foundation; either version 2 of the License, or
09: (at your option) any later version.
10:
11: XORM is distributed in the hope that it will be useful,
12: but WITHOUT ANY WARRANTY; without even the implied warranty of
13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: GNU General Public License for more details.
15:
16: You should have received a copy of the GNU General Public License
17: along with XORM; if not, write to the Free Software
18: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20: package org.xorm.datastore.xml;
21:
22: import java.util.Date;
23: import java.util.Hashtable;
24:
25: /**
26: * Helper class to get XML type values by name.
27: */
28: public class XMLType {
29: private XMLType() {
30: }
31:
32: private static Hashtable nameToType;
33: static {
34: nameToType = new Hashtable();
35: nameToType.put("boolean", Boolean.class);
36: nameToType.put("char", Character.class);
37: nameToType.put("date", Date.class);
38: nameToType.put("double", Double.class);
39: nameToType.put("float", Float.class);
40: nameToType.put("integer", Integer.class);
41: nameToType.put("long", Long.class);
42: nameToType.put("string", String.class);
43: }
44:
45: /**
46: * Returns the Class corresponding to the type definition.
47: * The name can be one of "boolean", "char", "date", "double", "float",
48: * "integer", "long", or "string", or may be a fully qualified Java
49: * class name, though some may not be supported.
50: */
51: public static Class forName(String name) {
52: if (name == null)
53: return null;
54: Class c = (Class) nameToType.get(name);
55: if (c == null) {
56: try {
57: c = Class.forName(name);
58: } catch (ClassNotFoundException e) {
59: // ignored; returns null
60: }
61: }
62: return c;
63: }
64: }
|