]> gerrit.simantics Code Review - simantics/platform.git/blob
cb6cdfba27fcc909cae086f8c9e748b3af9865c6
[simantics/platform.git] /
1 package org.simantics.graphfile.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 GraphFileResource {\r
12     \r
13     public final Resource File;\r
14     public final Resource Folder;\r
15     public final Resource HasFile;\r
16     public final Resource HasFile_Inverse;\r
17     public final Resource HasFiledata;\r
18     public final Resource HasFiledata_Inverse;\r
19     public final Resource HasFolder;\r
20     public final Resource HasFolder_Inverse;\r
21     public final Resource HasResourceName;\r
22     public final Resource HasResourceName_Inverse;\r
23     public final Resource HasSystemResource;\r
24     public final Resource LastModified;\r
25     public final Resource LastModified_Inverse;\r
26     public final Resource PartOfSystemResource;\r
27     public final Resource SystemResource;\r
28         \r
29     public static class URIs {\r
30         public static final String File = "http://www.simantics.org/GraphFile-0.1/File";\r
31         public static final String Folder = "http://www.simantics.org/GraphFile-0.1/Folder";\r
32         public static final String HasFile = "http://www.simantics.org/GraphFile-0.1/HasFile";\r
33         public static final String HasFile_Inverse = "http://www.simantics.org/GraphFile-0.1/HasFile/Inverse";\r
34         public static final String HasFiledata = "http://www.simantics.org/GraphFile-0.1/HasFiledata";\r
35         public static final String HasFiledata_Inverse = "http://www.simantics.org/GraphFile-0.1/HasFiledata/Inverse";\r
36         public static final String HasFolder = "http://www.simantics.org/GraphFile-0.1/HasFolder";\r
37         public static final String HasFolder_Inverse = "http://www.simantics.org/GraphFile-0.1/HasFolder/Inverse";\r
38         public static final String HasResourceName = "http://www.simantics.org/GraphFile-0.1/HasResourceName";\r
39         public static final String HasResourceName_Inverse = "http://www.simantics.org/GraphFile-0.1/HasResourceName/Inverse";\r
40         public static final String HasSystemResource = "http://www.simantics.org/GraphFile-0.1/HasSystemResource";\r
41         public static final String LastModified = "http://www.simantics.org/GraphFile-0.1/LastModified";\r
42         public static final String LastModified_Inverse = "http://www.simantics.org/GraphFile-0.1/LastModified/Inverse";\r
43         public static final String PartOfSystemResource = "http://www.simantics.org/GraphFile-0.1/PartOfSystemResource";\r
44         public static final String SystemResource = "http://www.simantics.org/GraphFile-0.1/SystemResource";\r
45     }\r
46     \r
47     public static Resource getResourceOrNull(ReadGraph graph, String uri) {\r
48         try {\r
49             return graph.getResource(uri);\r
50         } catch(DatabaseException e) {\r
51             System.err.println(e.getMessage());\r
52             return null;\r
53         }\r
54     }\r
55     \r
56     public GraphFileResource(ReadGraph graph) {\r
57         File = getResourceOrNull(graph, URIs.File);\r
58         Folder = getResourceOrNull(graph, URIs.Folder);\r
59         HasFile = getResourceOrNull(graph, URIs.HasFile);\r
60         HasFile_Inverse = getResourceOrNull(graph, URIs.HasFile_Inverse);\r
61         HasFiledata = getResourceOrNull(graph, URIs.HasFiledata);\r
62         HasFiledata_Inverse = getResourceOrNull(graph, URIs.HasFiledata_Inverse);\r
63         HasFolder = getResourceOrNull(graph, URIs.HasFolder);\r
64         HasFolder_Inverse = getResourceOrNull(graph, URIs.HasFolder_Inverse);\r
65         HasResourceName = getResourceOrNull(graph, URIs.HasResourceName);\r
66         HasResourceName_Inverse = getResourceOrNull(graph, URIs.HasResourceName_Inverse);\r
67         HasSystemResource = getResourceOrNull(graph, URIs.HasSystemResource);\r
68         LastModified = getResourceOrNull(graph, URIs.LastModified);\r
69         LastModified_Inverse = getResourceOrNull(graph, URIs.LastModified_Inverse);\r
70         PartOfSystemResource = getResourceOrNull(graph, URIs.PartOfSystemResource);\r
71         SystemResource = getResourceOrNull(graph, URIs.SystemResource);\r
72     }\r
73     \r
74     public static GraphFileResource getInstance(ReadGraph graph) {\r
75         Session session = graph.getSession();\r
76         GraphFileResource ret = session.peekService(GraphFileResource.class);\r
77         if(ret == null) {\r
78             QueryControl qc = graph.getService(QueryControl.class);\r
79             ret = new GraphFileResource(qc.getIndependentGraph(graph));\r
80             session.registerService(GraphFileResource.class, ret);\r
81         }\r
82         return ret;\r
83     }\r
84     \r
85     public static GraphFileResource getInstance(RequestProcessor session) throws DatabaseException {\r
86         GraphFileResource ret = session.peekService(GraphFileResource.class);\r
87         if(ret == null) {\r
88             ret = session.syncRequest(new Read<GraphFileResource>() {\r
89                 public GraphFileResource perform(ReadGraph graph) throws DatabaseException {\r
90                     QueryControl qc = graph.getService(QueryControl.class);\r
91                     return new GraphFileResource(qc.getIndependentGraph(graph));\r
92                 }\r
93             });\r
94             session.registerService(GraphFileResource.class, ret);\r
95         }\r
96         return ret;\r
97     }\r
98     \r
99 }\r
100 \r