/** * Utility method that casts the return value of * {@link #getUniqueSubject(Graph, URI, Value, Resource[])} to a URI, or * throws a GraphUtilException if that value is not a URI. * * @return The subject of the matched statement(s). * @throws GraphUtilException * If such an exception is thrown by * {@link #getUniqueSubject(Graph, URI, Value, Resource[])} or if its * return value is not a URI. */ public static URI getUniqueSubjectURI(Graph graph, URI pred, Value obj, Resource... contexts) throws GraphUtilException { Resource subject = getUniqueSubject(graph, pred, obj, contexts); if (subject instanceof URI) { return (URI)subject; } else { throw new GraphUtilException("Expected URI for subject " + subject); } }
/** * Utility method that casts the return value of * {@link #getUniqueSubject(Graph, IRI, Value, Resource[])} to a URI, or * throws a GraphUtilException if that value is not a URI. * * @return The subject of the matched statement(s). * @throws GraphUtilException * If such an exception is thrown by * {@link #getUniqueSubject(Graph, IRI, Value, Resource[])} or if its * return value is not a URI. * @deprecated since 2.8.0. Use * {@link Model#filter(Resource, IRI, Value, Resource...)} and * {@link Model#subjectIRI()} instead. */ @Deprecated public static IRI getUniqueSubjectURI(Graph graph, IRI pred, Value obj, Resource... contexts) throws GraphUtilException { Resource subject = getUniqueSubject(graph, pred, obj, contexts); if (subject instanceof IRI) { return (IRI)subject; } else { throw new GraphUtilException("Expected URI for subject " + subject); } }
@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); } }
@Override public void endRDF() throws RDFHandlerException { try { Resource resultSetNode = GraphUtil.getUniqueSubject(graph, RDF.TYPE, RESULTSET); Literal booleanLit = GraphUtil.getUniqueObjectLiteral(graph, resultSetNode, BOOLEAN); if (booleanLit.equals(DAWGTestResultSetSchema.TRUE)) { value = true; } else if (booleanLit.equals(DAWGTestResultSetSchema.FALSE)) { value = false; } else { throw new RDFHandlerException("Invalid boolean value: " + booleanLit); } } catch (GraphUtilException e) { throw new RDFHandlerException(e.getMessage(), e); } } }