/** * Gets the subject of the statement(s) with the specified predicate and * object from the specified contexts in the supplied graph. The combination * of predicate, object and contexts must match at least one statement. In * case more than one statement matches -- for example statements from * multiple contexts -- all these statements should have the same subject. A * {@link GraphUtilException} is thrown if these conditions are not met. See * {@link Graph#match(Resource, URI, Value, Resource[])} for a description of * the parameter values. * * @return The subject of the matched statement(s). * @throws GraphUtilException * If the statements matched by the specified parameters do not have * exactly one unique subject. */ public static Resource getUniqueSubject(Graph graph, URI pred, Value obj, Resource... contexts) throws GraphUtilException { Set<Resource> subjects = getSubjects(graph, pred, obj, contexts); if (subjects.size() == 1) { return subjects.iterator().next(); } else if (subjects.isEmpty()) { throw new GraphUtilException("Missing property: " + pred); } else { throw new GraphUtilException("Multiple " + pred + " properties found"); } }
@Override public void parse(Graph graph, Resource implNode) throws RepositoryConfigException { super.parse(graph, implNode); try { URI uri = GraphUtil.getOptionalObjectURI(graph, implNode, ENDPOINT); if (uri != null) { setURL(uri.stringValue()); } Set<Value> set = GraphUtil.getObjects(graph, implNode, SUBJECT_SPACE); subjects.clear(); for (Value space : set) { subjects.add(space.stringValue()); } } catch (GraphUtilException e) { throw new RepositoryConfigException(e.getMessage(), e); } } }
@Override public void parse(Graph graph, Resource subj) throws RepositoryConfigException { super.parse(graph, subj); try { Literal lit = GraphUtil.getOptionalObjectLiteral(graph, subj, SNAPSHOT); if (lit != null) { setSnapshot(lit.booleanValue()); } lit = GraphUtil.getOptionalObjectLiteral(graph, subj, SERIALIZABLE); if (lit != null) { setSerializable(lit.booleanValue()); } } catch (GraphUtilException e) { throw new RepositoryConfigException(e.toString(), e); } }
nextRecord.stringValue(), re.getMessage());
@Override public void parse(Graph graph, Resource implNode) throws SailConfigException { super.parse(graph, implNode); try { Literal propertiesLit = GraphUtil.getOptionalObjectLiteral( graph, implNode, BigdataConfigSchema.PROPERTIES); if (propertiesLit != null) { setPropertiesFile((propertiesLit).getLabel()); } else { throw new SailConfigException("Properties file required"); } } catch (GraphUtilException e) { throw new SailConfigException(e.getMessage(), e); } } }
/** * 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); } }
@Override public void parse(Graph graph, Resource implNode) throws RepositoryConfigException { super.parse(graph, implNode); try { Literal propertiesLit = GraphUtil.getOptionalObjectLiteral( graph, implNode, BigdataConfigSchema.PROPERTIES); if (propertiesLit != null) { setPropertiesFile((propertiesLit).getLabel()); } else { throw new RepositoryConfigException("Properties file required"); } } 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. The * combination of subject, predicate and contexts must match at least one * statement. In case more than one statement matches -- for example * statements from multiple contexts -- all these statements should have the * same object. A {@link GraphUtilException} is thrown if these conditions * are not met. See {@link Graph#match(Resource, URI, Value, Resource[])} for * a description of the parameter values. * * @return The object of the matched statement(s). * @throws GraphUtilException * If the statements matched by the specified parameters do not have * exactly one unique object. */ public static Value getUniqueObject(Graph graph, Resource subj, URI pred, Resource... contexts) throws GraphUtilException { Set<Value> objects = getObjects(graph, subj, pred, contexts); if (objects.size() == 1) { return objects.iterator().next(); } else if (objects.isEmpty()) { throw new GraphUtilException("Missing property: " + pred); } else { throw new GraphUtilException("Multiple " + pred + " properties found"); } }
@Override public void parse(Graph graph, Resource implNode) throws SailConfigException { super.parse(graph, implNode); try { Literal propertiesLit = GraphUtil.getOptionalObjectLiteral( graph, implNode, BigdataConfigSchema.PROPERTIES); if (propertiesLit != null) { setPropertiesFile((propertiesLit).getLabel()); } else { throw new SailConfigException("Properties file required"); } } catch (GraphUtilException e) { throw new SailConfigException(e.getMessage(), e); } } }
/** * Utility method that casts the return value of * {@link #getUniqueObject(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). * @throws GraphUtilException * If such an exception is thrown by * {@link #getUniqueObject(Graph, Resource, URI, Resource[])} or if * its return value is not a Literal. */ public static Literal getUniqueObjectLiteral(Graph graph, Resource subj, URI 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); } }
@Override public void parse(Graph graph, Resource implNode) throws RepositoryConfigException { super.parse(graph, implNode); try { Literal propertiesLit = GraphUtil.getOptionalObjectLiteral( graph, implNode, BigdataConfigSchema.PROPERTIES); if (propertiesLit != null) { setPropertiesFile((propertiesLit).getLabel()); } else { throw new RepositoryConfigException("Properties file required"); } } catch (GraphUtilException e) { throw new RepositoryConfigException(e.getMessage(), e); } } }
/** * Utility method that casts the return value of * {@link #getOptionalSubject(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), or <tt>null</tt> if no * matching statements were found. * @throws GraphUtilException * If such an exception is thrown by * {@link #getOptionalSubject(Graph, URI, Value, Resource[])} or if * its return value is not a URI. */ public static URI getOptionalSubjectURI(Graph graph, URI pred, Value obj, Resource... contexts) throws GraphUtilException { Resource subject = getOptionalSubject(graph, pred, obj, contexts); if (subject instanceof URI) { return (URI)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); } }
throw new GraphUtilException("Missing property: " + pred); throw new GraphUtilException("Multiple " + pred + " properties found");
@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); } } }
/** * Utility method that casts the return value of * {@link #getUniqueObject(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). * @throws GraphUtilException * If such an exception is thrown by * {@link #getUniqueObject(Graph, Resource, URI, Resource[])} or if * its return value is not a Resource. */ public static Resource getUniqueObjectResource(Graph graph, Resource subj, URI 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); } }
throw new SailConfigException(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, URI, 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. */ public static Value getOptionalObject(Graph graph, Resource subj, URI 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"); } }
throw new SailConfigException(e.getMessage(), e);
throw new GraphUtilException("Missing property: " + pred); throw new GraphUtilException("Multiple " + pred + " properties found");