View Javadoc

1   /*
2    * $Id: VoTypes.java,v 1.2 2005/03/21 18:45:55 mch Exp $
3    *
4    * (C) Copyright Astrogrid...
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  //   public final static String DATE_CHAR = "date.string"; //date as a string
31     public final static String DATE      = "date";   //date as seconds since/before 1970
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        //for older resources (based on VOTable types)
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   $Log: VoTypes.java,v $
76   Revision 1.2  2005/03/21 18:45:55  mch
77   Naughty big lump of changes
78  
79   Revision 1.1.1.1  2005/02/17 18:37:34  mch
80   Initial checkin
81  
82   Revision 1.1.1.1  2005/02/16 17:11:24  mch
83   Initial checkin
84  
85   Revision 1.1.2.2  2005/01/24 12:14:27  mch
86   Fixes to VizieR proxy and resource stuff
87  
88   Revision 1.1.2.1  2005/01/13 18:57:31  mch
89   Fixes to metadata mostly
90  
91  
92   */
93  
94  
95