1 package org.simantics.db.layer0.variable;
3 import java.util.Collection;
4 import java.util.Collections;
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;
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
25 * @author Tuukka Lehtonen
27 public abstract class ValueProxyVariable implements Variable {
29 protected final Variable proxy;
30 protected final Variable parent;
32 public ValueProxyVariable(Variable proxy, Variable parent) {
34 throw new NullPointerException("null proxy");
36 throw new NullPointerException("null parent");
42 public <T> T getPropertyValue(ReadGraph graph, String name) throws DatabaseException {
43 throw new DatabaseException("Could not resolve property " + name);
47 public <T> T getPropertyValue(ReadGraph graph, Resource property) throws DatabaseException {
48 throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));
52 public <T> T getPossiblePropertyValue(ReadGraph graph, String name) throws DatabaseException {
53 throw new DatabaseException("Could not resolve property " + name);
57 public <T> T getPossiblePropertyValue(ReadGraph graph, Resource property) throws DatabaseException {
58 throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));
62 public <T> T getPropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException {
63 throw new DatabaseException("Could not resolve property " + name);
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));
72 public <T> T getPossiblePropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException {
73 throw new DatabaseException("Could not resolve property " + name);
77 public <T> T getPossiblePropertyValue(ReadGraph graph, Resource property, Binding binding) throws DatabaseException {
78 return proxy.getPossiblePropertyValue(graph, property, binding);
82 public PropertyInfo getPropertyInfo(ReadGraph graph) throws DatabaseException {
83 return proxy.getPropertyInfo(graph);
87 public Resource getIndexRoot(ReadGraph graph) throws DatabaseException {
88 return proxy.getIndexRoot(graph);
92 public abstract <T> T getValue(ReadGraph graph) throws DatabaseException;
95 public abstract <T> T getPossibleValue(ReadGraph graph) throws DatabaseException;
98 public abstract <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException;
101 public abstract <T> T getPossibleValue(ReadGraph graph, Binding binding) throws DatabaseException;
104 public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException {
105 throw new DatabaseException("Not supported");
109 public void setValue(WriteGraph graph, Object value) throws DatabaseException {
110 throw new DatabaseException("Not supported");
114 public void setPropertyValue(WriteGraph graph, String name, Object value, Binding binding) throws DatabaseException {
115 throw new DatabaseException("Not supported");
119 public void setPropertyValue(WriteGraph graph, Resource property, Object value, Binding binding) throws DatabaseException {
120 throw new DatabaseException("Not supported");
124 public void setPropertyValue(WriteGraph graph, String name, Object value) throws DatabaseException {
125 throw new DatabaseException("Not supported");
129 public void setPropertyValue(WriteGraph graph, Resource property, Object value) throws DatabaseException {
130 throw new DatabaseException("Not supported");
134 public Variable getChild(ReadGraph graph, String name) throws DatabaseException {
135 throw new DatabaseException("Could not resolve child " + name);
139 public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {
144 public Variable getProperty(ReadGraph graph, String name) throws DatabaseException {
145 throw new DatabaseException("Could not resolve property " + name);
149 public Variable getProperty(ReadGraph graph, Resource property) throws DatabaseException {
150 throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));
154 public Variable getPossibleProperty(ReadGraph graph, String name) throws DatabaseException {
159 public Variable getPossibleProperty(ReadGraph graph, Resource property) throws DatabaseException {
164 public Collection<Variable> browseChildren(ReadGraph graph) throws DatabaseException {
165 return getChildren(graph);
169 public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {
170 return Collections.emptyList();
174 public Collection<Variable> browseProperties(ReadGraph graph) throws DatabaseException {
175 return getProperties(graph);
179 public Collection<Variable> getProperties(ReadGraph graph) throws DatabaseException {
180 return Collections.emptyList();
184 public Collection<Variable> getProperties(ReadGraph graph, String classification) throws DatabaseException {
185 return Collections.emptyList();
189 public Collection<Variable> getProperties(ReadGraph graph, Resource classification) throws DatabaseException {
190 return Collections.emptyList();
194 public Variable browse(ReadGraph graph, String suffix) throws DatabaseException {
195 if (suffix.isEmpty())
197 throw new DatabaseException("Could not browse with suffix '" + suffix + "'");
201 public Variable browsePossible(ReadGraph graph, String suffix) throws DatabaseException {
202 if (suffix.isEmpty())
208 public Variable browse(ReadGraph graph, Resource config) throws DatabaseException {
209 throw new DatabaseException("Could not browse '" + NameUtils.getSafeName(graph, config, true) + "'");
213 public Variable browsePossible(ReadGraph graph, Resource config) throws DatabaseException {
218 public <T> T getInterface(ReadGraph graph, Class<T> clazz) throws DatabaseException {
223 public <T> T adapt(ReadGraph graph, Class<T> clazz) throws DatabaseException {
228 public <T> T adaptPossible(ReadGraph graph, Class<T> clazz) throws DatabaseException {
233 public abstract String getURI(ReadGraph graph) throws DatabaseException;
236 public abstract int hashCode();
239 public abstract boolean equals(Object obj);
242 public Variable resolve(ReadGraph graph, RVIPart part) throws DatabaseException {
243 throw new DatabaseException("not supported");
247 public Variable resolvePossible(ReadGraph graph, RVIPart part) throws DatabaseException {
252 public abstract String getName(ReadGraph graph) throws DatabaseException;
255 public String getLabel(ReadGraph graph) throws DatabaseException {
256 throw new DatabaseException("not supported");
260 public abstract Datatype getDatatype(ReadGraph graph) throws DatabaseException;
263 public Datatype getPossibleDatatype(ReadGraph graph) throws DatabaseException {
265 return getDatatype(graph);
266 } catch (DatabaseException e) {
272 public Variable getPredicate(ReadGraph graph) throws DatabaseException {
273 throw new DatabaseException("not supported");
277 public Variable getPossiblePredicate(ReadGraph graph) throws DatabaseException {
278 throw new DatabaseException("not supported");
282 public Resource getPredicateResource(ReadGraph graph) throws DatabaseException {
283 throw new DatabaseException("not supported");
287 public Resource getPossiblePredicateResource(ReadGraph graph) throws DatabaseException {
289 return getPredicateResource(graph);
290 } catch (DatabaseException e) {
296 public Variable getParent(ReadGraph graph) throws DatabaseException {
301 public Resource getRepresents(ReadGraph graph) throws DatabaseException {
302 throw new DatabaseException("no resource representation");
306 public Resource getPossibleRepresents(ReadGraph graph) throws DatabaseException {
311 public Resource getType(ReadGraph graph) throws DatabaseException {
312 throw new DatabaseException("not supported");
316 public Resource getPossibleType(ReadGraph graph) throws DatabaseException {
321 public Resource getType(ReadGraph graph, Resource baseType) throws DatabaseException {
322 throw new DatabaseException("not supported");
326 public Resource getPossibleType(ReadGraph graph, Resource baseType) throws DatabaseException {
331 public abstract RVI getRVI(ReadGraph graph) throws DatabaseException;
334 public RVI getPossibleRVI(ReadGraph graph) throws DatabaseException {
336 return getRVI(graph);
337 } catch (DatabaseException e) {
343 public Role getRole(ReadGraph graph) throws DatabaseException {
344 return Role.PROPERTY;
348 public Role getPossibleRole(ReadGraph graph) throws DatabaseException {
349 return Role.PROPERTY;
353 public Set<String> getClassifications(ReadGraph graph) throws DatabaseException {
354 return Collections.emptySet();
357 public abstract Variant getVariantValue(ReadGraph graph) throws DatabaseException;