Search in sources :

Example 6 with IncorrectPropertyCountException

use of won.protocol.exception.IncorrectPropertyCountException in project webofneeds by researchstudio-sat.

the class RdfUtils method findOnePropertyFromResource.

public static RDFNode findOnePropertyFromResource(final Model model, final Resource resource, final Property property) {
    List<RDFNode> foundNodes = new ArrayList<RDFNode>();
    NodeIterator iterator = model.listObjectsOfProperty(resource, property);
    while (iterator.hasNext()) {
        foundNodes.add(iterator.next());
    }
    if (foundNodes.size() == 0)
        return null;
    else if (foundNodes.size() == 1)
        return foundNodes.get(0);
    else if (foundNodes.size() > 1) {
        RDFNode n = foundNodes.get(0);
        for (RDFNode node : foundNodes) {
            if (!node.equals(n))
                throw new IncorrectPropertyCountException(1, 2);
        }
        return n;
    } else
        return null;
}
Also used : IncorrectPropertyCountException(won.protocol.exception.IncorrectPropertyCountException)

Aggregations

IncorrectPropertyCountException (won.protocol.exception.IncorrectPropertyCountException)6 NodeIterator (org.apache.jena.rdf.model.NodeIterator)2 OutputStream (java.io.OutputStream)1 Node (org.apache.jena.graph.Node)1 Model (org.apache.jena.rdf.model.Model)1 Path (org.apache.jena.sparql.path.Path)1 DefaultNeedModelWrapper (won.protocol.util.DefaultNeedModelWrapper)1 RdfUtils (won.protocol.util.RdfUtils)1