1
2
3
4
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
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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124