KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > joseki > QueryEngineHTTP


1 /*
2  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 package com.hp.hpl.jena.joseki;
7
8 import org.apache.commons.logging.* ;
9 import java.net.* ;
10
11 //import com.hp.hpl.jena.common.* ;
12
import com.hp.hpl.jena.rdf.model.* ;
13 //import com.hp.hpl.jena.rdf.model.impl.* ;
14
//import com.hp.hpl.jena.vocabulary.* ;
15

16 import com.hp.hpl.jena.rdql.* ;
17
18 /** Create an execution object for performing an RDQL query
19  * on a model over HTTP.
20  *
21  * @author Andy Seaborne
22  * @version $Id: QueryEngineHTTP.java,v 1.4 2004/04/30 14:13:13 andy_seaborne Exp $
23  */

24 public class QueryEngineHTTP implements QueryExecution
25 {
26     static final Log logger = LogFactory.getLog(QueryEngineHTTP.class.getName()) ;
27     
28     Query query ;
29     HttpQuery qHTTP ;
30     Model resultModel = null ;
31     
32     public QueryEngineHTTP(Query q, String JavaDoc urlStr)
33     {
34         query = q ;
35         String JavaDoc queryString = q.toString().replaceAll("\\s{2,}", " ") ;
36         qHTTP = new HttpQuery(urlStr, "RDQL") ;
37         qHTTP.addParam("query", queryString) ;
38     }
39
40     public QueryEngineHTTP(Query q, URL u)
41     {
42         query = q ;
43         String JavaDoc queryString = q.toString().replaceAll("\\s{2,}", " ") ;
44         qHTTP = new HttpQuery(u, "RDQL") ;
45         qHTTP.addParam("query", queryString) ;
46     }
47
48      /** Initialise a query execution. May be called before exec.
49      * If it has not be called, the query engine will initialise
50      * itself during the exec() method.
51      */

52
53     public void init()
54     {
55         return ;
56     }
57     
58     public QueryResults exec(ResultBinding rb)
59     {
60         logger.error("Initial bindings not supported") ;
61         return null ;
62     }
63     // Iterator of ResultBindings
64
public QueryResults exec()
65     {
66         try {
67             
68             resultModel = null ;
69             try {
70                 resultModel = qHTTP.exec() ;
71             } catch (HttpException httpEx)
72             {
73                 logger.debug("Error on remote invokation: "+httpEx) ;
74                 throw httpEx ;
75             }
76             
77             if ( resultModel.size() == 0 )
78                 logger.debug("Model size is zero") ;
79
80             // Execute the query locally to build result binding.
81
query.setSource(resultModel);
82             QueryExecution qexec = new QueryEngine(query);
83             return qexec.exec() ;
84         }
85         catch (RDFException rdfEx)
86         {
87             logger.debug("RDFException: "+rdfEx) ;
88             return null;
89         }
90     }
91
92     /** Stop in mid execution.
93      * No guarantee that the concrete implementation actual will stop or
94      * that it will do so immediately.
95      */

96     public void abort() { }
97     
98     /** Normal end of use of this execution */
99     public void close() { resultModel = null ; }
100     
101     /** Get the last result model */
102     public Model getResultModel() { return resultModel ; }
103
104     /** Release last result model (in case its very large). */
105     public void releaseResultModel() { resultModel = null ; }
106     
107     public HttpQuery getHttpQuery() { return qHTTP ; }
108 }
109
110 /*
111  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
112  * All rights reserved.
113  *
114  * Redistribution and use in source and binary forms, with or without
115  * modification, are permitted provided that the following conditions
116  * are met:
117  * 1. Redistributions of source code must retain the above copyright
118  * notice, this list of conditions and the following disclaimer.
119  * 2. Redistributions in binary form must reproduce the above copyright
120  * notice, this list of conditions and the following disclaimer in the
121  * documentation and/or other materials provided with the distribution.
122  * 3. The name of the author may not be used to endorse or promote products
123  * derived from this software without specific prior written permission.
124  *
125  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
126  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
127  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
128  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
129  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
130  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
131  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
132  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
133  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
134  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
135  */

136
Popular Tags