]> gerrit.simantics Code Review - simantics/platform.git/blob
7849e4da3bed1b7d81a75a37a69faf4f376161f7
[simantics/platform.git] /
1 package org.simantics.scenegraph.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 ScenegraphResources {
12     
13     public final Resource Functions;
14     public final Resource Functions_defaultRuntimeResource;
15     public final Resource Functions_defaultRuntimeVariable;
16     public final Resource Functions_liftedProperty;
17     public final Resource Functions_singleVariableSelection;
18     public final Resource LiftedProperty;
19     public final Resource LiftedPropertyRelation;
20     public final Resource LiftedProperty_HasPredicate;
21     public final Resource LiftedProperty_HasPredicate_Inverse;
22     public final Resource Node;
23     public final Resource Node_HasProperty;
24     public final Resource Node_HasProperty_Inverse;
25     public final Resource Node_children;
26     public final Resource Node_children_Inverse;
27     public final Resource Runtime;
28     public final Resource Runtime_HasResource;
29     public final Resource Runtime_HasResource_Inverse;
30     public final Resource Runtime_HasVariable;
31     public final Resource Runtime_HasVariable_Inverse;
32     public final Resource Runtime_resource;
33     public final Resource Runtime_resource_Inverse;
34     public final Resource Runtime_variable;
35     public final Resource Runtime_variable_Inverse;
36     public final Resource lifted;
37     public final Resource userProperty;
38     public final Resource userProperty_Inverse;
39         
40     public static class URIs {
41         public static final String Functions = "http://www.simantics.org/Scenegraph-1.1/Functions";
42         public static final String Functions_defaultRuntimeResource = "http://www.simantics.org/Scenegraph-1.1/Functions/defaultRuntimeResource";
43         public static final String Functions_defaultRuntimeVariable = "http://www.simantics.org/Scenegraph-1.1/Functions/defaultRuntimeVariable";
44         public static final String Functions_liftedProperty = "http://www.simantics.org/Scenegraph-1.1/Functions/liftedProperty";
45         public static final String Functions_singleVariableSelection = "http://www.simantics.org/Scenegraph-1.1/Functions/singleVariableSelection";
46         public static final String LiftedProperty = "http://www.simantics.org/Scenegraph-1.1/LiftedProperty";
47         public static final String LiftedPropertyRelation = "http://www.simantics.org/Scenegraph-1.1/LiftedPropertyRelation";
48         public static final String LiftedProperty_HasPredicate = "http://www.simantics.org/Scenegraph-1.1/LiftedProperty/HasPredicate";
49         public static final String LiftedProperty_HasPredicate_Inverse = "http://www.simantics.org/Scenegraph-1.1/LiftedProperty/HasPredicate/Inverse";
50         public static final String Node = "http://www.simantics.org/Scenegraph-1.1/Node";
51         public static final String Node_HasProperty = "http://www.simantics.org/Scenegraph-1.1/Node/HasProperty";
52         public static final String Node_HasProperty_Inverse = "http://www.simantics.org/Scenegraph-1.1/Node/HasProperty/Inverse";
53         public static final String Node_children = "http://www.simantics.org/Scenegraph-1.1/Node/children";
54         public static final String Node_children_Inverse = "http://www.simantics.org/Scenegraph-1.1/Node/children/Inverse";
55         public static final String Runtime = "http://www.simantics.org/Scenegraph-1.1/Runtime";
56         public static final String Runtime_HasResource = "http://www.simantics.org/Scenegraph-1.1/Runtime/HasResource";
57         public static final String Runtime_HasResource_Inverse = "http://www.simantics.org/Scenegraph-1.1/Runtime/HasResource/Inverse";
58         public static final String Runtime_HasVariable = "http://www.simantics.org/Scenegraph-1.1/Runtime/HasVariable";
59         public static final String Runtime_HasVariable_Inverse = "http://www.simantics.org/Scenegraph-1.1/Runtime/HasVariable/Inverse";
60         public static final String Runtime_resource = "http://www.simantics.org/Scenegraph-1.1/Runtime/resource";
61         public static final String Runtime_resource_Inverse = "http://www.simantics.org/Scenegraph-1.1/Runtime/resource/Inverse";
62         public static final String Runtime_variable = "http://www.simantics.org/Scenegraph-1.1/Runtime/variable";
63         public static final String Runtime_variable_Inverse = "http://www.simantics.org/Scenegraph-1.1/Runtime/variable/Inverse";
64         public static final String lifted = "http://www.simantics.org/Scenegraph-1.1/lifted";
65         public static final String userProperty = "http://www.simantics.org/Scenegraph-1.1/userProperty";
66         public static final String userProperty_Inverse = "http://www.simantics.org/Scenegraph-1.1/userProperty/Inverse";
67     }
68     
69     public static Resource getResourceOrNull(ReadGraph graph, String uri) {
70         try {
71             return graph.getResource(uri);
72         } catch(DatabaseException e) {
73             System.err.println(e.getMessage());
74             return null;
75         }
76     }
77     
78     public ScenegraphResources(ReadGraph graph) {
79         Functions = getResourceOrNull(graph, URIs.Functions);
80         Functions_defaultRuntimeResource = getResourceOrNull(graph, URIs.Functions_defaultRuntimeResource);
81         Functions_defaultRuntimeVariable = getResourceOrNull(graph, URIs.Functions_defaultRuntimeVariable);
82         Functions_liftedProperty = getResourceOrNull(graph, URIs.Functions_liftedProperty);
83         Functions_singleVariableSelection = getResourceOrNull(graph, URIs.Functions_singleVariableSelection);
84         LiftedProperty = getResourceOrNull(graph, URIs.LiftedProperty);
85         LiftedPropertyRelation = getResourceOrNull(graph, URIs.LiftedPropertyRelation);
86         LiftedProperty_HasPredicate = getResourceOrNull(graph, URIs.LiftedProperty_HasPredicate);
87         LiftedProperty_HasPredicate_Inverse = getResourceOrNull(graph, URIs.LiftedProperty_HasPredicate_Inverse);
88         Node = getResourceOrNull(graph, URIs.Node);
89         Node_HasProperty = getResourceOrNull(graph, URIs.Node_HasProperty);
90         Node_HasProperty_Inverse = getResourceOrNull(graph, URIs.Node_HasProperty_Inverse);
91         Node_children = getResourceOrNull(graph, URIs.Node_children);
92         Node_children_Inverse = getResourceOrNull(graph, URIs.Node_children_Inverse);
93         Runtime = getResourceOrNull(graph, URIs.Runtime);
94         Runtime_HasResource = getResourceOrNull(graph, URIs.Runtime_HasResource);
95         Runtime_HasResource_Inverse = getResourceOrNull(graph, URIs.Runtime_HasResource_Inverse);
96         Runtime_HasVariable = getResourceOrNull(graph, URIs.Runtime_HasVariable);
97         Runtime_HasVariable_Inverse = getResourceOrNull(graph, URIs.Runtime_HasVariable_Inverse);
98         Runtime_resource = getResourceOrNull(graph, URIs.Runtime_resource);
99         Runtime_resource_Inverse = getResourceOrNull(graph, URIs.Runtime_resource_Inverse);
100         Runtime_variable = getResourceOrNull(graph, URIs.Runtime_variable);
101         Runtime_variable_Inverse = getResourceOrNull(graph, URIs.Runtime_variable_Inverse);
102         lifted = getResourceOrNull(graph, URIs.lifted);
103         userProperty = getResourceOrNull(graph, URIs.userProperty);
104         userProperty_Inverse = getResourceOrNull(graph, URIs.userProperty_Inverse);
105     }
106     
107     public static ScenegraphResources getInstance(ReadGraph graph) {
108         Session session = graph.getSession();
109         ScenegraphResources ret = session.peekService(ScenegraphResources.class);
110         if(ret == null) {
111             QueryControl qc = graph.getService(QueryControl.class);
112             ret = new ScenegraphResources(qc.getIndependentGraph(graph));
113             session.registerService(ScenegraphResources.class, ret);
114         }
115         return ret;
116     }
117     
118     public static ScenegraphResources getInstance(RequestProcessor session) throws DatabaseException {
119         ScenegraphResources ret = session.peekService(ScenegraphResources.class);
120         if(ret == null) {
121             ret = session.syncRequest(new Read<ScenegraphResources>() {
122                 public ScenegraphResources perform(ReadGraph graph) throws DatabaseException {
123                     QueryControl qc = graph.getService(QueryControl.class);
124                     return new ScenegraphResources(qc.getIndependentGraph(graph));
125                 }
126             });
127             session.registerService(ScenegraphResources.class, ret);
128         }
129         return ret;
130     }
131     
132 }
133