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