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