+ }
+
+ private Resource getTypeFromPossibleTypeFunction(ReadGraph graph, Resource baseType,
+ Function2<Variable, Resource, Resource> fn) throws DatabaseException {
+ if (fn == null)
+ // Type function was not defined - return nothing
+ return null;
+
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.put("graph", graph);
+ try {
+ return (Resource) fn.apply(this, baseType);
+ } catch (Throwable t) {
+ if (t instanceof DatabaseException)
+ throw (DatabaseException) t;
+ throw new DatabaseException(t);
+ } finally {
+ sclContext.put("graph", oldGraph);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private Function2<Variable, Resource, Resource> getPossibleTypeFunction(ReadGraph graph) throws DatabaseException {
+ Variable custom = getPossibleProperty(graph, "typeResource");
+ return custom != null
+ ? (Function2<Variable, Resource, Resource>) custom.getPossibleValue(graph)
+ : null;
+ }