X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fvariable%2FAbstractVariable.java;h=9ab54dcf6a4bf6579876ed5e51c5ad4664613971;hb=1f8b50d81a1aa1bbd67a77f7cbc1060f2eb805d4;hp=d9366b132aa2a41e471bf0cd2ea7d1c9b19cef96;hpb=6f11a60dee43d620d500c0cf5af34a1d91c80a8b;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractVariable.java index d9366b132..9ab54dcf6 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractVariable.java @@ -39,6 +39,8 @@ import org.simantics.db.layer0.variable.RVI.ResourceRVIPart; 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. @@ -187,18 +189,6 @@ public abstract class AbstractVariable implements Variable { 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.instance()); - throw new DatabaseException("No type for " + getURI(graph)); - } - return graph.getSingleType(resource); - - } - public RVIPart getRVIPart(ReadGraph graph) throws DatabaseException { throw new UnsupportedOperationException(); } @@ -950,8 +940,62 @@ public abstract class AbstractVariable implements Variable { } } + public Resource getType(ReadGraph graph) throws DatabaseException { + + Variable custom = getPossibleProperty(graph, "typeResource"); + if(custom != null) { + + Object o = custom.getPossibleValue(graph); + Function2 fn = (Function2)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.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 fn = (Function2)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"); @@ -962,6 +1006,27 @@ public abstract class AbstractVariable implements Variable { } public Resource getType(ReadGraph graph, Resource baseType) throws DatabaseException { + + Variable custom = getPossibleProperty(graph, "typeResource"); + if(custom != null) { + + Object o = custom.getPossibleValue(graph); + Function2 fn = (Function2)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"); @@ -973,6 +1038,26 @@ public abstract class AbstractVariable implements Variable { @Override public Resource getPossibleType(ReadGraph graph, Resource baseType) throws DatabaseException { + + Variable custom = getPossibleProperty(graph, "typeResource"); + if(custom != null) { + Object o = custom.getPossibleValue(graph); + Function2 fn = (Function2)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");