View Javadoc

1   /*
2    * $Id: VoTypes.java,v 1.6 2006/09/26 15:34:42 clq2 Exp $
3    *
4    * (C) Copyright Astrogrid...
5    */
6   
7   package org.astrogrid.dataservice.metadata;
8   
9   import java.util.Date;
10  
11  
12  /***
13   * Defines Data types for the Virtual Observatory, and useful translation methods.
14   * These are primarily based on the types defined for VOTables.
15   *
16   * @author M Hill
17   */
18  
19  public class VoTypes  {
20     
21     //These are the VOTable data types from the 1.1 schema;  
22     //they are all defined here, but not all are presently in use by DSA.
23     public final static String BOOLEAN        = "boolean";   
24     public final static String BIT            = "bit";             //Not used
25     public final static String UBYTE          = "unsignedByte";    //Not used
26     public final static String SHORT          = "short";
27     public final static String INT            = "int";
28     public final static String LONG           = "long";
29     public final static String CHAR           = "char";
30     public final static String UNICHAR        = "unicodeChar";     //Not used
31     public final static String DOUBLE         = "double";
32     public final static String FLOAT          = "float";
33     public final static String FLOATCOMPLEX   = "floatComplex";    //Not used
34     public final static String DOUBLECOMPLEX  = "doubleComplex";   //Not used
35     
36     public final static String[] TYPES = new String[] {
37        BOOLEAN, BIT, UBYTE, SHORT, INT, LONG, CHAR, UNICHAR, DOUBLE, FLOAT, FLOATCOMPLEX, DOUBLECOMPLEX
38     };
39     
40  
41     /***
42      * Returns a VODataService <datatype> fragment for the given java class.
43      * Patch fix - Full description needs the arraysize.
44      *
45      */
46     public static String getVoTypeXml(Class javatype) {
47        if (javatype == null) {
48           throw new IllegalArgumentException("Null type given to work out VoType");
49        }
50        else if (javatype == Byte.class)  {  
51          return "<dataType>" + SHORT     + "</dataType>"; 
52        }
53        else if (javatype == Short.class)  {  
54          return "<dataType>" + SHORT     + "</dataType>"; 
55        }
56        else if (javatype == Integer.class) {  
57          return "<dataType>" + INT + "</dataType>"; 
58        }
59        else if (javatype == Long.class)    {  
60          return "<dataType>" + LONG     + "</dataType>"; 
61        }
62        else if (javatype == Float.class)   {  
63          return "<dataType>" + FLOAT   + "</dataType>"; 
64        }
65        else if (javatype == Double.class)  {  
66          return "<dataType>" + DOUBLE   + "</dataType>"; 
67        }
68        else if (javatype == Boolean.class) {  
69          return "<dataType>" + BOOLEAN + "</dataType>"; 
70        }
71        else if (javatype == Character.class) {  
72          // Be pedantic about array size to emphasise it really is just 1 char
73          return "<dataType arraysize='1'>" + CHAR + "</dataType>"; 
74        }
75        else if (javatype == String.class)  {  
76          return "<dataType arraysize='*'>" + CHAR    + "</dataType>"; 
77        }
78        else if (javatype == Date.class)    {  
79          return "<dataType arraysize='*'>" + CHAR + "</dataType>"; 
80        }
81        else {
82           throw new IllegalArgumentException("Don't know what VOType the java class "+javatype+" maps to");
83        }
84     }
85  
86     
87     /***Returns the 'VO Type' for the given java class.  NOTE that this is not
88      * sufficient for Votable, which needs the arraysize also set for strings
89      */
90     public static String getVoType(Class javatype) {
91        if (javatype == null) {
92           throw new IllegalArgumentException("Null type given to work out VoType");
93        }
94        else if (javatype == Byte.class)  {  
95          return "datatype='"+SHORT+"'";    
96        }
97        else if (javatype == Short.class)  {  
98          return "datatype='"+SHORT+"'";    
99        }
100       else if (javatype == Integer.class) {  
101         return "datatype='"+INT+"'";     
102       }
103       else if (javatype == Long.class)    {  
104         return "datatype='"+LONG+"'";    
105       }
106       else if (javatype == Float.class)   {  
107         return "datatype='"+FLOAT+"'";   
108       }
109       else if (javatype == Double.class)  {   
110         return "datatype='"+DOUBLE+"'";  
111       }
112       else if (javatype == Boolean.class) {  
113         return "datatype='"+BOOLEAN+"'";    
114       }
115       else if (javatype == Character.class) {  
116         // Be pedantic about array size to emphasise it really is just 1 char
117         return "datatype='"+CHAR+"' arraysize='1'";    
118       }
119       else if (javatype == String.class)  {  
120         return "datatype='"+CHAR+"' arraysize='*'";    
121       }
122       else if (javatype == Date.class)    {  
123         return "datatype='"+CHAR+"' arraysize='*'";    
124       }
125       else {
126          throw new IllegalArgumentException("Don't know what VOType the java class "+javatype+" maps to");
127       }
128    }
129 
130    /***Returns the VO Type as a string of two attributes (datatype and arraysize)
131     * for the given java class type.
132     */
133    public static String getVoTableTypeAttributes(Class javatype) {
134       if (javatype == null) {
135          throw new IllegalArgumentException("Null type given to work out VoType");
136       }
137       else if (javatype == Byte.class) {  
138         return "datatype='"+SHORT+"'";     
139       }
140       else if (javatype == Short.class) {  
141         return "datatype='"+SHORT+"'";     
142       }
143       else if (javatype == Integer.class) {  
144         return "datatype='"+INT+"'";     
145       }
146       else if (javatype == Long.class)    {  
147         return "datatype='"+LONG+"'";    
148       }
149       else if (javatype == Float.class)   {  
150         return "datatype='"+FLOAT+"'";   
151       }
152       else if (javatype == Double.class) {   
153         return "datatype='"+FLOAT+"'";  
154       }
155       else if (javatype == Boolean.class) {  
156         return "datatype='"+BOOLEAN+"'";    
157       }
158       else if (javatype == Character.class) {  
159         // Be pedantic about array size to emphasise it really is just 1 char
160         return "datatype='"+CHAR+"' arraysize='1'";    
161       }
162       else if (javatype == String.class)  {  
163         return "datatype='"+CHAR+"' arraysize='*'";    
164       }
165       else if (javatype == Date.class)    {  
166         return "datatype='"+CHAR+"' arraysize='*'";    
167       }
168       else {
169          throw new IllegalArgumentException("Don't know what VOType the java class "+javatype+" maps to");
170       }
171    }
172 
173    /* THIS IS NOT CURRENTLY IN USE IN DSA.
174     * MAPPING FROM VOTable to SQL is less simple than the other direction. *
175    /* *Returns the java class for the given data type */
176    /*
177    public static Class getJavaType(String votype) {
178       if (votype == null) {
179          throw new IllegalArgumentException("Null type given to work out JavaType");
180       }
181       else if (votype.equals(LONG))    { return Long.class; }
182       else if (votype.equals(BOOLEAN)) { return Boolean.class; }
183       else if (votype.equals(BIT))     { return Boolean.class; }
184       else if (votype.equals(UBYTE))   { return Integer.class; }
185       else if (votype.equals(CHAR))    { return String.class;  }
186       else if (votype.equals(UNICHAR)) { return Long.class; }
187       else if (votype.equals(DOUBLE))  { return Double.class; }
188       else if (votype.equals(FLOAT))   { return Double.class; }
189       else if (votype.equals(INT))     { return Long.class; }
190       else if (votype.equals(SHORT))   { return String.class;  }
191 //      else if (votype.equals(DOUBLECOMPLEX)) { return Long.class; }
192 //      else if (votype.equals(FLOATCOMPLEX))   { return String.class;  }
193       else {
194          throw new IllegalArgumentException("Don't know what java type the VOType '"+votype+"' maps to");
195       }
196    }
197       */
198    
199 }
200 
201 /*
202  $Log: VoTypes.java,v $
203  Revision 1.6  2006/09/26 15:34:42  clq2
204  SLI_KEA_1794 for slinger and PAL_KEA_1974 for pal and xml, deleted slinger jar from repo, merged with pal
205 
206  Revision 1.5.24.1  2006/08/25 16:24:41  kea
207  Pre-weekend checkin.  Work in progress on extending data type interpretation.
208  Fix for missing xerces jar in war bundle.
209 
210  Revision 1.5  2006/02/09 09:54:09  clq2
211  KEA_1521_pal
212 
213  Revision 1.4.50.1  2006/01/30 14:10:50  kea
214  Fixes for bug 1479.
215 
216  Revision 1.4  2005/06/09 08:53:58  clq2
217  200506081212
218 
219  Revision 1.3.6.1  2005/06/09 01:31:57  dave
220  Fixed bugs in the metedata generator(s).
221  Note - updated Date patch may not work in other timezones.
222  Note - <resource> element may not be the right one.
223 
224  Revision 1.3  2005/05/27 16:21:05  clq2
225  mchv_1
226 
227  Revision 1.2.16.1  2005/04/21 17:20:51  mch
228  Fixes to output types
229 
230  Revision 1.2  2005/03/21 18:45:55  mch
231  Naughty big lump of changes
232 
233  Revision 1.1.1.1  2005/02/17 18:37:34  mch
234  Initial checkin
235 
236  Revision 1.1.1.1  2005/02/16 17:11:24  mch
237  Initial checkin
238 
239  Revision 1.1.2.2  2005/01/24 12:14:27  mch
240  Fixes to VizieR proxy and resource stuff
241 
242  Revision 1.1.2.1  2005/01/13 18:57:31  mch
243  Fixes to metadata mostly
244 
245 
246  */
247 
248 
249