]> gerrit.simantics Code Review - simantics/district.git/blob
513891dfe47b99761638344c0e5f46019ab4df41
[simantics/district.git] /
1 package org.simantics.district.network.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 DistrictNetworkResource {\r
12     \r
13     public final Resource ActionContext;\r
14     public final Resource ActionContext_newDiagramContribution;\r
15     public final Resource Actions;\r
16     public final Resource Actions_NewDNDiagram;\r
17     public final Resource Composite;\r
18     public final Resource Connection;\r
19     public final Resource Diagram;\r
20     public final Resource Edge;\r
21     public final Resource HasEndVertex;\r
22     public final Resource HasEndVertex_Inverse;\r
23     public final Resource HasStartVertex;\r
24     public final Resource HasStartVertex_Inverse;\r
25     public final Resource Images;\r
26     public final Resource Images_ConfigurationFolder;\r
27     public final Resource Vertex;\r
28         \r
29     public static class URIs {\r
30         public static final String ActionContext = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext";\r
31         public static final String ActionContext_newDiagramContribution = "http://www.simantics.org/DistrictNetwork-1.0/ActionContext/newDiagramContribution";\r
32         public static final String Actions = "http://www.simantics.org/DistrictNetwork-1.0/Actions";\r
33         public static final String Actions_NewDNDiagram = "http://www.simantics.org/DistrictNetwork-1.0/Actions/NewDNDiagram";\r
34         public static final String Composite = "http://www.simantics.org/DistrictNetwork-1.0/Composite";\r
35         public static final String Connection = "http://www.simantics.org/DistrictNetwork-1.0/Connection";\r
36         public static final String Diagram = "http://www.simantics.org/DistrictNetwork-1.0/Diagram";\r
37         public static final String Edge = "http://www.simantics.org/DistrictNetwork-1.0/Edge";\r
38         public static final String HasEndVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex";\r
39         public static final String HasEndVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasEndVertex/Inverse";\r
40         public static final String HasStartVertex = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex";\r
41         public static final String HasStartVertex_Inverse = "http://www.simantics.org/DistrictNetwork-1.0/HasStartVertex/Inverse";\r
42         public static final String Images = "http://www.simantics.org/DistrictNetwork-1.0/Images";\r
43         public static final String Images_ConfigurationFolder = "http://www.simantics.org/DistrictNetwork-1.0/Images/ConfigurationFolder";\r
44         public static final String Vertex = "http://www.simantics.org/DistrictNetwork-1.0/Vertex";\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 DistrictNetworkResource(ReadGraph graph) {\r
57         ActionContext = getResourceOrNull(graph, URIs.ActionContext);\r
58         ActionContext_newDiagramContribution = getResourceOrNull(graph, URIs.ActionContext_newDiagramContribution);\r
59         Actions = getResourceOrNull(graph, URIs.Actions);\r
60         Actions_NewDNDiagram = getResourceOrNull(graph, URIs.Actions_NewDNDiagram);\r
61         Composite = getResourceOrNull(graph, URIs.Composite);\r
62         Connection = getResourceOrNull(graph, URIs.Connection);\r
63         Diagram = getResourceOrNull(graph, URIs.Diagram);\r
64         Edge = getResourceOrNull(graph, URIs.Edge);\r
65         HasEndVertex = getResourceOrNull(graph, URIs.HasEndVertex);\r
66         HasEndVertex_Inverse = getResourceOrNull(graph, URIs.HasEndVertex_Inverse);\r
67         HasStartVertex = getResourceOrNull(graph, URIs.HasStartVertex);\r
68         HasStartVertex_Inverse = getResourceOrNull(graph, URIs.HasStartVertex_Inverse);\r
69         Images = getResourceOrNull(graph, URIs.Images);\r
70         Images_ConfigurationFolder = getResourceOrNull(graph, URIs.Images_ConfigurationFolder);\r
71         Vertex = getResourceOrNull(graph, URIs.Vertex);\r
72     }\r
73     \r
74     public static DistrictNetworkResource getInstance(ReadGraph graph) {\r
75         Session session = graph.getSession();\r
76         DistrictNetworkResource ret = session.peekService(DistrictNetworkResource.class);\r
77         if(ret == null) {\r
78             QueryControl qc = graph.getService(QueryControl.class);\r
79             ret = new DistrictNetworkResource(qc.getIndependentGraph(graph));\r
80             session.registerService(DistrictNetworkResource.class, ret);\r
81         }\r
82         return ret;\r
83     }\r
84     \r
85     public static DistrictNetworkResource getInstance(RequestProcessor session) throws DatabaseException {\r
86         DistrictNetworkResource ret = session.peekService(DistrictNetworkResource.class);\r
87         if(ret == null) {\r
88             ret = session.syncRequest(new Read<DistrictNetworkResource>() {\r
89                 public DistrictNetworkResource perform(ReadGraph graph) throws DatabaseException {\r
90                     QueryControl qc = graph.getService(QueryControl.class);\r
91                     return new DistrictNetworkResource(qc.getIndependentGraph(graph));\r
92                 }\r
93             });\r
94             session.registerService(DistrictNetworkResource.class, ret);\r
95         }\r
96         return ret;\r
97     }\r
98     \r
99 }\r
100 \r