]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph.loader/src/org/simantics/scenegraph/loader/function/All.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.scenegraph.loader / src / org / simantics / scenegraph / loader / function / All.java
1 package org.simantics.scenegraph.loader.function;
2
3 import org.simantics.databoard.Bindings;
4 import org.simantics.db.ReadGraph;
5 import org.simantics.db.Resource;
6 import org.simantics.db.exception.DatabaseException;
7 import org.simantics.db.layer0.variable.Variable;
8 import org.simantics.db.layer0.variable.Variables;
9 import org.simantics.layer0.Layer0;
10 import org.simantics.scenegraph.loader.SceneGraphContext;
11 import org.simantics.scenegraph.loader.ScenegraphLoaderUtils;
12 import org.simantics.scenegraph.ontology.ScenegraphResources;
13 import org.simantics.scl.reflection.annotations.SCLValue;
14
15 public class All {
16
17     @SCLValue(type = "ReadGraph -> Resource -> Variable -> Variable")
18     public static Variable defaultRuntimeVariable(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
19         
20         SceneGraphContext vc = ScenegraphLoaderUtils.getContext(graph, context);
21         if(vc == null) return null;
22         
23         ScenegraphResources SG = ScenegraphResources.getInstance(graph);
24         String uri = graph.getRelatedValue(vc.getRuntime(), SG.Runtime_HasVariable, Bindings.STRING);
25         return Variables.getVariable(graph, uri);
26         
27     }
28
29     @SCLValue(type = "ReadGraph -> Resource -> Variable -> Resource")
30     public static Resource defaultRuntimeResource(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
31         
32         SceneGraphContext vc = ScenegraphLoaderUtils.getContext(graph, context);
33         if(vc == null) return null;
34         
35         ScenegraphResources SG = ScenegraphResources.getInstance(graph);
36         return graph.getSingleObject(vc.getRuntime(), SG.Runtime_HasResource);
37         
38     }
39
40     
41         private static Object walk(ReadGraph graph, Variable context, String name) throws DatabaseException {
42                 
43                 Variable var = context.getPossibleProperty(graph, name);
44                 if(var != null) return var.getValue(graph);
45                 
46                 Variable parent = context.getParent(graph);
47                 if(parent == null) return null; 
48                 
49                 return walk(graph, parent, name);
50                 
51         }
52         
53     @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")
54     public static Object liftedProperty(ReadGraph graph, Resource converter, Variable context) throws DatabaseException {
55         
56         ScenegraphResources SG = ScenegraphResources.getInstance(graph);
57         final Resource predicate = graph.getSingleObject(converter, SG.LiftedProperty_HasPredicate);
58         
59                 try {
60                         Layer0 L0 = Layer0.getInstance(graph);
61                         Variable parent = context.getParent(graph);
62                         String name = graph.getRelatedValue(predicate, L0.HasName, Bindings.STRING);
63                         return walk(graph, parent, name);
64                 } catch (DatabaseException e) {
65                         e.printStackTrace();
66                         return null;
67                 }
68         
69     }
70         
71     @SCLValue(type = "ReadGraph -> Resource -> Variable -> Variable")
72     public static Variable singleVariableSelection(ReadGraph graph, Resource resource, Variable context) throws DatabaseException {
73         return ScenegraphLoaderUtils.getVariableSelection(graph, context);
74     }
75     
76 }