KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > joseki > server > processors > QueryModelProcessor


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

5
6 package org.joseki.server.processors;
7
8 import org.joseki.server.* ;
9 //import org.joseki.server.module.* ;
10
import org.joseki.vocabulary.JosekiVocab;
11
12 import com.hp.hpl.jena.rdf.model.* ;
13
14 /** This class is the indirection for queries that are specified by an RDF model.
15  * Large queries, or ones being forced to go to the model (no caching)
16  * are sent by HTTP POST. This class takes that request and finds the right
17  * language processor for query. The language is part of the argument
18  * model as property "joseki:queryOperationName".
19  *
20  * @author Andy Seaborne
21  * @version $Id: QueryModelProcessor.java,v 1.6 2004/04/30 14:13:11 andy_seaborne Exp $
22  */

23 public class QueryModelProcessor implements Processor
24 {
25     public QueryModelProcessor()
26     {
27     }
28     
29     /** @see org.joseki.server.Processor#init(Resource, Resource)
30       */

31      public void init(Resource processor, Resource binding) { }
32      
33     /**
34      * @see org.joseki.server.Processor#exec(Request)
35      */

36     public Model exec(Request request) throws ExecutionException
37     {
38         ModelSource aModel = request.getModelSource();
39         QueryProcessor qProc = null ;
40         try
41         {
42             aModel.startOperation(true);
43             Model queryModel = (Model) request.getDataArgs().get(0);
44
45             try
46             {
47                 // Bug fix: old (up to 2.0) wrongly uses joseki:queryOperationName
48
NodeIterator nIter =
49                     queryModel.listObjectsOfProperty(JosekiVocab.requestQueryLanguage) ;
50                 
51                 // Not found : try again with old name.
52
if ( nIter == null || ! nIter.hasNext() )
53                         nIter = queryModel.listObjectsOfProperty(JosekiVocab.queryOperationName) ;
54
55                 for (; nIter.hasNext();)
56                 {
57                     RDFNode n = nIter.nextNode();
58                     if (n instanceof Literal)
59                     {
60                         String JavaDoc queryLangName = ((Literal) n).getString();
61                         qProc = aModel.getProcessorRegistry().findQueryProcessor(queryLangName);
62                     }
63                 }
64             }
65             catch (RDFException ex)
66             {
67                 aModel.abortOperation();
68                 throw new ExecutionException(ExecutionError.rcArgumentUnreadable,
69                                              "Failed to extract query language name") ;
70             }
71             // Re-execute
72
if ( qProc == null )
73                 throw new ExecutionException(ExecutionError.rcOperationNotSupported,
74                                              "No query language found") ;
75             return qProc.exec(request) ;
76         } finally { aModel.endOperation() ; }
77         
78         //return null;
79
}
80
81     /**
82      * @see org.joseki.server.Processor#getInterfaceURI()
83      */

84     public String JavaDoc getInterfaceURI()
85     {
86         return JosekiVocab.opQueryModel ;
87     }
88
89     /** A model is required.
90      * @see org.joseki.server.Processor#argsNeeded()
91      */

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

126
Popular Tags