1
2
3
4
5
6
7 package org.astrogrid.dataservice.metadata;
8
9
10 /***
11 * Defines Data types for the Virtual Observatory, and useful translation methods.
12 * These are primarily based on the types defined for VOTables.
13 * However I've fiddled a bit to simplify the set down to something useful. Complex
14 * numbers are special cases of vectors (ie arrays), so I've removed those. I've also
15 * assumed (heh heh) that Precision and data size are not part of type, and so I've
16 * removed those.
17 *
18 * @author M Hill
19 */
20
21 import java.util.Date;
22 import org.astrogrid.tableserver.out.VoTableWriter;
23
24 public class VoTypes {
25
26 public final static String FLOAT = VoTableWriter.TYPE_FLOAT;
27 public final static String INT = VoTableWriter.TYPE_INT;
28 public final static String BOOLEAN = VoTableWriter.TYPE_BOOLEAN;
29 public final static String CHAR = VoTableWriter.TYPE_CHAR;
30
31 public final static String DATE = "date";
32
33 public final static String[] TYPES = new String[] {
34 BOOLEAN, CHAR, FLOAT, INT, DATE
35 };
36
37 /***Returns the VO Type for the given java class type */
38 public static String getVoType(Class javatype) {
39 if (javatype == null) {
40 throw new IllegalArgumentException("Null type given to work out VoType");
41 }
42 else if (javatype == String.class) { return CHAR; }
43 else if (javatype == Integer.class) { return INT; }
44 else if (javatype == Long.class) { return INT; }
45 else if (javatype == Float.class) { return FLOAT; }
46 else if (javatype == Double.class) { return FLOAT; }
47 else if (javatype == Boolean.class) { return BOOLEAN; }
48 else if (javatype == Date.class) { return DATE; }
49 else {
50 throw new IllegalArgumentException("Don't know what VOType the java class "+javatype+" maps to");
51 }
52 }
53
54 /***Returns the java class for the given data type */
55 public static Class getJavaType(String votype) {
56 if (votype == null) {
57 throw new IllegalArgumentException("Null type given to work out JavaType");
58 }
59 else if (votype.equals(CHAR)) { return String.class; }
60 else if (votype.equals(INT)) { return Long.class; }
61 else if (votype.equals(FLOAT)) { return Double.class; }
62 else if (votype.equals(BOOLEAN)) { return Boolean.class; }
63 else if (votype.equals(DATE)) { return Date.class; }
64
65 else if (votype.equals(VoTableWriter.TYPE_DOUBLE)) { return Double.class; }
66 else if (votype.equals(VoTableWriter.TYPE_LONG)) { return Long.class; }
67 else {
68 throw new IllegalArgumentException("Don't know what java type the VOType '"+votype+"' maps to");
69 }
70 }
71
72 }
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95