]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph.ontology/src/org/simantics/scenegraph/ontology/ScenegraphResources.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scenegraph.ontology / src / org / simantics / scenegraph / ontology / ScenegraphResources.java
1 package org.simantics.scenegraph.ontology;\r
2 \r
3 import org.simantics.db.RequestProcessor;\r
4 import org.simantics.db.Resource;\r
5 import org.simantics.db.ReadGraph;\r
6 import org.simantics.db.request.Read;\r
7 import org.simantics.db.Session;\r
8 import org.simantics.db.exception.DatabaseException;\r
9 import org.simantics.db.service.QueryControl;\r
10 \r
11 public class ScenegraphResources {\r
12     \r
13     public final Resource Functions;\r
14     public final Resource Functions_defaultRuntimeResource;\r
15     public final Resource Functions_defaultRuntimeVariable;\r
16     public final Resource Functions_liftedProperty;\r
17     public final Resource Functions_singleVariableSelection;\r
18     public final Resource LiftedProperty;\r
19     public final Resource LiftedPropertyRelation;\r
20     public final Resource LiftedProperty_HasPredicate;\r
21     public final Resource LiftedProperty_HasPredicate_Inverse;\r
22     public final Resource Node;\r
23     public final Resource Node_HasProperty;\r
24     public final Resource Node_HasProperty_Inverse;\r
25     public final Resource Node_children;\r
26     public final Resource Node_children_Inverse;\r
27     public final Resource Runtime;\r
28     public final Resource Runtime_HasResource;\r
29     public final Resource Runtime_HasResource_Inverse;\r
30     public final Resource Runtime_HasVariable;\r
31     public final Resource Runtime_HasVariable_Inverse;\r
32     public final Resource Runtime_resource;\r
33     public final Resource Runtime_resource_Inverse;\r
34     public final Resource Runtime_variable;\r
35     public final Resource Runtime_variable_Inverse;\r
36     public final Resource lifted;\r
37     public final Resource userProperty;\r
38     public final Resource userProperty_Inverse;\r
39         \r
40     public static class URIs {\r
41         public static final String Functions = "http://www.simantics.org/Scenegraph-1.1/Functions";\r
42         public static final String Functions_defaultRuntimeResource = "http://www.simantics.org/Scenegraph-1.1/Functions/defaultRuntimeResource";\r
43         public static final String Functions_defaultRuntimeVariable = "http://www.simantics.org/Scenegraph-1.1/Functions/defaultRuntimeVariable";\r
44         public static final String Functions_liftedProperty = "http://www.simantics.org/Scenegraph-1.1/Functions/liftedProperty";\r
45         public static final String Functions_singleVariableSelection = "http://www.simantics.org/Scenegraph-1.1/Functions/singleVariableSelection";\r
46         public static final String LiftedProperty = "http://www.simantics.org/Scenegraph-1.1/LiftedProperty";\r
47         public static final String LiftedPropertyRelation = "http://www.simantics.org/Scenegraph-1.1/LiftedPropertyRelation";\r
48         public static final String LiftedProperty_HasPredicate = "http://www.simantics.org/Scenegraph-1.1/LiftedProperty/HasPredicate";\r
49         public static final String LiftedProperty_HasPredicate_Inverse = "http://www.simantics.org/Scenegraph-1.1/LiftedProperty/HasPredicate/Inverse";\r
50         public static final String Node = "http://www.simantics.org/Scenegraph-1.1/Node";\r
51         public static final String Node_HasProperty = "http://www.simantics.org/Scenegraph-1.1/Node/HasProperty";\r
52         public static final String Node_HasProperty_Inverse = "http://www.simantics.org/Scenegraph-1.1/Node/HasProperty/Inverse";\r
53         public static final String Node_children = "http://www.simantics.org/Scenegraph-1.1/Node/children";\r
54         public static final String Node_children_Inverse = "http://www.simantics.org/Scenegraph-1.1/Node/children/Inverse";\r
55         public static final String Runtime = "http://www.simantics.org/Scenegraph-1.1/Runtime";\r
56         public static final String Runtime_HasResource = "http://www.simantics.org/Scenegraph-1.1/Runtime/HasResource";\r
57         public static final String Runtime_HasResource_Inverse = "http://www.simantics.org/Scenegraph-1.1/Runtime/HasResource/Inverse";\r
58         public static final String Runtime_HasVariable = "http://www.simantics.org/Scenegraph-1.1/Runtime/HasVariable";\r
59         public static final String Runtime_HasVariable_Inverse = "http://www.simantics.org/Scenegraph-1.1/Runtime/HasVariable/Inverse";\r
60         public static final String Runtime_resource = "http://www.simantics.org/Scenegraph-1.1/Runtime/resource";\r
61         public static final String Runtime_resource_Inverse = "http://www.simantics.org/Scenegraph-1.1/Runtime/resource/Inverse";\r
62         public static final String Runtime_variable = "http://www.simantics.org/Scenegraph-1.1/Runtime/variable";\r
63         public static final String Runtime_variable_Inverse = "http://www.simantics.org/Scenegraph-1.1/Runtime/variable/Inverse";\r
64         public static final String lifted = "http://www.simantics.org/Scenegraph-1.1/lifted";\r
65         public static final String userProperty = "http://www.simantics.org/Scenegraph-1.1/userProperty";\r
66         public static final String userProperty_Inverse = "http://www.simantics.org/Scenegraph-1.1/userProperty/Inverse";\r
67     }\r
68     \r
69     public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
70         try {\r
71             return graph.getResource(uri);\r
72         } catch(DatabaseException e) {\r
73             System.err.println(e.getMessage());\r
74             return null;\r
75         }\r
76     }\r
77     \r
78     public ScenegraphResources(ReadGraph graph) {\r
79         Functions = getResourceOrNull(graph, URIs.Functions);\r
80         Functions_defaultRuntimeResource = getResourceOrNull(graph, URIs.Functions_defaultRuntimeResource);\r
81         Functions_defaultRuntimeVariable = getResourceOrNull(graph, URIs.Functions_defaultRuntimeVariable);\r
82         Functions_liftedProperty = getResourceOrNull(graph, URIs.Functions_liftedProperty);\r
83         Functions_singleVariableSelection = getResourceOrNull(graph, URIs.Functions_singleVariableSelection);\r
84         LiftedProperty = getResourceOrNull(graph, URIs.LiftedProperty);\r
85         LiftedPropertyRelation = getResourceOrNull(graph, URIs.LiftedPropertyRelation);\r
86         LiftedProperty_HasPredicate = getResourceOrNull(graph, URIs.LiftedProperty_HasPredicate);\r
87         LiftedProperty_HasPredicate_Inverse = getResourceOrNull(graph, URIs.LiftedProperty_HasPredicate_Inverse);\r
88         Node = getResourceOrNull(graph, URIs.Node);\r
89         Node_HasProperty = getResourceOrNull(graph, URIs.Node_HasProperty);\r
90         Node_HasProperty_Inverse = getResourceOrNull(graph, URIs.Node_HasProperty_Inverse);\r
91         Node_children = getResourceOrNull(graph, URIs.Node_children);\r
92         Node_children_Inverse = getResourceOrNull(graph, URIs.Node_children_Inverse);\r
93         Runtime = getResourceOrNull(graph, URIs.Runtime);\r
94         Runtime_HasResource = getResourceOrNull(graph, URIs.Runtime_HasResource);\r
95         Runtime_HasResource_Inverse = getResourceOrNull(graph, URIs.Runtime_HasResource_Inverse);\r
96         Runtime_HasVariable = getResourceOrNull(graph, URIs.Runtime_HasVariable);\r
97         Runtime_HasVariable_Inverse = getResourceOrNull(graph, URIs.Runtime_HasVariable_Inverse);\r
98         Runtime_resource = getResourceOrNull(graph, URIs.Runtime_resource);\r
99         Runtime_resource_Inverse = getResourceOrNull(graph, URIs.Runtime_resource_Inverse);\r
100         Runtime_variable = getResourceOrNull(graph, URIs.Runtime_variable);\r
101         Runtime_variable_Inverse = getResourceOrNull(graph, URIs.Runtime_variable_Inverse);\r
102         lifted = getResourceOrNull(graph, URIs.lifted);\r
103         userProperty = getResourceOrNull(graph, URIs.userProperty);\r
104         userProperty_Inverse = getResourceOrNull(graph, URIs.userProperty_Inverse);\r
105     }\r
106     \r
107     public static ScenegraphResources getInstance(ReadGraph graph) {\r
108         Session session = graph.getSession();\r
109         ScenegraphResources ret = session.peekService(ScenegraphResources.class);\r
110         if(ret == null) {\r
111             QueryControl qc = graph.getService(QueryControl.class);\r
112             ret = new ScenegraphResources(qc.getIndependentGraph(graph));\r
113             session.registerService(ScenegraphResources.class, ret);\r
114         }\r
115         return ret;\r
116     }\r
117     \r
118     public static ScenegraphResources getInstance(RequestProcessor session) throws DatabaseException {\r
119         ScenegraphResources ret = session.peekService(ScenegraphResources.class);\r
120         if(ret == null) {\r
121             ret = session.syncRequest(new Read<ScenegraphResources>() {\r
122                 public ScenegraphResources perform(ReadGraph graph) throws DatabaseException {\r
123                     QueryControl qc = graph.getService(QueryControl.class);\r
124                     return new ScenegraphResources(qc.getIndependentGraph(graph));\r
125                 }\r
126             });\r
127             session.registerService(ScenegraphResources.class, ret);\r
128         }\r
129         return ret;\r
130     }\r
131     \r
132 }\r
133 \r