1 5 6 package org.joseki.server.processors; 7 8 import org.apache.commons.logging.* ; 9 10 import org.joseki.util.Closure ; 11 import org.joseki.vocabulary.*; 12 import org.joseki.server.*; 13 14 import com.hp.hpl.jena.rdf.model.*; 15 import com.hp.hpl.jena.rdf.model.RDFException; 16 17 import java.util.* ; 18 19 24 public class QueryProcessorSPO extends QueryProcessorCom 25 { 26 static Log logger = LogFactory.getLog(QueryProcessorSPO.class.getName()) ; 27 28 public QueryProcessorSPO() 29 { 30 super() ; 31 } 32 33 public String getInterfaceURI() { return JosekiVocab.queryOperationSPO ; } 34 35 public Model execQuery(ModelSource src, String queryString, Request request) 36 throws RDFException, QueryExecutionException 37 { 38 if (!(src instanceof ModelSourceJena)) 39 throw new QueryExecutionException( 40 ExecutionError.rcOperationNotSupported, 41 "Wrong implementation - this Fetch processor works with Jena models"); 42 Model model = ((ModelSourceJena)src).getModel() ; 43 44 String subjStr = request.getParam("s") ; 45 String predStr = request.getParam("p") ; 46 47 String objStr = request.getParam("o") ; 48 String valStr = request.getParam("v") ; 49 50 if ( objStr != null && valStr != null ) 51 throw new QueryExecutionException(ExecutionError.rcQueryExecutionFailure, 52 "Invalid request: both object URI and value specified"); 53 54 Resource subj = null ; 55 if ( subjStr != null ) 56 subj = model.createResource(subjStr) ; 57 58 Property prop = null ; 59 if ( predStr != null ) 60 prop = model.createProperty(predStr) ; 61 62 RDFNode obj = null ; 63 if ( objStr != null ) 64 obj = model.createResource(objStr) ; 65 if ( valStr != null ) 66 obj = model.createLiteral(valStr) ; 68 69 String closeOverBNodes$ = request.getParam("closure") ; 70 boolean closeOverBNodes = ( closeOverBNodes$ != null 71 && closeOverBNodes$.equalsIgnoreCase("true") ); 72 73 logger.debug("Triples("+subj+", "+prop+", "+obj+")") ; 74 75 Model resultModel = ModelFactory.createDefaultModel() ; 76 StmtIterator sIter = model.listStatements(subj, prop, obj) ; 77 78 if ( closeOverBNodes ) 79 { 80 for(; sIter.hasNext() ; ) 81 { 82 Statement stmt = sIter.nextStatement() ; 83 Closure.closure(stmt, resultModel) ; 84 } 85 } 86 else 87 resultModel.add(sIter) ; 88 89 resultModel.setNsPrefixes(model) ; 90 Map m = src.getPrefixes() ; 91 if ( m!= null ) 92 resultModel.setNsPrefixes(src.getPrefixes()) ; 93 return resultModel ; 94 } 95 96 public Model execQuery(ModelSource aModel, Model queryModel, Request request) 97 throws RDFException, QueryExecutionException 98 { 99 throw new QueryExecutionException(ExecutionError.rcOperationNotSupported, 100 "Can't access a model with \"triples\" this way") ; 101 } 102 103 104 } 105 106 132 | Popular Tags |