]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.graphfile.ontology/src/org/simantics/graphfile/ontology/GraphFileResource.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.graphfile.ontology / src / org / simantics / graphfile / ontology / GraphFileResource.java
diff --git a/bundles/org.simantics.graphfile.ontology/src/org/simantics/graphfile/ontology/GraphFileResource.java b/bundles/org.simantics.graphfile.ontology/src/org/simantics/graphfile/ontology/GraphFileResource.java
new file mode 100644 (file)
index 0000000..cb6cdfb
--- /dev/null
@@ -0,0 +1,100 @@
+package org.simantics.graphfile.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 GraphFileResource {\r
+    \r
+    public final Resource File;\r
+    public final Resource Folder;\r
+    public final Resource HasFile;\r
+    public final Resource HasFile_Inverse;\r
+    public final Resource HasFiledata;\r
+    public final Resource HasFiledata_Inverse;\r
+    public final Resource HasFolder;\r
+    public final Resource HasFolder_Inverse;\r
+    public final Resource HasResourceName;\r
+    public final Resource HasResourceName_Inverse;\r
+    public final Resource HasSystemResource;\r
+    public final Resource LastModified;\r
+    public final Resource LastModified_Inverse;\r
+    public final Resource PartOfSystemResource;\r
+    public final Resource SystemResource;\r
+        \r
+    public static class URIs {\r
+        public static final String File = "http://www.simantics.org/GraphFile-0.1/File";\r
+        public static final String Folder = "http://www.simantics.org/GraphFile-0.1/Folder";\r
+        public static final String HasFile = "http://www.simantics.org/GraphFile-0.1/HasFile";\r
+        public static final String HasFile_Inverse = "http://www.simantics.org/GraphFile-0.1/HasFile/Inverse";\r
+        public static final String HasFiledata = "http://www.simantics.org/GraphFile-0.1/HasFiledata";\r
+        public static final String HasFiledata_Inverse = "http://www.simantics.org/GraphFile-0.1/HasFiledata/Inverse";\r
+        public static final String HasFolder = "http://www.simantics.org/GraphFile-0.1/HasFolder";\r
+        public static final String HasFolder_Inverse = "http://www.simantics.org/GraphFile-0.1/HasFolder/Inverse";\r
+        public static final String HasResourceName = "http://www.simantics.org/GraphFile-0.1/HasResourceName";\r
+        public static final String HasResourceName_Inverse = "http://www.simantics.org/GraphFile-0.1/HasResourceName/Inverse";\r
+        public static final String HasSystemResource = "http://www.simantics.org/GraphFile-0.1/HasSystemResource";\r
+        public static final String LastModified = "http://www.simantics.org/GraphFile-0.1/LastModified";\r
+        public static final String LastModified_Inverse = "http://www.simantics.org/GraphFile-0.1/LastModified/Inverse";\r
+        public static final String PartOfSystemResource = "http://www.simantics.org/GraphFile-0.1/PartOfSystemResource";\r
+        public static final String SystemResource = "http://www.simantics.org/GraphFile-0.1/SystemResource";\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 GraphFileResource(ReadGraph graph) {\r
+        File = getResourceOrNull(graph, URIs.File);\r
+        Folder = getResourceOrNull(graph, URIs.Folder);\r
+        HasFile = getResourceOrNull(graph, URIs.HasFile);\r
+        HasFile_Inverse = getResourceOrNull(graph, URIs.HasFile_Inverse);\r
+        HasFiledata = getResourceOrNull(graph, URIs.HasFiledata);\r
+        HasFiledata_Inverse = getResourceOrNull(graph, URIs.HasFiledata_Inverse);\r
+        HasFolder = getResourceOrNull(graph, URIs.HasFolder);\r
+        HasFolder_Inverse = getResourceOrNull(graph, URIs.HasFolder_Inverse);\r
+        HasResourceName = getResourceOrNull(graph, URIs.HasResourceName);\r
+        HasResourceName_Inverse = getResourceOrNull(graph, URIs.HasResourceName_Inverse);\r
+        HasSystemResource = getResourceOrNull(graph, URIs.HasSystemResource);\r
+        LastModified = getResourceOrNull(graph, URIs.LastModified);\r
+        LastModified_Inverse = getResourceOrNull(graph, URIs.LastModified_Inverse);\r
+        PartOfSystemResource = getResourceOrNull(graph, URIs.PartOfSystemResource);\r
+        SystemResource = getResourceOrNull(graph, URIs.SystemResource);\r
+    }\r
+    \r
+    public static GraphFileResource getInstance(ReadGraph graph) {\r
+        Session session = graph.getSession();\r
+        GraphFileResource ret = session.peekService(GraphFileResource.class);\r
+        if(ret == null) {\r
+            QueryControl qc = graph.getService(QueryControl.class);\r
+            ret = new GraphFileResource(qc.getIndependentGraph(graph));\r
+            session.registerService(GraphFileResource.class, ret);\r
+        }\r
+        return ret;\r
+    }\r
+    \r
+    public static GraphFileResource getInstance(RequestProcessor session) throws DatabaseException {\r
+        GraphFileResource ret = session.peekService(GraphFileResource.class);\r
+        if(ret == null) {\r
+            ret = session.syncRequest(new Read<GraphFileResource>() {\r
+                public GraphFileResource perform(ReadGraph graph) throws DatabaseException {\r
+                    QueryControl qc = graph.getService(QueryControl.class);\r
+                    return new GraphFileResource(qc.getIndependentGraph(graph));\r
+                }\r
+            });\r
+            session.registerService(GraphFileResource.class, ret);\r
+        }\r
+        return ret;\r
+    }\r
+    \r
+}\r
+\r