/** * Utility method that casts the return value of * {@link #getOptionalObject(Graph, Resource, URI, Resource[])} to a * Resource, or throws a GraphUtilException if that value is not a Resource. * * @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, URI, Resource[])} or if * its return value is not a Resource. */ public static Resource getOptionalObjectResource(Graph graph, Resource subj, URI pred) throws GraphUtilException { Value obj = getOptionalObject(graph, subj, pred); if (obj == null || 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, URI, 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, URI, Resource[])} or if * its return value is not a URI. */ public static URI getOptionalObjectURI(Graph graph, Resource subj, URI pred) throws GraphUtilException { Value obj = getOptionalObject(graph, subj, pred); if (obj == null || obj instanceof URI) { return (URI)obj; } else { throw new GraphUtilException("Expected URI for property " + pred); } }
/** * Utility method that casts the return value of * {@link #getOptionalObject(Graph, Resource, URI, 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, URI, Resource[])} or if * its return value is not a Literal. */ public static Literal getOptionalObjectLiteral(Graph graph, Resource subj, URI 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); } }
/** * Utility method that casts the return value of * {@link #getOptionalObject(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), 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 Resource. * @deprecated since 2.8.0. Use * {@link Model#filter(Resource, IRI, Value, Resource...) } and * {@link Model#objectResource() } instead. */ @Deprecated public static Resource getOptionalObjectResource(Graph graph, Resource subj, IRI pred) throws GraphUtilException { Value obj = getOptionalObject(graph, subj, pred); if (obj == null || 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 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); } }
/** * 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); } }