]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - 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
diff --git a/bundles/org.simantics.scenegraph.ontology/src/org/simantics/scenegraph/ontology/ScenegraphResources.java b/bundles/org.simantics.scenegraph.ontology/src/org/simantics/scenegraph/ontology/ScenegraphResources.java
new file mode 100644 (file)
index 0000000..a382d9c
--- /dev/null
@@ -0,0 +1,133 @@
+package org.simantics.scenegraph.ontology;\r
+\r
+import org.simantics.db.RequestProcessor;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.request.Read;\r
+import org.simantics.db.Session;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.service.QueryControl;\r
+\r
+public class ScenegraphResources {\r
+    \r
+    public final Resource Functions;\r
+    public final Resource Functions_defaultRuntimeResource;\r
+    public final Resource Functions_defaultRuntimeVariable;\r
+    public final Resource Functions_liftedProperty;\r
+    public final Resource Functions_singleVariableSelection;\r
+    public final Resource LiftedProperty;\r
+    public final Resource LiftedPropertyRelation;\r
+    public final Resource LiftedProperty_HasPredicate;\r
+    public final Resource LiftedProperty_HasPredicate_Inverse;\r
+    public final Resource Node;\r
+    public final Resource Node_HasProperty;\r
+    public final Resource Node_HasProperty_Inverse;\r
+    public final Resource Node_children;\r
+    public final Resource Node_children_Inverse;\r
+    public final Resource Runtime;\r
+    public final Resource Runtime_HasResource;\r
+    public final Resource Runtime_HasResource_Inverse;\r
+    public final Resource Runtime_HasVariable;\r
+    public final Resource Runtime_HasVariable_Inverse;\r
+    public final Resource Runtime_resource;\r
+    public final Resource Runtime_resource_Inverse;\r
+    public final Resource Runtime_variable;\r
+    public final Resource Runtime_variable_Inverse;\r
+    public final Resource lifted;\r
+    public final Resource userProperty;\r
+    public final Resource userProperty_Inverse;\r
+        \r
+    public static class URIs {\r
+        public static final String Functions = "http://www.simantics.org/Scenegraph-1.1/Functions";\r
+        public static final String Functions_defaultRuntimeResource = "http://www.simantics.org/Scenegraph-1.1/Functions/defaultRuntimeResource";\r
+        public static final String Functions_defaultRuntimeVariable = "http://www.simantics.org/Scenegraph-1.1/Functions/defaultRuntimeVariable";\r
+        public static final String Functions_liftedProperty = "http://www.simantics.org/Scenegraph-1.1/Functions/liftedProperty";\r
+        public static final String Functions_singleVariableSelection = "http://www.simantics.org/Scenegraph-1.1/Functions/singleVariableSelection";\r
+        public static final String LiftedProperty = "http://www.simantics.org/Scenegraph-1.1/LiftedProperty";\r
+        public static final String LiftedPropertyRelation = "http://www.simantics.org/Scenegraph-1.1/LiftedPropertyRelation";\r
+        public static final String LiftedProperty_HasPredicate = "http://www.simantics.org/Scenegraph-1.1/LiftedProperty/HasPredicate";\r
+        public static final String LiftedProperty_HasPredicate_Inverse = "http://www.simantics.org/Scenegraph-1.1/LiftedProperty/HasPredicate/Inverse";\r
+        public static final String Node = "http://www.simantics.org/Scenegraph-1.1/Node";\r
+        public static final String Node_HasProperty = "http://www.simantics.org/Scenegraph-1.1/Node/HasProperty";\r
+        public static final String Node_HasProperty_Inverse = "http://www.simantics.org/Scenegraph-1.1/Node/HasProperty/Inverse";\r
+        public static final String Node_children = "http://www.simantics.org/Scenegraph-1.1/Node/children";\r
+        public static final String Node_children_Inverse = "http://www.simantics.org/Scenegraph-1.1/Node/children/Inverse";\r
+        public static final String Runtime = "http://www.simantics.org/Scenegraph-1.1/Runtime";\r
+        public static final String Runtime_HasResource = "http://www.simantics.org/Scenegraph-1.1/Runtime/HasResource";\r
+        public static final String Runtime_HasResource_Inverse = "http://www.simantics.org/Scenegraph-1.1/Runtime/HasResource/Inverse";\r
+        public static final String Runtime_HasVariable = "http://www.simantics.org/Scenegraph-1.1/Runtime/HasVariable";\r
+        public static final String Runtime_HasVariable_Inverse = "http://www.simantics.org/Scenegraph-1.1/Runtime/HasVariable/Inverse";\r
+        public static final String Runtime_resource = "http://www.simantics.org/Scenegraph-1.1/Runtime/resource";\r
+        public static final String Runtime_resource_Inverse = "http://www.simantics.org/Scenegraph-1.1/Runtime/resource/Inverse";\r
+        public static final String Runtime_variable = "http://www.simantics.org/Scenegraph-1.1/Runtime/variable";\r
+        public static final String Runtime_variable_Inverse = "http://www.simantics.org/Scenegraph-1.1/Runtime/variable/Inverse";\r
+        public static final String lifted = "http://www.simantics.org/Scenegraph-1.1/lifted";\r
+        public static final String userProperty = "http://www.simantics.org/Scenegraph-1.1/userProperty";\r
+        public static final String userProperty_Inverse = "http://www.simantics.org/Scenegraph-1.1/userProperty/Inverse";\r
+    }\r
+    \r
+    public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
+        try {\r
+            return graph.getResource(uri);\r
+        } catch(DatabaseException e) {\r
+            System.err.println(e.getMessage());\r
+            return null;\r
+        }\r
+    }\r
+    \r
+    public ScenegraphResources(ReadGraph graph) {\r
+        Functions = getResourceOrNull(graph, URIs.Functions);\r
+        Functions_defaultRuntimeResource = getResourceOrNull(graph, URIs.Functions_defaultRuntimeResource);\r
+        Functions_defaultRuntimeVariable = getResourceOrNull(graph, URIs.Functions_defaultRuntimeVariable);\r
+        Functions_liftedProperty = getResourceOrNull(graph, URIs.Functions_liftedProperty);\r
+        Functions_singleVariableSelection = getResourceOrNull(graph, URIs.Functions_singleVariableSelection);\r
+        LiftedProperty = getResourceOrNull(graph, URIs.LiftedProperty);\r
+        LiftedPropertyRelation = getResourceOrNull(graph, URIs.LiftedPropertyRelation);\r
+        LiftedProperty_HasPredicate = getResourceOrNull(graph, URIs.LiftedProperty_HasPredicate);\r
+        LiftedProperty_HasPredicate_Inverse = getResourceOrNull(graph, URIs.LiftedProperty_HasPredicate_Inverse);\r
+        Node = getResourceOrNull(graph, URIs.Node);\r
+        Node_HasProperty = getResourceOrNull(graph, URIs.Node_HasProperty);\r
+        Node_HasProperty_Inverse = getResourceOrNull(graph, URIs.Node_HasProperty_Inverse);\r
+        Node_children = getResourceOrNull(graph, URIs.Node_children);\r
+        Node_children_Inverse = getResourceOrNull(graph, URIs.Node_children_Inverse);\r
+        Runtime = getResourceOrNull(graph, URIs.Runtime);\r
+        Runtime_HasResource = getResourceOrNull(graph, URIs.Runtime_HasResource);\r
+        Runtime_HasResource_Inverse = getResourceOrNull(graph, URIs.Runtime_HasResource_Inverse);\r
+        Runtime_HasVariable = getResourceOrNull(graph, URIs.Runtime_HasVariable);\r
+        Runtime_HasVariable_Inverse = getResourceOrNull(graph, URIs.Runtime_HasVariable_Inverse);\r
+        Runtime_resource = getResourceOrNull(graph, URIs.Runtime_resource);\r
+        Runtime_resource_Inverse = getResourceOrNull(graph, URIs.Runtime_resource_Inverse);\r
+        Runtime_variable = getResourceOrNull(graph, URIs.Runtime_variable);\r
+        Runtime_variable_Inverse = getResourceOrNull(graph, URIs.Runtime_variable_Inverse);\r
+        lifted = getResourceOrNull(graph, URIs.lifted);\r
+        userProperty = getResourceOrNull(graph, URIs.userProperty);\r
+        userProperty_Inverse = getResourceOrNull(graph, URIs.userProperty_Inverse);\r
+    }\r
+    \r
+    public static ScenegraphResources getInstance(ReadGraph graph) {\r
+        Session session = graph.getSession();\r
+        ScenegraphResources ret = session.peekService(ScenegraphResources.class);\r
+        if(ret == null) {\r
+            QueryControl qc = graph.getService(QueryControl.class);\r
+            ret = new ScenegraphResources(qc.getIndependentGraph(graph));\r
+            session.registerService(ScenegraphResources.class, ret);\r
+        }\r
+        return ret;\r
+    }\r
+    \r
+    public static ScenegraphResources getInstance(RequestProcessor session) throws DatabaseException {\r
+        ScenegraphResources ret = session.peekService(ScenegraphResources.class);\r
+        if(ret == null) {\r
+            ret = session.syncRequest(new Read<ScenegraphResources>() {\r
+                public ScenegraphResources perform(ReadGraph graph) throws DatabaseException {\r
+                    QueryControl qc = graph.getService(QueryControl.class);\r
+                    return new ScenegraphResources(qc.getIndependentGraph(graph));\r
+                }\r
+            });\r
+            session.registerService(ScenegraphResources.class, ret);\r
+        }\r
+        return ret;\r
+    }\r
+    \r
+}\r
+\r