]> gerrit.simantics Code Review - simantics/platform.git/blob
24955a251ced53db9fd0155167b04b71f71eae76
[simantics/platform.git] /
1 package org.simantics.simulation.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 SimulationResource {
12     
13     public final Resource ActiveExperiment;
14     public final Resource Experiment;
15     public final Resource ExperimentState;
16     public final Resource ExperimentState_Disposed;
17     public final Resource ExperimentState_Initializing;
18     public final Resource ExperimentState_Running;
19     public final Resource ExperimentState_Stopped;
20     public final Resource HasActivationTime;
21     public final Resource HasActivationTime_Inverse;
22     public final Resource HasActiveExperiment;
23     public final Resource HasActiveExperiment_Inverse;
24     public final Resource HasConfiguration;
25     public final Resource HasDevsComponent;
26     public final Resource HasExperimentState;
27     public final Resource HasInitialState;
28     public final Resource HasInitialState_Inverse;
29     public final Resource HasState;
30     public final Resource HasState_Inverse;
31     public final Resource History;
32     public final Resource History_History;
33     public final Resource History_History_Item;
34     public final Resource History_History_Item_Bias;
35     public final Resource History_History_Item_Bias_Inverse;
36     public final Resource History_History_Item_CollectorState;
37     public final Resource History_History_Item_CollectorState_Inverse;
38     public final Resource History_History_Item_Deadband;
39     public final Resource History_History_Item_Deadband_Inverse;
40     public final Resource History_History_Item_Enabled;
41     public final Resource History_History_Item_Enabled_Inverse;
42     public final Resource History_History_Item_Format;
43     public final Resource History_History_Item_FormatId;
44     public final Resource History_History_Item_FormatId_Inverse;
45     public final Resource History_History_Item_Format_Inverse;
46     public final Resource History_History_Item_Gain;
47     public final Resource History_History_Item_Gain_Inverse;
48     public final Resource History_History_Item_GroupId;
49     public final Resource History_History_Item_GroupId_Inverse;
50     public final Resource History_History_Item_GroupItemId;
51     public final Resource History_History_Item_GroupItemId_Inverse;
52     public final Resource History_History_Item_Info;
53     public final Resource History_History_Item_Info_Inverse;
54     public final Resource History_History_Item_Interval;
55     public final Resource History_History_Item_Interval_Inverse;
56     public final Resource History_History_Item_Series;
57     public final Resource History_History_Item_Series_Inverse;
58     public final Resource History_History_Item_VariableId;
59     public final Resource History_History_Item_VariableId_Inverse;
60     public final Resource History_History_Item_size;
61     public final Resource History_History_Item_size_Inverse;
62     public final Resource History_History_archive;
63     public final Resource History_History_archive_Inverse;
64     public final Resource History_History_size;
65     public final Resource History_History_size_Inverse;
66     public final Resource IsActive;
67     public final Resource IsConfigurationOf;
68     public final Resource Model;
69     public final Resource Run;
70     public final Resource RunType;
71     public final Resource Run_iExperiment;
72     public final Resource Run_iExperiment_Inverse;
73     public final Resource State;
74     public final Resource State_History;
75     public final Resource State_History_Inverse;
76         
77     public static class URIs {
78         public static final String ActiveExperiment = "http://www.simantics.org/Simulation-1.1/ActiveExperiment";
79         public static final String Experiment = "http://www.simantics.org/Simulation-1.1/Experiment";
80         public static final String ExperimentState = "http://www.simantics.org/Simulation-1.1/ExperimentState";
81         public static final String ExperimentState_Disposed = "http://www.simantics.org/Simulation-1.1/ExperimentState/Disposed";
82         public static final String ExperimentState_Initializing = "http://www.simantics.org/Simulation-1.1/ExperimentState/Initializing";
83         public static final String ExperimentState_Running = "http://www.simantics.org/Simulation-1.1/ExperimentState/Running";
84         public static final String ExperimentState_Stopped = "http://www.simantics.org/Simulation-1.1/ExperimentState/Stopped";
85         public static final String HasActivationTime = "http://www.simantics.org/Simulation-1.1/HasActivationTime";
86         public static final String HasActivationTime_Inverse = "http://www.simantics.org/Simulation-1.1/HasActivationTime/Inverse";
87         public static final String HasActiveExperiment = "http://www.simantics.org/Simulation-1.1/HasActiveExperiment";
88         public static final String HasActiveExperiment_Inverse = "http://www.simantics.org/Simulation-1.1/HasActiveExperiment/Inverse";
89         public static final String HasConfiguration = "http://www.simantics.org/Simulation-1.1/HasConfiguration";
90         public static final String HasDevsComponent = "http://www.simantics.org/Simulation-1.1/HasDevsComponent";
91         public static final String HasExperimentState = "http://www.simantics.org/Simulation-1.1/HasExperimentState";
92         public static final String HasInitialState = "http://www.simantics.org/Simulation-1.1/HasInitialState";
93         public static final String HasInitialState_Inverse = "http://www.simantics.org/Simulation-1.1/HasInitialState/Inverse";
94         public static final String HasState = "http://www.simantics.org/Simulation-1.1/HasState";
95         public static final String HasState_Inverse = "http://www.simantics.org/Simulation-1.1/HasState/Inverse";
96         public static final String History = "http://www.simantics.org/Simulation-1.1/History";
97         public static final String History_History = "http://www.simantics.org/Simulation-1.1/History/History";
98         public static final String History_History_Item = "http://www.simantics.org/Simulation-1.1/History/History/Item";
99         public static final String History_History_Item_Bias = "http://www.simantics.org/Simulation-1.1/History/History/Item/Bias";
100         public static final String History_History_Item_Bias_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/Item/Bias/Inverse";
101         public static final String History_History_Item_CollectorState = "http://www.simantics.org/Simulation-1.1/History/History/Item/CollectorState";
102         public static final String History_History_Item_CollectorState_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/Item/CollectorState/Inverse";
103         public static final String History_History_Item_Deadband = "http://www.simantics.org/Simulation-1.1/History/History/Item/Deadband";
104         public static final String History_History_Item_Deadband_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/Item/Deadband/Inverse";
105         public static final String History_History_Item_Enabled = "http://www.simantics.org/Simulation-1.1/History/History/Item/Enabled";
106         public static final String History_History_Item_Enabled_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/Item/Enabled/Inverse";
107         public static final String History_History_Item_Format = "http://www.simantics.org/Simulation-1.1/History/History/Item/Format";
108         public static final String History_History_Item_FormatId = "http://www.simantics.org/Simulation-1.1/History/History/Item/FormatId";
109         public static final String History_History_Item_FormatId_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/Item/FormatId/Inverse";
110         public static final String History_History_Item_Format_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/Item/Format/Inverse";
111         public static final String History_History_Item_Gain = "http://www.simantics.org/Simulation-1.1/History/History/Item/Gain";
112         public static final String History_History_Item_Gain_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/Item/Gain/Inverse";
113         public static final String History_History_Item_GroupId = "http://www.simantics.org/Simulation-1.1/History/History/Item/GroupId";
114         public static final String History_History_Item_GroupId_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/Item/GroupId/Inverse";
115         public static final String History_History_Item_GroupItemId = "http://www.simantics.org/Simulation-1.1/History/History/Item/GroupItemId";
116         public static final String History_History_Item_GroupItemId_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/Item/GroupItemId/Inverse";
117         public static final String History_History_Item_Info = "http://www.simantics.org/Simulation-1.1/History/History/Item/Info";
118         public static final String History_History_Item_Info_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/Item/Info/Inverse";
119         public static final String History_History_Item_Interval = "http://www.simantics.org/Simulation-1.1/History/History/Item/Interval";
120         public static final String History_History_Item_Interval_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/Item/Interval/Inverse";
121         public static final String History_History_Item_Series = "http://www.simantics.org/Simulation-1.1/History/History/Item/Series";
122         public static final String History_History_Item_Series_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/Item/Series/Inverse";
123         public static final String History_History_Item_VariableId = "http://www.simantics.org/Simulation-1.1/History/History/Item/VariableId";
124         public static final String History_History_Item_VariableId_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/Item/VariableId/Inverse";
125         public static final String History_History_Item_size = "http://www.simantics.org/Simulation-1.1/History/History/Item/size";
126         public static final String History_History_Item_size_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/Item/size/Inverse";
127         public static final String History_History_archive = "http://www.simantics.org/Simulation-1.1/History/History/archive";
128         public static final String History_History_archive_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/archive/Inverse";
129         public static final String History_History_size = "http://www.simantics.org/Simulation-1.1/History/History/size";
130         public static final String History_History_size_Inverse = "http://www.simantics.org/Simulation-1.1/History/History/size/Inverse";
131         public static final String IsActive = "http://www.simantics.org/Simulation-1.1/IsActive";
132         public static final String IsConfigurationOf = "http://www.simantics.org/Simulation-1.1/IsConfigurationOf";
133         public static final String Model = "http://www.simantics.org/Simulation-1.1/Model";
134         public static final String Run = "http://www.simantics.org/Simulation-1.1/Run";
135         public static final String RunType = "http://www.simantics.org/Simulation-1.1/RunType";
136         public static final String Run_iExperiment = "http://www.simantics.org/Simulation-1.1/Run/iExperiment";
137         public static final String Run_iExperiment_Inverse = "http://www.simantics.org/Simulation-1.1/Run/iExperiment/Inverse";
138         public static final String State = "http://www.simantics.org/Simulation-1.1/State";
139         public static final String State_History = "http://www.simantics.org/Simulation-1.1/State/History";
140         public static final String State_History_Inverse = "http://www.simantics.org/Simulation-1.1/State/History/Inverse";
141     }
142     
143     public static Resource getResourceOrNull(ReadGraph graph, String uri) {
144         try {
145             return graph.getResource(uri);
146         } catch(DatabaseException e) {
147             System.err.println(e.getMessage());
148             return null;
149         }
150     }
151     
152     public SimulationResource(ReadGraph graph) {
153         ActiveExperiment = getResourceOrNull(graph, URIs.ActiveExperiment);
154         Experiment = getResourceOrNull(graph, URIs.Experiment);
155         ExperimentState = getResourceOrNull(graph, URIs.ExperimentState);
156         ExperimentState_Disposed = getResourceOrNull(graph, URIs.ExperimentState_Disposed);
157         ExperimentState_Initializing = getResourceOrNull(graph, URIs.ExperimentState_Initializing);
158         ExperimentState_Running = getResourceOrNull(graph, URIs.ExperimentState_Running);
159         ExperimentState_Stopped = getResourceOrNull(graph, URIs.ExperimentState_Stopped);
160         HasActivationTime = getResourceOrNull(graph, URIs.HasActivationTime);
161         HasActivationTime_Inverse = getResourceOrNull(graph, URIs.HasActivationTime_Inverse);
162         HasActiveExperiment = getResourceOrNull(graph, URIs.HasActiveExperiment);
163         HasActiveExperiment_Inverse = getResourceOrNull(graph, URIs.HasActiveExperiment_Inverse);
164         HasConfiguration = getResourceOrNull(graph, URIs.HasConfiguration);
165         HasDevsComponent = getResourceOrNull(graph, URIs.HasDevsComponent);
166         HasExperimentState = getResourceOrNull(graph, URIs.HasExperimentState);
167         HasInitialState = getResourceOrNull(graph, URIs.HasInitialState);
168         HasInitialState_Inverse = getResourceOrNull(graph, URIs.HasInitialState_Inverse);
169         HasState = getResourceOrNull(graph, URIs.HasState);
170         HasState_Inverse = getResourceOrNull(graph, URIs.HasState_Inverse);
171         History = getResourceOrNull(graph, URIs.History);
172         History_History = getResourceOrNull(graph, URIs.History_History);
173         History_History_Item = getResourceOrNull(graph, URIs.History_History_Item);
174         History_History_Item_Bias = getResourceOrNull(graph, URIs.History_History_Item_Bias);
175         History_History_Item_Bias_Inverse = getResourceOrNull(graph, URIs.History_History_Item_Bias_Inverse);
176         History_History_Item_CollectorState = getResourceOrNull(graph, URIs.History_History_Item_CollectorState);
177         History_History_Item_CollectorState_Inverse = getResourceOrNull(graph, URIs.History_History_Item_CollectorState_Inverse);
178         History_History_Item_Deadband = getResourceOrNull(graph, URIs.History_History_Item_Deadband);
179         History_History_Item_Deadband_Inverse = getResourceOrNull(graph, URIs.History_History_Item_Deadband_Inverse);
180         History_History_Item_Enabled = getResourceOrNull(graph, URIs.History_History_Item_Enabled);
181         History_History_Item_Enabled_Inverse = getResourceOrNull(graph, URIs.History_History_Item_Enabled_Inverse);
182         History_History_Item_Format = getResourceOrNull(graph, URIs.History_History_Item_Format);
183         History_History_Item_FormatId = getResourceOrNull(graph, URIs.History_History_Item_FormatId);
184         History_History_Item_FormatId_Inverse = getResourceOrNull(graph, URIs.History_History_Item_FormatId_Inverse);
185         History_History_Item_Format_Inverse = getResourceOrNull(graph, URIs.History_History_Item_Format_Inverse);
186         History_History_Item_Gain = getResourceOrNull(graph, URIs.History_History_Item_Gain);
187         History_History_Item_Gain_Inverse = getResourceOrNull(graph, URIs.History_History_Item_Gain_Inverse);
188         History_History_Item_GroupId = getResourceOrNull(graph, URIs.History_History_Item_GroupId);
189         History_History_Item_GroupId_Inverse = getResourceOrNull(graph, URIs.History_History_Item_GroupId_Inverse);
190         History_History_Item_GroupItemId = getResourceOrNull(graph, URIs.History_History_Item_GroupItemId);
191         History_History_Item_GroupItemId_Inverse = getResourceOrNull(graph, URIs.History_History_Item_GroupItemId_Inverse);
192         History_History_Item_Info = getResourceOrNull(graph, URIs.History_History_Item_Info);
193         History_History_Item_Info_Inverse = getResourceOrNull(graph, URIs.History_History_Item_Info_Inverse);
194         History_History_Item_Interval = getResourceOrNull(graph, URIs.History_History_Item_Interval);
195         History_History_Item_Interval_Inverse = getResourceOrNull(graph, URIs.History_History_Item_Interval_Inverse);
196         History_History_Item_Series = getResourceOrNull(graph, URIs.History_History_Item_Series);
197         History_History_Item_Series_Inverse = getResourceOrNull(graph, URIs.History_History_Item_Series_Inverse);
198         History_History_Item_VariableId = getResourceOrNull(graph, URIs.History_History_Item_VariableId);
199         History_History_Item_VariableId_Inverse = getResourceOrNull(graph, URIs.History_History_Item_VariableId_Inverse);
200         History_History_Item_size = getResourceOrNull(graph, URIs.History_History_Item_size);
201         History_History_Item_size_Inverse = getResourceOrNull(graph, URIs.History_History_Item_size_Inverse);
202         History_History_archive = getResourceOrNull(graph, URIs.History_History_archive);
203         History_History_archive_Inverse = getResourceOrNull(graph, URIs.History_History_archive_Inverse);
204         History_History_size = getResourceOrNull(graph, URIs.History_History_size);
205         History_History_size_Inverse = getResourceOrNull(graph, URIs.History_History_size_Inverse);
206         IsActive = getResourceOrNull(graph, URIs.IsActive);
207         IsConfigurationOf = getResourceOrNull(graph, URIs.IsConfigurationOf);
208         Model = getResourceOrNull(graph, URIs.Model);
209         Run = getResourceOrNull(graph, URIs.Run);
210         RunType = getResourceOrNull(graph, URIs.RunType);
211         Run_iExperiment = getResourceOrNull(graph, URIs.Run_iExperiment);
212         Run_iExperiment_Inverse = getResourceOrNull(graph, URIs.Run_iExperiment_Inverse);
213         State = getResourceOrNull(graph, URIs.State);
214         State_History = getResourceOrNull(graph, URIs.State_History);
215         State_History_Inverse = getResourceOrNull(graph, URIs.State_History_Inverse);
216     }
217     
218     public static SimulationResource getInstance(ReadGraph graph) {
219         Session session = graph.getSession();
220         SimulationResource ret = session.peekService(SimulationResource.class);
221         if(ret == null) {
222             QueryControl qc = graph.getService(QueryControl.class);
223             ret = new SimulationResource(qc.getIndependentGraph(graph));
224             session.registerService(SimulationResource.class, ret);
225         }
226         return ret;
227     }
228     
229     public static SimulationResource getInstance(RequestProcessor session) throws DatabaseException {
230         SimulationResource ret = session.peekService(SimulationResource.class);
231         if(ret == null) {
232             ret = session.syncRequest(new Read<SimulationResource>() {
233                 public SimulationResource perform(ReadGraph graph) throws DatabaseException {
234                     QueryControl qc = graph.getService(QueryControl.class);
235                     return new SimulationResource(qc.getIndependentGraph(graph));
236                 }
237             });
238             session.registerService(SimulationResource.class, ret);
239         }
240         return ret;
241     }
242     
243 }
244