/** * 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); } }
/** * 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<>()); }
/** * Gets the subject of the statement(s) with the specified predicate and object from the specified * contexts in the supplied graph. If the combination of predicate, object and contexts matches one or * more statements, all these statements should have the same subject. A {@link GraphUtilException} is * thrown if this is not the case. See {@link Graph#match(Resource, IRI, Value, Resource[])} for a * description of the parameter values. * * @return The subject of the matched statement(s), or <tt>null</tt> if no matching statements were found. * @throws GraphUtilException * If the statements matched by the specified parameters have more than one unique subject. * @deprecated since 2.8.0. Use {@link Model#filter(Resource, IRI, Value, Resource...)} and * {@link Model#subjectResource()} instead. */ @Deprecated public static Resource getOptionalSubject(Graph graph, IRI pred, Value obj, Resource... contexts) throws GraphUtilException { Set<Resource> subjects = getSubjects(graph, pred, obj, contexts); if (subjects.isEmpty()) { return null; } else if (subjects.size() == 1) { return subjects.iterator().next(); } else { throw new GraphUtilException("Multiple " + pred + " properties found"); } }
private Binding getBinding(Resource bindingNode) throws GraphUtilException { Literal name = GraphUtil.getUniqueObjectLiteral(graph, bindingNode, VARIABLE); Value value = GraphUtil.getUniqueObject(graph, bindingNode, VALUE); return new SimpleBinding(name.getLabel(), value); } }
@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); } } }
@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); } }
/** * Utility method that casts the return value of * {@link #getUniqueObject(Graph, Resource, IRI, Resource[])} to a Literal, or throws a GraphUtilException * if that value is not a Literal. * * @return The object of the matched statement(s). * @throws GraphUtilException * If such an exception is thrown by {@link #getUniqueObject(Graph, Resource, IRI, Resource[])} or * if its return value is not a Literal. * @deprecated since 2.8.0. Use {@link Model#filter(Resource, IRI, Value, Resource...) } and * {@link Model#objectLiteral() } instead. */ @Deprecated public static Literal getUniqueObjectLiteral(Graph graph, Resource subj, IRI pred) throws GraphUtilException { Value obj = getUniqueObject(graph, subj, pred); if (obj instanceof Literal) { return (Literal)obj; } else { throw new GraphUtilException("Expected literal for property " + pred); } }
/** * Utility method that casts the return value of * {@link #getOptionalObject(Graph, Resource, IRI, Resource[])} to a Literal, or throws a * GraphUtilException if that value is not a Literal. * * @return The object of the matched statement(s), or <tt>null</tt> if no matching statements were found. * @throws GraphUtilException * If such an exception is thrown by {@link #getOptionalObject(Graph, Resource, IRI, Resource[])} * or if its return value is not a Literal. * @deprecated since 2.8.0. Use {@link Model#filter(Resource, IRI, Value, Resource...) } and * {@link Model#objectLiteral() } instead. */ @Deprecated public static Literal getOptionalObjectLiteral(Graph graph, Resource subj, IRI pred) throws GraphUtilException { Value obj = getOptionalObject(graph, subj, pred); if (obj == null || obj instanceof Literal) { return (Literal)obj; } else { throw new GraphUtilException("Expected literal for property " + pred); } }
@Override public void parse(Model graph, Resource implNode) throws RepositoryConfigException { super.parse(graph, implNode); try { IRI uri = GraphUtil.getOptionalObjectURI(graph, implNode, SERVERURL); if (uri != null) { setServerUrl(uri.toString()); } Literal username = GraphUtil.getOptionalObjectLiteral(graph, implNode, USERNAME); if (username != null) { setUsername(username.getLabel()); } Literal password = GraphUtil.getOptionalObjectLiteral(graph, implNode, PASSWORD); if (password != null) { setPassword(password.getLabel()); } Literal catalogId = GraphUtil.getOptionalObjectLiteral(graph, implNode, CATALOGID); if (catalogId != null) { setCatalogId(catalogId.getLabel()); } Literal repositoryId = GraphUtil.getOptionalObjectLiteral(graph, implNode, REPOSITORYID); if (repositoryId != null) { setRepositoryId(repositoryId.getLabel()); } } catch (GraphUtilException e) { throw new RepositoryConfigException(e.getMessage(), e); } }
/** * Gets the object of the statement(s) with the specified subject and predicate from the specified * contexts in the supplied graph. If the combination of subject, predicate and contexts matches one or * more statements, all these statements should have the same object. A {@link GraphUtilException} is * thrown if this is not the case. See {@link Graph#match(Resource, IRI, Value, Resource[])} for a * description of the parameter values. * * @return The object of the matched statement(s), or <tt>null</tt> if no matching statements were found. * @throws GraphUtilException * If the statements matched by the specified parameters have more than one unique object. * @deprecated since 2.8.0. Use {@link Model#filter(Resource, IRI, Value, Resource...) } and * {@link Model#objectValue() } instead. */ @Deprecated public static Value getOptionalObject(Graph graph, Resource subj, IRI pred, Resource... contexts) throws GraphUtilException { Set<Value> objects = getObjects(graph, subj, pred, contexts); if (objects.isEmpty()) { return null; } else if (objects.size() == 1) { return objects.iterator().next(); } else { throw new GraphUtilException("Multiple " + pred + " properties found"); } }
/** * Gets the subject of the statements with the specified predicate, object and (optionally) contexts from * the supplied graph. Calling this method is equivalent to calling * <tt>graph.match(null, pred, obj, contexts)</tt> and adding the subjects 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#subjects()} instead. */ @Deprecated public static Set<Resource> getSubjects(Graph graph, IRI pred, Value obj, Resource... contexts) { Iterator<Resource> iter = getSubjectIterator(graph, pred, obj, contexts); return Iterators.addAll(iter, new LinkedHashSet<>()); }
/** * Utility method that casts the return value of * {@link #getOptionalSubject(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), or <tt>null</tt> if no matching statements were found. * @throws GraphUtilException * If such an exception is thrown by {@link #getOptionalSubject(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 getOptionalSubjectURI(Graph graph, IRI pred, Value obj, Resource... contexts) throws GraphUtilException { Resource subject = getOptionalSubject(graph, pred, obj, contexts); if (subject == null || subject instanceof IRI) { return (IRI)subject; } else { throw new GraphUtilException("Expected URI for subject " + subject); } }
final Literal userLit = GraphUtil.getOptionalObjectLiteral(model, implNode, USER); if (userLit != null) { setUser(userLit.getLabel()); final Literal pwdLit = GraphUtil.getOptionalObjectLiteral(model, implNode, PASSWORD); if (pwdLit != null) { setPassword(pwdLit.getLabel()); final Literal instLit = GraphUtil.getOptionalObjectLiteral(model, implNode, INSTANCE); if (instLit != null) { setInstance(instLit.getLabel()); final Literal zooLit = GraphUtil.getOptionalObjectLiteral(model, implNode, ZOOKEEPERS); if (zooLit != null) { setZookeepers(zooLit.getLabel()); final Literal mockLit = GraphUtil.getOptionalObjectLiteral(model, implNode, IS_MOCK); if (mockLit != null) { setMock(Boolean.parseBoolean(mockLit.getLabel()));
@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); } } }
@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); } }
private Binding getBinding(Resource bindingNode) throws GraphUtilException { Literal name = GraphUtil.getUniqueObjectLiteral(graph, bindingNode, VARIABLE); Value value = GraphUtil.getUniqueObject(graph, bindingNode, VALUE); return new SimpleBinding(name.getLabel(), value); } }
/** * Utility method that casts the return value of * {@link #getUniqueObject(Graph, Resource, IRI, Resource[])} to a Resource, or throws a * GraphUtilException if that value is not a Resource. * * @return The object of the matched statement(s). * @throws GraphUtilException * If such an exception is thrown by {@link #getUniqueObject(Graph, Resource, IRI, Resource[])} or * if its return value is not a Resource. * @deprecated since 2.8.0. Use {@link Model#filter(Resource, IRI, Value, Resource...) } and * {@link Model#objectResource() } instead. */ @Deprecated public static Resource getUniqueObjectResource(Graph graph, Resource subj, IRI pred) throws GraphUtilException { Value obj = getUniqueObject(graph, subj, pred); if (obj instanceof Resource) { return (Resource)obj; } else { throw new GraphUtilException("Expected URI or blank node for property " + pred); } }
/** * Utility method that casts the return value of * {@link #getOptionalObject(Graph, Resource, IRI, Resource[])} to a URI, or throws a GraphUtilException * if that value is not a URI. * * @return The object of the matched statement(s), or <tt>null</tt> if no matching statements were found. * @throws GraphUtilException * If such an exception is thrown by {@link #getOptionalObject(Graph, Resource, IRI, 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#objectIRI() } instead. */ @Deprecated public static IRI getOptionalObjectURI(Graph graph, Resource subj, IRI pred) throws GraphUtilException { Value obj = getOptionalObject(graph, subj, pred); if (obj == null || obj instanceof IRI) { return (IRI)obj; } else { throw new GraphUtilException("Expected URI for property " + pred); } }
/** * Gets the object of the statement(s) with the specified subject and predicate from the specified * contexts in the supplied graph. If the combination of subject, predicate and contexts matches one or * more statements, all these statements should have the same object. A {@link GraphUtilException} is * thrown if this is not the case. See {@link Graph#match(Resource, IRI, Value, Resource[])} for a * description of the parameter values. * * @return The object of the matched statement(s), or <tt>null</tt> if no matching statements were found. * @throws GraphUtilException * If the statements matched by the specified parameters have more than one unique object. * @deprecated since 2.8.0. Use {@link Model#filter(Resource, IRI, Value, Resource...) } and * {@link Model#objectValue() } instead. */ @Deprecated public static Value getOptionalObject(Graph graph, Resource subj, IRI pred, Resource... contexts) throws GraphUtilException { Set<Value> objects = getObjects(graph, subj, pred, contexts); if (objects.isEmpty()) { return null; } else if (objects.size() == 1) { return objects.iterator().next(); } else { throw new GraphUtilException("Multiple " + pred + " properties found"); } }
/** * Gets the subject of the statements with the specified predicate, object and (optionally) contexts from * the supplied graph. Calling this method is equivalent to calling * <tt>graph.match(null, pred, obj, contexts)</tt> and adding the subjects 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#subjects()} instead. */ @Deprecated public static Set<Resource> getSubjects(Graph graph, IRI pred, Value obj, Resource... contexts) { Iterator<Resource> iter = getSubjectIterator(graph, pred, obj, contexts); return Iterators.addAll(iter, new LinkedHashSet<Resource>()); }