View Javadoc

1   /*
2    * $Id: DefaultPlugin.java,v 1.2 2005/03/21 18:45:55 mch 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 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   $Log: DefaultPlugin.java,v $
57   Revision 1.2  2005/03/21 18:45:55  mch
58   Naughty big lump of changes
59  
60   Revision 1.1.1.1  2005/02/17 18:37:34  mch
61   Initial checkin
62  
63   Revision 1.1.1.1  2005/02/16 17:11:24  mch
64   Initial checkin
65  
66   Revision 1.4.2.2  2004/11/23 11:55:06  mch
67   renamved makeTarget methods
68  
69   Revision 1.4.2.1  2004/11/22 00:57:16  mch
70   New interfaces for SIAP etc and new slinger package
71  
72   Revision 1.4  2004/11/11 23:23:29  mch
73   Prepared framework for SSAP and SIAP
74  
75   Revision 1.3  2004/11/03 00:17:56  mch
76   PAL_MCH Candidate 2 merge
77  
78   Revision 1.2.6.1  2004/10/27 00:43:39  mch
79   Started adding getCount, some resource fixes, some jsps
80  
81   Revision 1.2  2004/10/18 13:11:30  mch
82   Lumpy Merge
83  
84   Revision 1.1.2.1  2004/10/15 19:59:05  mch
85   Lots of changes during trip to CDS to improve int test pass rate
86  
87  
88   */
89  
90  
91  
92