I have written code that looks like this:

Property myPropertyA = ...
Property myPropertyB = ...
Property myPropertyC = ...
Model model = ...
NodeIterator iterA, iterB, iterC;
RDFNode nodeA, nodeB, nodeC;

if (                  (iterA =
model.listObjectsOfProperty(myPropertyA)).hasNext()
                && (nodeA = iterA.next()).isResource()
                && (iterB =
model.listObjectsOfProperty(nodeA.asResource(), myPropertyB)).hasNext()
                && (nodeB = iterB.next()).isResource()
                && (iterC =
model.listObjectsOfProperty(nodeB.asResource(), myPropertyC)).hasNext()
                && (nodeC = iterC.next()).isLiteral()) {
            String toReturn = nodeC.asLiteral().getString();
        }

Essentially I'm trying to get the first literal (if it exists) value for a
property path like
:Resource_1 :myPropertyA/:myPropertyB/:myPropertyC "literal"

Is there a better (but non SPARQL) way of achieving this? Maybe some method
that I overlooked?

Because although the above code pattern works, it's not easily expandable.
I would hate to see what it would look like if I were not searching for the
first value, but for all values.

Reply via email to