]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.district.selection/src/org/simantics/district/selection/ElementSelectionResource.java
Implementation of non-UI parts of network element queries
[simantics/district.git] / org.simantics.district.selection / src / org / simantics / district / selection / ElementSelectionResource.java
1 package org.simantics.district.selection;
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 ElementSelectionResource {
12     
13     public final Resource AggregateCondition;
14     public final Resource Condition;
15     public final Resource Condition_IsInverse;
16     public final Resource Condition_IsInverse_Inverse;
17     public final Resource Conjunction;
18     public final Resource Disjunction;
19     public final Resource ElementaryCondition;
20     public final Resource Generator;
21     public final Resource Generator_Diagram;
22     public final Resource Generator_Explicit;
23     public final Resource Generator_HasDiagram;
24     public final Resource Generator_HasDiagram_Inverse;
25     public final Resource Generator_HasSelectedElement;
26     public final Resource Generator_HasSelectedElement_Inverse;
27     public final Resource Generator_Model;
28     public final Resource HasSubcondition;
29     public final Resource HasSubcondition_Inverse;
30     public final Resource Negation;
31     public final Resource PropertyCondition;
32     public final Resource PropertyCondition_HasLowerLimit;
33     public final Resource PropertyCondition_HasLowerLimit_Inverse;
34     public final Resource PropertyCondition_HasPropertyName;
35     public final Resource PropertyCondition_HasPropertyName_Inverse;
36     public final Resource PropertyCondition_HasUpperLimit;
37     public final Resource PropertyCondition_HasUpperLimit_Inverse;
38     public final Resource PropertySelector;
39     public final Resource PropertySelector_HasResultCount;
40     public final Resource PropertySelector_HasResultCount_Inverse;
41     public final Resource PropertySelector_HasSelectionPropertyName;
42     public final Resource PropertySelector_HasSelectionPropertyName_Inverse;
43     public final Resource RegionCondition;
44     public final Resource RegionCondition_HasRegion;
45     public final Resource RegionCondition_HasRegion_Inverse;
46     public final Resource RouteCondition;
47     public final Resource RouteCondition_HasRoute;
48     public final Resource RouteCondition_HasRoute_Inverse;
49     public final Resource Selection;
50     public final Resource Selection_HasCondition;
51     public final Resource Selection_HasCondition_Inverse;
52     public final Resource Selection_HasGenerator;
53     public final Resource Selection_HasGenerator_Inverse;
54     public final Resource Selection_HasSelector;
55     public final Resource Selection_HasSelector_Inverse;
56     public final Resource Selector;
57     public final Resource Selector_All;
58     public final Resource Selector_NHighest;
59     public final Resource Selector_NLowest;
60         
61     public static class URIs {
62         public static final String AggregateCondition = "http://www.simantics.org/ElementSelection-1.0/AggregateCondition";
63         public static final String Condition = "http://www.simantics.org/ElementSelection-1.0/Condition";
64         public static final String Condition_IsInverse = "http://www.simantics.org/ElementSelection-1.0/Condition/IsInverse";
65         public static final String Condition_IsInverse_Inverse = "http://www.simantics.org/ElementSelection-1.0/Condition/IsInverse/Inverse";
66         public static final String Conjunction = "http://www.simantics.org/ElementSelection-1.0/Conjunction";
67         public static final String Disjunction = "http://www.simantics.org/ElementSelection-1.0/Disjunction";
68         public static final String ElementaryCondition = "http://www.simantics.org/ElementSelection-1.0/ElementaryCondition";
69         public static final String Generator = "http://www.simantics.org/ElementSelection-1.0/Generator";
70         public static final String Generator_Diagram = "http://www.simantics.org/ElementSelection-1.0/Generator/Diagram";
71         public static final String Generator_Explicit = "http://www.simantics.org/ElementSelection-1.0/Generator/Explicit";
72         public static final String Generator_HasDiagram = "http://www.simantics.org/ElementSelection-1.0/Generator/HasDiagram";
73         public static final String Generator_HasDiagram_Inverse = "http://www.simantics.org/ElementSelection-1.0/Generator/HasDiagram/Inverse";
74         public static final String Generator_HasSelectedElement = "http://www.simantics.org/ElementSelection-1.0/Generator/HasSelectedElement";
75         public static final String Generator_HasSelectedElement_Inverse = "http://www.simantics.org/ElementSelection-1.0/Generator/HasSelectedElement/Inverse";
76         public static final String Generator_Model = "http://www.simantics.org/ElementSelection-1.0/Generator/Model";
77         public static final String HasSubcondition = "http://www.simantics.org/ElementSelection-1.0/HasSubcondition";
78         public static final String HasSubcondition_Inverse = "http://www.simantics.org/ElementSelection-1.0/HasSubcondition/Inverse";
79         public static final String Negation = "http://www.simantics.org/ElementSelection-1.0/Negation";
80         public static final String PropertyCondition = "http://www.simantics.org/ElementSelection-1.0/PropertyCondition";
81         public static final String PropertyCondition_HasLowerLimit = "http://www.simantics.org/ElementSelection-1.0/PropertyCondition/HasLowerLimit";
82         public static final String PropertyCondition_HasLowerLimit_Inverse = "http://www.simantics.org/ElementSelection-1.0/PropertyCondition/HasLowerLimit/Inverse";
83         public static final String PropertyCondition_HasPropertyName = "http://www.simantics.org/ElementSelection-1.0/PropertyCondition/HasPropertyName";
84         public static final String PropertyCondition_HasPropertyName_Inverse = "http://www.simantics.org/ElementSelection-1.0/PropertyCondition/HasPropertyName/Inverse";
85         public static final String PropertyCondition_HasUpperLimit = "http://www.simantics.org/ElementSelection-1.0/PropertyCondition/HasUpperLimit";
86         public static final String PropertyCondition_HasUpperLimit_Inverse = "http://www.simantics.org/ElementSelection-1.0/PropertyCondition/HasUpperLimit/Inverse";
87         public static final String PropertySelector = "http://www.simantics.org/ElementSelection-1.0/PropertySelector";
88         public static final String PropertySelector_HasResultCount = "http://www.simantics.org/ElementSelection-1.0/PropertySelector/HasResultCount";
89         public static final String PropertySelector_HasResultCount_Inverse = "http://www.simantics.org/ElementSelection-1.0/PropertySelector/HasResultCount/Inverse";
90         public static final String PropertySelector_HasSelectionPropertyName = "http://www.simantics.org/ElementSelection-1.0/PropertySelector/HasSelectionPropertyName";
91         public static final String PropertySelector_HasSelectionPropertyName_Inverse = "http://www.simantics.org/ElementSelection-1.0/PropertySelector/HasSelectionPropertyName/Inverse";
92         public static final String RegionCondition = "http://www.simantics.org/ElementSelection-1.0/RegionCondition";
93         public static final String RegionCondition_HasRegion = "http://www.simantics.org/ElementSelection-1.0/RegionCondition/HasRegion";
94         public static final String RegionCondition_HasRegion_Inverse = "http://www.simantics.org/ElementSelection-1.0/RegionCondition/HasRegion/Inverse";
95         public static final String RouteCondition = "http://www.simantics.org/ElementSelection-1.0/RouteCondition";
96         public static final String RouteCondition_HasRoute = "http://www.simantics.org/ElementSelection-1.0/RouteCondition/HasRoute";
97         public static final String RouteCondition_HasRoute_Inverse = "http://www.simantics.org/ElementSelection-1.0/RouteCondition/HasRoute/Inverse";
98         public static final String Selection = "http://www.simantics.org/ElementSelection-1.0/Selection";
99         public static final String Selection_HasCondition = "http://www.simantics.org/ElementSelection-1.0/Selection/HasCondition";
100         public static final String Selection_HasCondition_Inverse = "http://www.simantics.org/ElementSelection-1.0/Selection/HasCondition/Inverse";
101         public static final String Selection_HasGenerator = "http://www.simantics.org/ElementSelection-1.0/Selection/HasGenerator";
102         public static final String Selection_HasGenerator_Inverse = "http://www.simantics.org/ElementSelection-1.0/Selection/HasGenerator/Inverse";
103         public static final String Selection_HasSelector = "http://www.simantics.org/ElementSelection-1.0/Selection/HasSelector";
104         public static final String Selection_HasSelector_Inverse = "http://www.simantics.org/ElementSelection-1.0/Selection/HasSelector/Inverse";
105         public static final String Selector = "http://www.simantics.org/ElementSelection-1.0/Selector";
106         public static final String Selector_All = "http://www.simantics.org/ElementSelection-1.0/Selector/All";
107         public static final String Selector_NHighest = "http://www.simantics.org/ElementSelection-1.0/Selector/NHighest";
108         public static final String Selector_NLowest = "http://www.simantics.org/ElementSelection-1.0/Selector/NLowest";
109     }
110     
111     public static Resource getResourceOrNull(ReadGraph graph, String uri) {
112         try {
113             return graph.getResource(uri);
114         } catch(DatabaseException e) {
115             System.err.println(e.getMessage());
116             return null;
117         }
118     }
119     
120     public ElementSelectionResource(ReadGraph graph) {
121         AggregateCondition = getResourceOrNull(graph, URIs.AggregateCondition);
122         Condition = getResourceOrNull(graph, URIs.Condition);
123         Condition_IsInverse = getResourceOrNull(graph, URIs.Condition_IsInverse);
124         Condition_IsInverse_Inverse = getResourceOrNull(graph, URIs.Condition_IsInverse_Inverse);
125         Conjunction = getResourceOrNull(graph, URIs.Conjunction);
126         Disjunction = getResourceOrNull(graph, URIs.Disjunction);
127         ElementaryCondition = getResourceOrNull(graph, URIs.ElementaryCondition);
128         Generator = getResourceOrNull(graph, URIs.Generator);
129         Generator_Diagram = getResourceOrNull(graph, URIs.Generator_Diagram);
130         Generator_Explicit = getResourceOrNull(graph, URIs.Generator_Explicit);
131         Generator_HasDiagram = getResourceOrNull(graph, URIs.Generator_HasDiagram);
132         Generator_HasDiagram_Inverse = getResourceOrNull(graph, URIs.Generator_HasDiagram_Inverse);
133         Generator_HasSelectedElement = getResourceOrNull(graph, URIs.Generator_HasSelectedElement);
134         Generator_HasSelectedElement_Inverse = getResourceOrNull(graph, URIs.Generator_HasSelectedElement_Inverse);
135         Generator_Model = getResourceOrNull(graph, URIs.Generator_Model);
136         HasSubcondition = getResourceOrNull(graph, URIs.HasSubcondition);
137         HasSubcondition_Inverse = getResourceOrNull(graph, URIs.HasSubcondition_Inverse);
138         Negation = getResourceOrNull(graph, URIs.Negation);
139         PropertyCondition = getResourceOrNull(graph, URIs.PropertyCondition);
140         PropertyCondition_HasLowerLimit = getResourceOrNull(graph, URIs.PropertyCondition_HasLowerLimit);
141         PropertyCondition_HasLowerLimit_Inverse = getResourceOrNull(graph, URIs.PropertyCondition_HasLowerLimit_Inverse);
142         PropertyCondition_HasPropertyName = getResourceOrNull(graph, URIs.PropertyCondition_HasPropertyName);
143         PropertyCondition_HasPropertyName_Inverse = getResourceOrNull(graph, URIs.PropertyCondition_HasPropertyName_Inverse);
144         PropertyCondition_HasUpperLimit = getResourceOrNull(graph, URIs.PropertyCondition_HasUpperLimit);
145         PropertyCondition_HasUpperLimit_Inverse = getResourceOrNull(graph, URIs.PropertyCondition_HasUpperLimit_Inverse);
146         PropertySelector = getResourceOrNull(graph, URIs.PropertySelector);
147         PropertySelector_HasResultCount = getResourceOrNull(graph, URIs.PropertySelector_HasResultCount);
148         PropertySelector_HasResultCount_Inverse = getResourceOrNull(graph, URIs.PropertySelector_HasResultCount_Inverse);
149         PropertySelector_HasSelectionPropertyName = getResourceOrNull(graph, URIs.PropertySelector_HasSelectionPropertyName);
150         PropertySelector_HasSelectionPropertyName_Inverse = getResourceOrNull(graph, URIs.PropertySelector_HasSelectionPropertyName_Inverse);
151         RegionCondition = getResourceOrNull(graph, URIs.RegionCondition);
152         RegionCondition_HasRegion = getResourceOrNull(graph, URIs.RegionCondition_HasRegion);
153         RegionCondition_HasRegion_Inverse = getResourceOrNull(graph, URIs.RegionCondition_HasRegion_Inverse);
154         RouteCondition = getResourceOrNull(graph, URIs.RouteCondition);
155         RouteCondition_HasRoute = getResourceOrNull(graph, URIs.RouteCondition_HasRoute);
156         RouteCondition_HasRoute_Inverse = getResourceOrNull(graph, URIs.RouteCondition_HasRoute_Inverse);
157         Selection = getResourceOrNull(graph, URIs.Selection);
158         Selection_HasCondition = getResourceOrNull(graph, URIs.Selection_HasCondition);
159         Selection_HasCondition_Inverse = getResourceOrNull(graph, URIs.Selection_HasCondition_Inverse);
160         Selection_HasGenerator = getResourceOrNull(graph, URIs.Selection_HasGenerator);
161         Selection_HasGenerator_Inverse = getResourceOrNull(graph, URIs.Selection_HasGenerator_Inverse);
162         Selection_HasSelector = getResourceOrNull(graph, URIs.Selection_HasSelector);
163         Selection_HasSelector_Inverse = getResourceOrNull(graph, URIs.Selection_HasSelector_Inverse);
164         Selector = getResourceOrNull(graph, URIs.Selector);
165         Selector_All = getResourceOrNull(graph, URIs.Selector_All);
166         Selector_NHighest = getResourceOrNull(graph, URIs.Selector_NHighest);
167         Selector_NLowest = getResourceOrNull(graph, URIs.Selector_NLowest);
168     }
169     
170     public static ElementSelectionResource getInstance(ReadGraph graph) {
171         Session session = graph.getSession();
172         ElementSelectionResource ret = session.peekService(ElementSelectionResource.class);
173         if(ret == null) {
174             QueryControl qc = graph.getService(QueryControl.class);
175             ret = new ElementSelectionResource(qc.getIndependentGraph(graph));
176             session.registerService(ElementSelectionResource.class, ret);
177         }
178         return ret;
179     }
180     
181     public static ElementSelectionResource getInstance(RequestProcessor session) throws DatabaseException {
182         ElementSelectionResource ret = session.peekService(ElementSelectionResource.class);
183         if(ret == null) {
184             ret = session.syncRequest(new Read<ElementSelectionResource>() {
185                 public ElementSelectionResource perform(ReadGraph graph) throws DatabaseException {
186                     QueryControl qc = graph.getService(QueryControl.class);
187                     return new ElementSelectionResource(qc.getIndependentGraph(graph));
188                 }
189             });
190             session.registerService(ElementSelectionResource.class, ret);
191         }
192         return ret;
193     }
194     
195 }
196