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