private Literal getOptionalObjectLiteral(Model model, Resource subject, URI predicate, String lang) { Set<Value> objects = GraphUtil.getObjects(model, subject, predicate); Literal result = null; for (Value nextValue : objects) { if (nextValue instanceof Literal) { final Literal literal = (Literal) nextValue; if (result == null || (lang != null && lang.equals(literal.getLanguage()))) { result = literal; } } } return result; }
/** * 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"); } }
throws GraphUtilException Set<Value> objects = getObjects(graph, subj, pred, contexts);
/** * 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"); } }
throws GraphUtilException Set<Value> objects = getObjects(graph, subj, pred, contexts);
for (Value v : GraphUtil.getObjects(model, resource, p)) { if (v instanceof Literal) { final Literal lit = (Literal) v; for (Value v : GraphUtil.getObjects(model, resource, p)) { if (v instanceof Literal) { final Literal lit = (Literal) v;
@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); } } }