X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scenegraph.loader%2Fsrc%2Forg%2Fsimantics%2Fscenegraph%2Floader%2Ffunction%2FAll.java;h=83714a9a43dc067a25b704a579104669bc22f356;hp=5efa5d6054416ce08523096637f90d8cf009d801;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.scenegraph.loader/src/org/simantics/scenegraph/loader/function/All.java b/bundles/org.simantics.scenegraph.loader/src/org/simantics/scenegraph/loader/function/All.java index 5efa5d605..83714a9a4 100644 --- a/bundles/org.simantics.scenegraph.loader/src/org/simantics/scenegraph/loader/function/All.java +++ b/bundles/org.simantics.scenegraph.loader/src/org/simantics/scenegraph/loader/function/All.java @@ -1,76 +1,76 @@ -package org.simantics.scenegraph.loader.function; - -import org.simantics.databoard.Bindings; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.variable.Variable; -import org.simantics.db.layer0.variable.Variables; -import org.simantics.layer0.Layer0; -import org.simantics.scenegraph.loader.SceneGraphContext; -import org.simantics.scenegraph.loader.ScenegraphLoaderUtils; -import org.simantics.scenegraph.ontology.ScenegraphResources; -import org.simantics.scl.reflection.annotations.SCLValue; - -public class All { - - @SCLValue(type = "ReadGraph -> Resource -> Variable -> Variable") - public static Variable defaultRuntimeVariable(ReadGraph graph, Resource converter, Variable context) throws DatabaseException { - - SceneGraphContext vc = ScenegraphLoaderUtils.getContext(graph, context); - if(vc == null) return null; - - ScenegraphResources SG = ScenegraphResources.getInstance(graph); - String uri = graph.getRelatedValue(vc.getRuntime(), SG.Runtime_HasVariable, Bindings.STRING); - return Variables.getVariable(graph, uri); - - } - - @SCLValue(type = "ReadGraph -> Resource -> Variable -> Resource") - public static Resource defaultRuntimeResource(ReadGraph graph, Resource converter, Variable context) throws DatabaseException { - - SceneGraphContext vc = ScenegraphLoaderUtils.getContext(graph, context); - if(vc == null) return null; - - ScenegraphResources SG = ScenegraphResources.getInstance(graph); - return graph.getSingleObject(vc.getRuntime(), SG.Runtime_HasResource); - - } - - - private static Object walk(ReadGraph graph, Variable context, String name) throws DatabaseException { - - Variable var = context.getPossibleProperty(graph, name); - if(var != null) return var.getValue(graph); - - Variable parent = context.getParent(graph); - if(parent == null) return null; - - return walk(graph, parent, name); - - } - - @SCLValue(type = "ReadGraph -> Resource -> Variable -> a") - public static Object liftedProperty(ReadGraph graph, Resource converter, Variable context) throws DatabaseException { - - ScenegraphResources SG = ScenegraphResources.getInstance(graph); - final Resource predicate = graph.getSingleObject(converter, SG.LiftedProperty_HasPredicate); - - try { - Layer0 L0 = Layer0.getInstance(graph); - Variable parent = context.getParent(graph); - String name = graph.getRelatedValue(predicate, L0.HasName, Bindings.STRING); - return walk(graph, parent, name); - } catch (DatabaseException e) { - e.printStackTrace(); - return null; - } - - } - - @SCLValue(type = "ReadGraph -> Resource -> Variable -> Variable") - public static Variable singleVariableSelection(ReadGraph graph, Resource resource, Variable context) throws DatabaseException { - return ScenegraphLoaderUtils.getVariableSelection(graph, context); - } - -} +package org.simantics.scenegraph.loader.function; + +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.variable.Variable; +import org.simantics.db.layer0.variable.Variables; +import org.simantics.layer0.Layer0; +import org.simantics.scenegraph.loader.SceneGraphContext; +import org.simantics.scenegraph.loader.ScenegraphLoaderUtils; +import org.simantics.scenegraph.ontology.ScenegraphResources; +import org.simantics.scl.reflection.annotations.SCLValue; + +public class All { + + @SCLValue(type = "ReadGraph -> Resource -> Variable -> Variable") + public static Variable defaultRuntimeVariable(ReadGraph graph, Resource converter, Variable context) throws DatabaseException { + + SceneGraphContext vc = ScenegraphLoaderUtils.getContext(graph, context); + if(vc == null) return null; + + ScenegraphResources SG = ScenegraphResources.getInstance(graph); + String uri = graph.getRelatedValue(vc.getRuntime(), SG.Runtime_HasVariable, Bindings.STRING); + return Variables.getVariable(graph, uri); + + } + + @SCLValue(type = "ReadGraph -> Resource -> Variable -> Resource") + public static Resource defaultRuntimeResource(ReadGraph graph, Resource converter, Variable context) throws DatabaseException { + + SceneGraphContext vc = ScenegraphLoaderUtils.getContext(graph, context); + if(vc == null) return null; + + ScenegraphResources SG = ScenegraphResources.getInstance(graph); + return graph.getSingleObject(vc.getRuntime(), SG.Runtime_HasResource); + + } + + + private static Object walk(ReadGraph graph, Variable context, String name) throws DatabaseException { + + Variable var = context.getPossibleProperty(graph, name); + if(var != null) return var.getValue(graph); + + Variable parent = context.getParent(graph); + if(parent == null) return null; + + return walk(graph, parent, name); + + } + + @SCLValue(type = "ReadGraph -> Resource -> Variable -> a") + public static Object liftedProperty(ReadGraph graph, Resource converter, Variable context) throws DatabaseException { + + ScenegraphResources SG = ScenegraphResources.getInstance(graph); + final Resource predicate = graph.getSingleObject(converter, SG.LiftedProperty_HasPredicate); + + try { + Layer0 L0 = Layer0.getInstance(graph); + Variable parent = context.getParent(graph); + String name = graph.getRelatedValue(predicate, L0.HasName, Bindings.STRING); + return walk(graph, parent, name); + } catch (DatabaseException e) { + e.printStackTrace(); + return null; + } + + } + + @SCLValue(type = "ReadGraph -> Resource -> Variable -> Variable") + public static Variable singleVariableSelection(ReadGraph graph, Resource resource, Variable context) throws DatabaseException { + return ScenegraphLoaderUtils.getVariableSelection(graph, context); + } + +}