1
2
3
4
5
6
7 package org.astrogrid.datacenter.query;
8
9 import java.io.IOException;
10 import java.io.InputStream;
11 import javax.xml.parsers.ParserConfigurationException;
12 import org.apache.axis.encoding.Serializer;
13 import org.astrogrid.slinger.targets.TargetIndicator;
14 import org.astrogrid.util.DomHelper;
15 import org.w3c.dom.Element;
16 import org.xml.sax.SAXException;
17
18 /***
19 * Convenience routines for making a Query from an ADQL document, string or SOAP-generated model
20 * <p>
21 *
22 * @author M Hill
23 */
24
25
26 public class AdqlQueryMaker {
27
28 /*** Constructs a Query from the given ADQL (0.7.4) OM which is generated from the
29 * SkyNode (0.7.4) WSDL
30 */
31 public static Query makeQuery(net.ivoa.www.xml.ADQL.v0_7_4.SelectType adql) {
32
33
34
35 Adql074Parser maker = new Adql074Parser();
36 return maker.makeQuery(adql);
37 }
38
39
40 /*** Constructs a Query from the given ADQL DOM. */
41 public static Query makeQuery(Element adql) throws QueryException {
42
43 return AdqlXml074Parser.makeQuery(adql);
44 }
45
46 /*** Convenience routine - creates a Query (object model) from the given ADQL string.
47 */
48 public static Query makeQuery(String adql) throws QueryException, SAXException, IOException, ParserConfigurationException {
49 return makeQuery(DomHelper.newDocument(adql).getDocumentElement());
50 }
51
52 /*** Convenience routine - Constructs query from given inputstream
53 */
54 public static Query makeQuery(InputStream in) throws QueryException, IOException, SAXException, ParserConfigurationException {
55 return makeQuery(DomHelper.newDocument(in).getDocumentElement());
56 }
57
58 public static Query makeQuery(String adql, TargetIndicator target, String format) throws QueryException, SAXException, IOException, ParserConfigurationException {
59 Query query = makeQuery(adql);
60 query.getResultsDef().setTarget(target);
61 query.getResultsDef().setFormat(format);
62 return query;
63 }
64
65 /*** Constructs query from given inputstream
66 */
67 public static Query makeQuery(InputStream in, TargetIndicator target, String format) throws QueryException, IOException, SAXException, ParserConfigurationException {
68 Query query = makeQuery(in);
69 query.getResultsDef().setTarget(target);
70 query.getResultsDef().setFormat(format);
71 return query;
72 }
73
74 public static Query makeQuery(Element adql, TargetIndicator target, String format) throws QueryException {
75 Query query = makeQuery(adql);
76 query.getResultsDef().setTarget(target);
77 query.getResultsDef().setFormat(format);
78 return query;
79 }
80
81
82 }
83
84
85
86
87
88
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