View Javadoc

1   /*
2    * $Id: NvoConeSearchDelegate.java,v 1.7 2004/04/05 10:09:18 mch Exp $
3    *
4    * (C) Copyright AstroGrid...
5    */
6   
7   package org.astrogrid.datacenter.delegate.nvocone;
8   import java.io.IOException;
9   import java.io.InputStream;
10  import java.net.MalformedURLException;
11  import java.net.URL;
12  import org.astrogrid.datacenter.delegate.ConeSearcher;
13  import org.astrogrid.datacenter.delegate.DatacenterException;
14  import org.astrogrid.datacenter.query.QueryState;
15  
16  /***
17   * The National Virtual Observatory, an American effort, defined a simple
18   * cone search service:
19   * @see http://www.us-vo.org/metadata/conesearch/
20   * <p>
21   * This delegate implements this as a ConeSearch, and also accepts
22   * very simple Adql-queries that can be adapted if possible.
23   *
24   * @author M Hill
25   */
26  
27  public class NvoConeSearchDelegate implements ConeSearcher
28  {
29     protected String serverUrl = null;
30  
31     private int timeout = 0;
32     
33     public NvoConeSearchDelegate(String baseUrl)
34     {
35        this.serverUrl = baseUrl;
36     }
37     
38     /*** Sets the timeout in seconds.  Set before doing search */
39     public void setTimeout(int newTimeout) {
40        this.timeout = newTimeout;
41     }
42     
43     /***
44      * Simple cone-search http call.
45      * @param ra Right Ascension in decimal degrees, J2000
46      * @param dec Decliniation in decimal degress, J2000
47      * @param sr search radius in decimal degrees
48      * @return input stream to results, which will be a VOTable document
49      */
50     public InputStream coneSearch(double ra, double dec, double sr) throws IOException
51     {
52        String queryUrl = serverUrl;
53        
54        //add query stuff - there might already be query stuff in the base url
55        if (serverUrl.indexOf("?")>-1) {
56           queryUrl = queryUrl + "&";
57        }
58        else {
59           queryUrl = queryUrl + "?";
60        }
61        
62        queryUrl = queryUrl+"RA="+ra+"&DEC="+dec+"&SR="+sr;
63  
64        try
65        {
66           
67           URL url = new URL(queryUrl);
68           
69           //run query
70           return url.openStream();
71        }
72        catch (MalformedURLException mue)
73        {
74           throw new DatacenterException("server URL invalid: '"+queryUrl+"'",mue);
75        }
76        catch (IOException e)
77        {
78           throw new DatacenterException("Error connecting to service",e);
79        }
80     }
81     
82     
83     public String getMetadata() {
84        return "Not done yet";
85     }
86     
87     public String getStatus(String id) {
88        return ""+QueryState.UNKNOWN;
89     }
90     
91  }
92  
93  /*
94  $Log: NvoConeSearchDelegate.java,v $
95  Revision 1.7  2004/04/05 10:09:18  mch
96  Added setTimeout
97  
98  Revision 1.6  2004/03/12 20:00:11  mch
99  It05 Refactor (Client)
100 
101 Revision 1.5  2003/11/26 16:31:46  nw
102 altered transport to accept any query format.
103 moved back to axis from castor
104 
105 Revision 1.4  2003/11/18 00:34:37  mch
106 New Adql-compliant cone search
107 
108 Revision 1.3  2003/11/17 16:59:12  mch
109 ConeSearcher.coneSearch now returns stream not parsed element, throws IOException
110 
111 Revision 1.2  2003/11/17 12:32:27  mch
112 Moved QueryStatus to query pacakge
113 
114 Revision 1.1  2003/11/14 00:36:40  mch
115 Code restructure
116 
117 Revision 1.1  2003/10/06 18:55:21  mch
118 Naughtily large set of changes converting to SOAPy bean/interface-based delegates
119 
120 
121 
122 */
123 
124