import org.simantics.db.layer0.variable.RVI.StringRVIPart;
import org.simantics.db.layer0.variable.Variables.Role;
import org.simantics.layer0.Layer0;
+import org.simantics.scl.runtime.SCLContext;
+import org.simantics.scl.runtime.function.Function2;
/**
* Abstract implementation of Variable -interface.
return graph.getPossibleRelatedValue2(represents, graph.getService(Layer0.class).HasLabel, getParent(graph), Bindings.STRING);
}
- public Resource getType(ReadGraph graph) throws DatabaseException {
-
- Resource resource = getPossibleRepresents(graph);
- if(resource == null) {
- String uri = getPossiblePropertyValue(graph, "typeURI");
- if(uri != null) return graph.syncRequest(new org.simantics.db.common.primitiverequest.Resource(uri), TransientCacheAsyncListener.<Resource>instance());
- throw new DatabaseException("No type for " + getURI(graph));
- }
- return graph.getSingleType(resource);
-
- }
-
public RVIPart getRVIPart(ReadGraph graph) throws DatabaseException {
throw new UnsupportedOperationException();
}
}
}
+ public Resource getType(ReadGraph graph) throws DatabaseException {
+
+ Variable custom = getPossibleProperty(graph, "typeResource");
+ if(custom != null) {
+
+ Object o = custom.getPossibleValue(graph);
+ Function2<Variable,Resource,Resource> fn = (Function2<Variable,Resource,Resource>)o;
+
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.put("graph", graph);
+ try {
+ return (Resource)fn.apply(this, Layer0.getInstance(graph).Entity);
+ } catch (Throwable t) {
+ if (t instanceof DatabaseException)
+ throw (DatabaseException) t;
+ throw new DatabaseException(t);
+ } finally {
+ sclContext.put("graph", oldGraph);
+ }
+
+ }
+
+ Resource resource = getPossibleRepresents(graph);
+ if(resource == null) {
+ String uri = getPossiblePropertyValue(graph, "typeURI");
+ if(uri != null) return graph.syncRequest(new org.simantics.db.common.primitiverequest.Resource(uri), TransientCacheAsyncListener.<Resource>instance());
+ throw new DatabaseException("No type for " + getURI(graph));
+ }
+ return graph.getSingleType(resource);
+
+ }
+
+
@Override
public Resource getPossibleType(ReadGraph graph) throws DatabaseException {
+
+ Variable custom = getPossibleProperty(graph, "typeResource");
+ if(custom != null) {
+
+ Object o = custom.getPossibleValue(graph);
+ Function2<Variable,Resource,Resource> fn = (Function2<Variable,Resource,Resource>)o;
+
+ SCLContext sclContext = SCLContext.getCurrent();
+ Object oldGraph = sclContext.put("graph", graph);
+ try {
+ return (Resource)fn.apply(this, Layer0.getInstance(graph).Entity);
+ } catch (Throwable t) {
+ if (t instanceof DatabaseException)
+ throw (DatabaseException) t;
+ throw new DatabaseException(t);
+ } finally {
+ sclContext.put("graph", oldGraph);
+ }
+
+ }
+
Resource resource = getPossibleRepresents(graph);
if(resource == null) {
String uri = getPossiblePropertyValue(graph, "typeURI");
}
public Resource getType(ReadGraph graph, Resource baseType) throws DatabaseException {
+
+ Variable custom = getPossibleProperty(graph, "typeResource");
+ if(custom != null) {
+
+ Object o = custom.getPossibleValue(graph);
+ Function2<Variable,Resource,Resource> fn = (Function2<Variable,Resource,Resource>)o;
+
+ 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);
+ }
+
+ }
+
Resource resource = getPossibleRepresents(graph);
if(resource == null) {
String uri = getPossiblePropertyValue(graph, "typeURI");
@Override
public Resource getPossibleType(ReadGraph graph, Resource baseType) throws DatabaseException {
+
+ Variable custom = getPossibleProperty(graph, "typeResource");
+ if(custom != null) {
+ Object o = custom.getPossibleValue(graph);
+ Function2<Variable,Resource,Resource> fn = (Function2<Variable,Resource,Resource>)o;
+
+ 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);
+ }
+
+ }
+
Resource resource = getPossibleRepresents(graph);
if(resource == null) {
String uri = getPossiblePropertyValue(graph, "typeURI");