View Javadoc

1   /*
2    * $Id: DefaultPlugin.java,v 1.4 2006/06/15 16:50:08 clq2 Exp $
3    *
4    * (C) Copyright Astrogrid...
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 org.apache.commons.logging.Log;
14  import org.apache.commons.logging.LogFactory;
15  import org.astrogrid.query.Query;
16  import org.astrogrid.query.QueryException;
17  import org.astrogrid.query.returns.ReturnTable;
18  import org.astrogrid.slinger.targets.WriterTarget;
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, QueryException {
41        StringWriter sw = new StringWriter();
42        query.setResultsDef(new ReturnTable(new WriterTarget(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   $Log: DefaultPlugin.java,v $
57   Revision 1.4  2006/06/15 16:50:08  clq2
58   PAL_KEA_1612
59  
60   Revision 1.3.64.3  2006/04/21 12:10:37  kea
61   Renamed ReturnSimple back to ReturnTable (since it is indeed intended
62   for returning tables).
63  
64   Revision 1.3.64.2  2006/04/21 11:54:05  kea
65   Changed QueryException from a RuntimeException to an Exception.
66  
67   Revision 1.3.64.1  2006/04/20 15:08:28  kea
68   More moving sideways.
69  
70   Revision 1.3  2005/05/27 16:21:02  clq2
71   mchv_1
72  
73   Revision 1.2.16.1  2005/04/21 17:20:51  mch
74   Fixes to output types
75  
76   Revision 1.2  2005/03/21 18:45:55  mch
77   Naughty big lump of changes
78  
79   Revision 1.1.1.1  2005/02/17 18:37:34  mch
80   Initial checkin
81  
82   Revision 1.1.1.1  2005/02/16 17:11:24  mch
83   Initial checkin
84  
85   Revision 1.4.2.2  2004/11/23 11:55:06  mch
86   renamved makeTarget methods
87  
88   Revision 1.4.2.1  2004/11/22 00:57:16  mch
89   New interfaces for SIAP etc and new slinger package
90  
91   Revision 1.4  2004/11/11 23:23:29  mch
92   Prepared framework for SSAP and SIAP
93  
94   Revision 1.3  2004/11/03 00:17:56  mch
95   PAL_MCH Candidate 2 merge
96  
97   Revision 1.2.6.1  2004/10/27 00:43:39  mch
98   Started adding getCount, some resource fixes, some jsps
99  
100  Revision 1.2  2004/10/18 13:11:30  mch
101  Lumpy Merge
102 
103  Revision 1.1.2.1  2004/10/15 19:59:05  mch
104  Lots of changes during trip to CDS to improve int test pass rate
105 
106 
107  */
108 
109 
110 
111