Resource result = null;
Cursor<? extends Statement> statements = super.getStatements(subject, predicate, null, true, contexts);
try {
Statement st;
while ((st = statements.next()) != null) {
if (st.getObject() instanceof Resource) {
result = (Resource)st.getObject();
break;
}
}
}
finally {
statements.close();
}
// see if we should try and find a value from the supplied resource's
// parent.
if (result == null && inherit) {
visited.add(subject);
URI inheritanceProperty = getInheritanceProperty();
if (inheritanceProperty != null) {
Cursor<? extends Statement> parentStatements = super.getStatements(subject, inheritanceProperty,
null, true);
try {
Statement parentStatement;
while ((parentStatement = parentStatements.next()) != null) {
Value value = parentStatement.getObject();
if (value instanceof Resource) {
result = getPropertyResourceValue((Resource)value, predicate, false, visited, contexts);
if (result != null) {
break;
}