- @SuppressWarnings("unchecked")
- @Override
- public <T> T getValue(ReadGraph graph, Resource resource) throws DatabaseException {
- return (T) new FunctionImpl3<ReadGraph, Resource, Object, Object>() {
- @Override
- public Object apply(ReadGraph graph, Resource converter, Object context) {
- SCLContext sclContext = SCLContext.getCurrent();
- Object oldGraph = sclContext.get("graph");
- try {
- if (context instanceof Variable) {
- Variable variable = (Variable)context;
- try {
- Function1<Object,Object> fn = getFunction(graph, variable.getParent(graph).getRepresents(graph), variable.getRepresents(graph), variable.getPredicateResource(graph));
- sclContext.put("graph", graph);
- return fn.apply(variable);
- } catch (DatabaseException e) {
- throw new RuntimeDatabaseException(e);
- }
- } if (context instanceof Resource) {
- Resource resource = (Resource)context;
- try {
- // Here converter is the object and context is the subject
- Function1<Object,Object> fn = getFunction(graph, resource, converter, null);
- return fn.apply(resource);
- } catch (DatabaseException e) {
- throw new RuntimeDatabaseException(e);
- }
- } else {
- throw new IllegalStateException("Unknown context " + context);
+ private final FunctionImpl3<ReadGraph, Resource, Object, Object> function = new FunctionImpl3<ReadGraph, Resource, Object, Object>() {
+ @Override
+ public Object apply(ReadGraph graph, Resource converter, Object context) {
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.get("graph");
+ try {
+ if (context instanceof Variable) {
+ Variable variable = (Variable)context;
+ try {
+ Function1<Object,Object> fn = getFunction(graph, variable.getParent(graph).getRepresents(graph), variable.getRepresents(graph), variable.getPredicateResource(graph));
+ sclContext.put("graph", graph);
+ return fn.apply(variable);
+ } catch (DatabaseException e) {
+ throw new RuntimeDatabaseException(e);
+ }
+ } if (context instanceof Resource) {
+ Resource resource = (Resource)context;
+ try {
+ // Here converter is the object and context is the subject
+ Function1<Object,Object> fn = getFunction(graph, resource, converter, null);
+ return fn.apply(resource);
+ } catch (DatabaseException e) {
+ throw new RuntimeDatabaseException(e);