View Javadoc

1   /*
2    * $Id: StdDataTypes.java,v 1.3 2006/09/26 15:34:42 clq2 Exp $
3    *
4    * (C) Copyright Astrogrid...
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";   //date as seconds since/before 1970
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        //for backwards-compatibility
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   $Log: StdDataTypes.java,v $
85   Revision 1.3  2006/09/26 15:34:42  clq2
86   SLI_KEA_1794 for slinger and PAL_KEA_1974 for pal and xml, deleted slinger jar from repo, merged with pal
87  
88   Revision 1.2.84.1  2006/08/25 16:24:41  kea
89   Pre-weekend checkin.  Work in progress on extending data type interpretation.
90   Fix for missing xerces jar in war bundle.
91  
92   Revision 1.2  2005/05/27 16:21:06  clq2
93   mchv_1
94  
95   Revision 1.1.2.1  2005/04/21 17:20:51  mch
96   Fixes to output types
97  
98   Revision 1.2  2005/03/21 18:45:55  mch
99   Naughty big lump of changes
100 
101  Revision 1.1.1.1  2005/02/17 18:37:34  mch
102  Initial checkin
103 
104  Revision 1.1.1.1  2005/02/16 17:11:24  mch
105  Initial checkin
106 
107  Revision 1.1.2.2  2005/01/24 12:14:27  mch
108  Fixes to VizieR proxy and resource stuff
109 
110  Revision 1.1.2.1  2005/01/13 18:57:31  mch
111  Fixes to metadata mostly
112 
113 
114  */
115 
116 
117