/** * Gets the objects of the statements with the specified subject, predicate * and (optionally) contexts from the supplied graph. Calling this method is * equivalent to calling <tt>graph.match(subj, pred, null, contexts)</tt> and * adding the objects of the matching statements to a set. See * {@link Graph#match(Resource, URI, Value, Resource[])} for a description of * the parameter values. */ public static Set<Value> getObjects(Graph graph, Resource subj, URI pred, Resource... contexts) { Iterator<Value> iter = getObjectIterator(graph, subj, pred, contexts); return Iterators.addAll(iter, new LinkedHashSet<Value>()); }
/** * Gets the objects of the statements with the specified subject, predicate * and (optionally) contexts from the supplied graph. Calling this method is * equivalent to calling <tt>graph.match(subj, pred, null, contexts)</tt> and * adding the objects of the matching statements to a set. See * {@link Graph#match(Resource, IRI, Value, Resource[])} for a description of * the parameter values. * * @deprecated since 2.8.0. Use * {@link Model#filter(Resource, IRI, Value, Resource...)} and * {@link Model#objects()} instead. */ @Deprecated public static Set<Value> getObjects(Graph graph, Resource subj, IRI pred, Resource... contexts) { Iterator<Value> iter = getObjectIterator(graph, subj, pred, contexts); return Iterators.addAll(iter, new LinkedHashSet<Value>()); }
private List<String> getBindingNames(Resource resultSetNode) throws RDFHandlerException { List<String> bindingNames = new ArrayList<String>(16); Iterator<Value> varIter = GraphUtil.getObjectIterator(graph, resultSetNode, RESULTVARIABLE); while (varIter.hasNext()) { Value varName = varIter.next(); if (varName instanceof Literal) { bindingNames.add(((Literal)varName).getLabel()); } else { throw new RDFHandlerException("Value for " + RESULTVARIABLE + " is not a literal: " + varName); } } return bindingNames; }
private void reportSolution(Resource solutionNode, List<String> bindingNames) throws RDFHandlerException, GraphUtilException { MapBindingSet bindingSet = new MapBindingSet(bindingNames.size()); Iterator<Value> bindingIter = GraphUtil.getObjectIterator(graph, solutionNode, BINDING); while (bindingIter.hasNext()) { Value bindingNode = bindingIter.next(); if (bindingNode instanceof Resource) { Binding binding = getBinding((Resource)bindingNode); bindingSet.addBinding(binding); } else { throw new RDFHandlerException("Value for " + BINDING + " is not a resource: " + bindingNode); } } try { tqrHandler.handleSolution(bindingSet); } catch (TupleQueryResultHandlerException e) { throw new RDFHandlerException(e.getMessage(), e); } }
@Override public void endRDF() throws RDFHandlerException { try { Resource resultSetNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RESULTSET); List<String> bindingNames = getBindingNames(resultSetNode); tqrHandler.startQueryResult(bindingNames); Iterator<Value> solIter = GraphUtil.getObjectIterator(graph, resultSetNode, SOLUTION); while (solIter.hasNext()) { Value solutionNode = solIter.next(); if (solutionNode instanceof Resource) { reportSolution((Resource)solutionNode, bindingNames); } else { throw new RDFHandlerException("Value for " + SOLUTION + " is not a resource: " + solutionNode); } } tqrHandler.endQueryResult(); } catch (GraphUtilException e) { throw new RDFHandlerException(e.getMessage(), e); } catch (TupleQueryResultHandlerException e) { throw new RDFHandlerException(e.getMessage(), e); } }