1
2
3
4
5
6
7 package org.astrogrid.dataservice.queriers;
8
9
10 import java.io.IOException;
11 import java.io.StringWriter;
12 import java.security.Principal;
13 import javax.xml.parsers.ParserConfigurationException;
14 import org.apache.commons.logging.Log;
15 import org.apache.commons.logging.LogFactory;
16 import org.astrogrid.query.Query;
17 import org.astrogrid.query.returns.ReturnTable;
18 import org.astrogrid.slinger.targets.TargetMaker;
19 import org.astrogrid.xml.DomHelper;
20 import org.xml.sax.SAXException;
21
22 /***
23 * Default plugin has an aborted flag and a logger
24 */
25
26 public abstract class DefaultPlugin implements QuerierPlugin {
27
28 protected static final Log log = LogFactory.getLog(QuerierPlugin.class);
29
30 protected boolean aborted = false;
31
32 /*** Abort - if this is called, try and top the query and tidy up. */
33 public void abort() {
34 aborted = true;
35 }
36
37 /*** Used by plugins that can't do a proper count, but have to get the results
38 * and count them. Often proxy services where the proxied service doesn't provide
39 * the functionality. */
40 public long getCountFromResults(Principal user, Query query, Querier querier) throws IOException {
41 StringWriter sw = new StringWriter();
42 query.setResultsDef(new ReturnTable(TargetMaker.makeTarget(sw), ReturnTable.VOTABLE));
43 askQuery(user, query, querier);
44 try {
45 return DomHelper.newDocument(sw.toString()).getElementsByTagName("TR").getLength();
46 }
47 catch (SAXException e) {
48 throw new IOException("Proxied service returned invalid VOTable: "+e);
49 }
50 }
51
52
53
54 }
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92