]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ValueProxyVariable.java
Merge commit 'ad8333027322fda6b9a8a524c7a7e15a54c52f38'
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / ValueProxyVariable.java
1 package org.simantics.db.layer0.variable;\r
2 \r
3 import java.util.Collection;\r
4 import java.util.Collections;\r
5 import java.util.Set;\r
6 \r
7 import org.simantics.databoard.binding.Binding;\r
8 import org.simantics.databoard.binding.mutable.Variant;\r
9 import org.simantics.databoard.type.Datatype;\r
10 import org.simantics.db.ReadGraph;\r
11 import org.simantics.db.Resource;\r
12 import org.simantics.db.WriteGraph;\r
13 import org.simantics.db.common.utils.NameUtils;\r
14 import org.simantics.db.exception.DatabaseException;\r
15 import org.simantics.db.layer0.request.PropertyInfo;\r
16 import org.simantics.db.layer0.variable.RVI.RVIPart;\r
17 import org.simantics.db.layer0.variable.Variables.Role;\r
18 \r
19 /**\r
20  * An abstract base proxy implementation for value container variables that are\r
21  * leaves of the variable tree. This means by default the variable has no\r
22  * support for children or properties, only for returning a single value that it\r
23  * wraps.\r
24  * \r
25  * @author Tuukka Lehtonen\r
26  */\r
27 public abstract class ValueProxyVariable implements Variable {\r
28 \r
29         protected final Variable proxy;\r
30         protected final Variable parent;\r
31 \r
32         public ValueProxyVariable(Variable proxy, Variable parent) {\r
33                 if (proxy == null)\r
34                         throw new NullPointerException("null proxy");\r
35                 if (parent == null)\r
36                         throw new NullPointerException("null parent");\r
37                 this.parent = parent;\r
38                 this.proxy = proxy;\r
39         }\r
40 \r
41         @Override\r
42         public <T> T getPropertyValue(ReadGraph graph, String name) throws DatabaseException {\r
43                 throw new DatabaseException("Could not resolve property " + name);\r
44         }\r
45 \r
46         @Override\r
47         public <T> T getPropertyValue(ReadGraph graph, Resource property) throws DatabaseException {\r
48                 throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));\r
49         }\r
50 \r
51         @Override\r
52         public <T> T getPossiblePropertyValue(ReadGraph graph, String name) throws DatabaseException {\r
53                 throw new DatabaseException("Could not resolve property " + name);\r
54         }\r
55 \r
56         @Override\r
57         public <T> T getPossiblePropertyValue(ReadGraph graph, Resource property) throws DatabaseException {\r
58                 throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));\r
59         }\r
60 \r
61         @Override\r
62         public <T> T getPropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException {\r
63                 throw new DatabaseException("Could not resolve property " + name);\r
64         }\r
65 \r
66         @Override\r
67         public <T> T getPropertyValue(ReadGraph graph, Resource property, Binding binding) throws DatabaseException {\r
68                 throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));\r
69         }\r
70 \r
71         @Override\r
72         public <T> T getPossiblePropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException {\r
73                 throw new DatabaseException("Could not resolve property " + name);\r
74         }\r
75 \r
76         @Override\r
77         public <T> T getPossiblePropertyValue(ReadGraph graph, Resource property, Binding binding) throws DatabaseException {\r
78                 return proxy.getPossiblePropertyValue(graph, property, binding);\r
79         }\r
80 \r
81         @Override\r
82         public PropertyInfo getPropertyInfo(ReadGraph graph) throws DatabaseException {\r
83                 return proxy.getPropertyInfo(graph);\r
84         }\r
85         \r
86         @Override\r
87         public Resource getIndexRoot(ReadGraph graph) throws DatabaseException {\r
88                 return proxy.getIndexRoot(graph);\r
89         }\r
90         \r
91         @Override\r
92         public abstract <T> T getValue(ReadGraph graph) throws DatabaseException;\r
93 \r
94         @Override\r
95         public abstract <T> T getPossibleValue(ReadGraph graph) throws DatabaseException;\r
96 \r
97         @Override\r
98         public abstract <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException;\r
99 \r
100         @Override\r
101         public abstract <T> T getPossibleValue(ReadGraph graph, Binding binding) throws DatabaseException;\r
102 \r
103         @Override\r
104         public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException {\r
105                 throw new DatabaseException("Not supported");\r
106         }\r
107 \r
108         @Override\r
109         public void setValue(WriteGraph graph, Object value) throws DatabaseException {\r
110                 throw new DatabaseException("Not supported");\r
111         }\r
112 \r
113         @Override\r
114         public void setPropertyValue(WriteGraph graph, String name, Object value, Binding binding) throws DatabaseException {\r
115                 throw new DatabaseException("Not supported");\r
116         }\r
117 \r
118         @Override\r
119         public void setPropertyValue(WriteGraph graph, Resource property, Object value, Binding binding) throws DatabaseException {\r
120                 throw new DatabaseException("Not supported");\r
121         }\r
122 \r
123         @Override\r
124         public void setPropertyValue(WriteGraph graph, String name, Object value) throws DatabaseException {\r
125                 throw new DatabaseException("Not supported");\r
126         }\r
127 \r
128         @Override\r
129         public void setPropertyValue(WriteGraph graph, Resource property, Object value) throws DatabaseException {\r
130                 throw new DatabaseException("Not supported");\r
131         }\r
132 \r
133         @Override\r
134         public Variable getChild(ReadGraph graph, String name) throws DatabaseException {\r
135                 throw new DatabaseException("Could not resolve child " + name);\r
136         }\r
137 \r
138         @Override\r
139         public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {\r
140                 return null;\r
141         }\r
142 \r
143         @Override\r
144         public Variable getProperty(ReadGraph graph, String name) throws DatabaseException {\r
145                 throw new DatabaseException("Could not resolve property " + name);\r
146         }\r
147 \r
148         @Override\r
149         public Variable getProperty(ReadGraph graph, Resource property) throws DatabaseException {\r
150                 throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));\r
151         }\r
152 \r
153         @Override\r
154         public Variable getPossibleProperty(ReadGraph graph, String name) throws DatabaseException {\r
155                 return null;\r
156         }\r
157 \r
158         @Override\r
159         public Variable getPossibleProperty(ReadGraph graph, Resource property) throws DatabaseException {\r
160                 return null;\r
161         }\r
162 \r
163         @Override\r
164         public Collection<Variable> browseChildren(ReadGraph graph) throws DatabaseException {\r
165                 return getChildren(graph);\r
166         }\r
167 \r
168         @Override\r
169         public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {\r
170                 return Collections.emptyList();\r
171         }\r
172 \r
173         @Override\r
174         public Collection<Variable> browseProperties(ReadGraph graph) throws DatabaseException {\r
175                 return getProperties(graph);\r
176         }\r
177 \r
178         @Override\r
179         public Collection<Variable> getProperties(ReadGraph graph) throws DatabaseException {\r
180                 return Collections.emptyList();\r
181         }\r
182 \r
183         @Override\r
184         public Collection<Variable> getProperties(ReadGraph graph, String classification) throws DatabaseException {\r
185                 return Collections.emptyList();\r
186         }\r
187 \r
188         @Override\r
189         public Collection<Variable> getProperties(ReadGraph graph, Resource classification) throws DatabaseException {\r
190                 return Collections.emptyList();\r
191         }\r
192 \r
193         @Override\r
194         public Variable browse(ReadGraph graph, String suffix) throws DatabaseException {\r
195                 if (suffix.isEmpty())\r
196                         return this;\r
197                 throw new DatabaseException("Could not browse with suffix '" + suffix + "'");\r
198         }\r
199 \r
200         @Override\r
201         public Variable browsePossible(ReadGraph graph, String suffix) throws DatabaseException {\r
202                 if (suffix.isEmpty())\r
203                         return this;\r
204                 return null;\r
205         }\r
206 \r
207         @Override\r
208         public Variable browse(ReadGraph graph, Resource config) throws DatabaseException {\r
209                 throw new DatabaseException("Could not browse '" + NameUtils.getSafeName(graph, config, true) + "'");\r
210         }\r
211 \r
212         @Override\r
213         public Variable browsePossible(ReadGraph graph, Resource config) throws DatabaseException {\r
214                 return null;\r
215         }\r
216 \r
217         @Override\r
218         public <T> T getInterface(ReadGraph graph, Class<T> clazz) throws DatabaseException {\r
219                 return null;\r
220         }\r
221 \r
222         @Override\r
223         public <T> T adapt(ReadGraph graph, Class<T> clazz) throws DatabaseException {\r
224                 return null;\r
225         }\r
226 \r
227         @Override\r
228         public <T> T adaptPossible(ReadGraph graph, Class<T> clazz) throws DatabaseException {\r
229                 return null;\r
230         }\r
231 \r
232         @Override\r
233         public abstract String getURI(ReadGraph graph) throws DatabaseException;\r
234 \r
235         @Override\r
236         public abstract int hashCode();\r
237 \r
238         @Override\r
239         public abstract boolean equals(Object obj);\r
240 \r
241         @Override\r
242         public Variable resolve(ReadGraph graph, RVIPart part) throws DatabaseException {\r
243                 throw new DatabaseException("not supported");\r
244         }\r
245 \r
246         @Override\r
247         public Variable resolvePossible(ReadGraph graph, RVIPart part) throws DatabaseException {\r
248                 return null;\r
249         }\r
250 \r
251         @Override\r
252         public abstract String getName(ReadGraph graph) throws DatabaseException;\r
253 \r
254         @Override\r
255         public String getLabel(ReadGraph graph) throws DatabaseException {\r
256                 throw new DatabaseException("not supported");\r
257         }\r
258 \r
259         @Override\r
260         public abstract Datatype getDatatype(ReadGraph graph) throws DatabaseException;\r
261 \r
262         @Override\r
263         public Datatype getPossibleDatatype(ReadGraph graph) throws DatabaseException {\r
264                 try {\r
265                         return getDatatype(graph);\r
266                 } catch (DatabaseException e) {\r
267                         return null;\r
268                 }\r
269         }\r
270 \r
271         @Override\r
272         public Variable getPredicate(ReadGraph graph) throws DatabaseException {\r
273                 throw new DatabaseException("not supported");\r
274         }\r
275 \r
276         @Override\r
277         public Variable getPossiblePredicate(ReadGraph graph) throws DatabaseException {\r
278                 throw new DatabaseException("not supported");\r
279         }\r
280 \r
281         @Override\r
282         public Resource getPredicateResource(ReadGraph graph) throws DatabaseException {\r
283                 throw new DatabaseException("not supported");\r
284         }\r
285 \r
286         @Override\r
287         public Resource getPossiblePredicateResource(ReadGraph graph) throws DatabaseException {\r
288                 try {\r
289                         return getPredicateResource(graph);\r
290                 } catch (DatabaseException e) {\r
291                         return null;\r
292                 }\r
293         }\r
294 \r
295         @Override\r
296         public Variable getParent(ReadGraph graph) throws DatabaseException {\r
297                 return parent;\r
298         }\r
299 \r
300         @Override\r
301         public Resource getRepresents(ReadGraph graph) throws DatabaseException {\r
302                 throw new DatabaseException("no resource representation");\r
303         }\r
304 \r
305         @Override\r
306         public Resource getPossibleRepresents(ReadGraph graph) throws DatabaseException {\r
307                 return null;\r
308         }\r
309 \r
310         @Override\r
311         public Resource getType(ReadGraph graph) throws DatabaseException {\r
312                 throw new DatabaseException("not supported");\r
313         }\r
314 \r
315         @Override\r
316         public Resource getPossibleType(ReadGraph graph) throws DatabaseException {\r
317                 return null;\r
318         }\r
319 \r
320         @Override\r
321         public Resource getType(ReadGraph graph, Resource baseType) throws DatabaseException {\r
322                 throw new DatabaseException("not supported");\r
323         }\r
324 \r
325         @Override\r
326         public Resource getPossibleType(ReadGraph graph, Resource baseType) throws DatabaseException {\r
327                 return null;\r
328         }\r
329 \r
330         @Override\r
331         public abstract RVI getRVI(ReadGraph graph) throws DatabaseException;\r
332 \r
333         @Override\r
334         public RVI getPossibleRVI(ReadGraph graph) throws DatabaseException {\r
335                 try {\r
336                         return getRVI(graph);\r
337                 } catch (DatabaseException e) {\r
338                         return null;\r
339                 }\r
340         }\r
341 \r
342         @Override\r
343         public Role getRole(ReadGraph graph) throws DatabaseException {\r
344                 return Role.PROPERTY;\r
345         }\r
346         \r
347         @Override\r
348         public Role getPossibleRole(ReadGraph graph) throws DatabaseException {\r
349                 return Role.PROPERTY;\r
350         }\r
351         \r
352         @Override\r
353         public Set<String> getClassifications(ReadGraph graph) throws DatabaseException {\r
354                 return Collections.emptySet();\r
355         }\r
356 \r
357         public abstract Variant getVariantValue(ReadGraph graph) throws DatabaseException;\r
358 \r
359 }\r