View Javadoc

1   /*
2      CdsUnitDictionary.java
3   
4      Date      Author      Changes
5      $date$    M Hill      Created
6   
7      (c) Copyright...
8   */
9   
10  package org.astrogrid.common.units;
11  
12  import java.net.URL;
13  
14  /***
15   * CdsUnitDictionary...
16   *
17   * An implementation of a Unit dictionary based on a web page provided by
18   * CDS (Centre de Donn?es Astronomiques de Strasbourg) at
19   * http://vizier.u-strasbg.fr/doc/catstd-3.2.htx
20   *
21   * @version %I%
22   * @author M Hill
23   */
24     
25  public class CdsUnitDictionary implements UnitDictionary
26  {
27     private static final String cdsPage = "http://vizier.u-strasbg.fr/doc/catstd-3.2.htx";
28  
29     private static final UnitDictionary INSTANCE = new CdsUnitDictionary();
30  
31     /*** Private so that no external objects can create it, and so ensure that
32      * it is a singleton
33      */
34     private CdsUnitDictionary()
35     {
36        super();
37     }
38     
39     /*** @see UnitDictionary.isUnitValid */
40     public boolean isUnitValid(String unit)
41     {
42        // Not yet implemented
43        return true;
44     }
45     
46     /*** @see UnitDictionary.assertUnitValid */
47     public void assertUnitValid(String unit) throws IllegalUnitException
48     {
49        if (!isUnitValid(unit))
50           throw new IllegalUnitException(unit, "Unit not found at CDS website '"+cdsPage+"'");
51     }
52  
53     //See interface for javadoc
54     public String getUnitDescription(String unit) throws IllegalUnitException
55     {
56        //not yet implemented
57        return "<Unknown desc>";
58     }
59     
60     public String convertValue(String value, String units, String targetUnits) throws IllegalUnitException
61     {
62        assertUnitValid(units);
63        assertUnitValid(targetUnits);
64        
65        //do we have some convertion algorithm?
66        
67        //throwing an exception is probably not the right way to do this, as
68        //this circumstance is likely to be quite common. Return null instead?
69        return null;
70        //or throw new UnsupportedOperationException("No convertion algorithm from "+units+" to "+targetUnits);
71     }
72     
73     public static UnitDictionary getInstance()
74     {
75        return INSTANCE;
76     }
77        
78  }
79