1
2
3
4
5
6
7 package org.astrogrid.dataservice.metadata;
8
9
10 /***
11 * Defines standard data types, and useful translation methods.
12 * These are a RDBMS-oriented subset of possible VOTable types.
13 *
14 * @author M Hill
15 * @author K Andrews
16 */
17
18 import java.util.Date;
19 import org.astrogrid.tableserver.out.VoTableWriter;
20
21 public class StdDataTypes {
22
23 public final static String SHORT = "short";
24 public final static String INT = "int";
25 public final static String LONG = "long";
26 public final static String FLOAT = "float";
27 public final static String DOUBLE = "double";
28 public final static String BOOLEAN = "boolean";
29 public final static String CHAR = "char";
30 public final static String STRING = "string";
31 public final static String DATE = "dateTime";
32
33 public final static String[] TYPES = new String[] {
34 BOOLEAN, STRING, FLOAT, INT, DATE
35 };
36
37 /***Returns the VO Type for the given java class type.
38 * NOTES:
39 - VOTable has an unsignedByte but no byte
40 */
41 public static String getStdType(Class javatype) {
42 if (javatype == null) {
43 throw new IllegalArgumentException("Null type given to work out VoType");
44 }
45 else if (javatype == Byte.class) { return SHORT; }
46 else if (javatype == Short.class) { return SHORT; }
47 else if (javatype == Integer.class) { return INT; }
48 else if (javatype == Long.class) { return LONG; }
49 else if (javatype == Float.class) { return FLOAT; }
50 else if (javatype == Double.class) { return DOUBLE; }
51 else if (javatype == Boolean.class) { return BOOLEAN; }
52 else if (javatype == Character.class) { return CHAR; }
53 else if (javatype == String.class) { return STRING; }
54 else if (javatype == Date.class) { return DATE; }
55 else {
56 throw new IllegalArgumentException("Don't know what VOType the java class "+javatype+" maps to");
57 }
58 }
59
60 /***Returns the java class for the given data type */
61 public static Class getJavaType(String stdtype) {
62 if (stdtype == null) {
63 throw new IllegalArgumentException("Null type given to work out JavaType");
64 }
65 else if (stdtype.equals(SHORT)) { return Short.class; }
66 else if (stdtype.equals(INT)) { return Integer.class; }
67 else if (stdtype.equals(LONG)) { return Long.class; }
68 else if (stdtype.equals(FLOAT)) { return Float.class; }
69 else if (stdtype.equals(DOUBLE)) { return Double.class; }
70 else if (stdtype.equals(BOOLEAN)) { return Boolean.class; }
71 else if (stdtype.equals(CHAR)) { return Character.class; }
72 else if (stdtype.equals(STRING)) { return String.class; }
73 else if (stdtype.equals(DATE)) { return Date.class; }
74
75 else if (stdtype.equals("date")) { return Date.class; }
76 else {
77 throw new IllegalArgumentException("Unrecognised data type " +
78 stdtype + " given to work out JavaType");
79 }
80 }
81 }
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117