-package org.simantics.db.layer0.variable;\r
-\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.Set;\r
-\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.binding.mutable.Variant;\r
-import org.simantics.databoard.type.Datatype;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.request.PropertyInfo;\r
-import org.simantics.db.layer0.variable.RVI.RVIPart;\r
-import org.simantics.db.layer0.variable.Variables.Role;\r
-\r
-/**\r
- * An abstract base proxy implementation for value container variables that are\r
- * leaves of the variable tree. This means by default the variable has no\r
- * support for children or properties, only for returning a single value that it\r
- * wraps.\r
- * \r
- * @author Tuukka Lehtonen\r
- */\r
-public abstract class ValueProxyVariable implements Variable {\r
-\r
- protected final Variable proxy;\r
- protected final Variable parent;\r
-\r
- public ValueProxyVariable(Variable proxy, Variable parent) {\r
- if (proxy == null)\r
- throw new NullPointerException("null proxy");\r
- if (parent == null)\r
- throw new NullPointerException("null parent");\r
- this.parent = parent;\r
- this.proxy = proxy;\r
- }\r
-\r
- @Override\r
- public <T> T getPropertyValue(ReadGraph graph, String name) throws DatabaseException {\r
- throw new DatabaseException("Could not resolve property " + name);\r
- }\r
-\r
- @Override\r
- public <T> T getPropertyValue(ReadGraph graph, Resource property) throws DatabaseException {\r
- throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));\r
- }\r
-\r
- @Override\r
- public <T> T getPossiblePropertyValue(ReadGraph graph, String name) throws DatabaseException {\r
- throw new DatabaseException("Could not resolve property " + name);\r
- }\r
-\r
- @Override\r
- public <T> T getPossiblePropertyValue(ReadGraph graph, Resource property) throws DatabaseException {\r
- throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));\r
- }\r
-\r
- @Override\r
- public <T> T getPropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException {\r
- throw new DatabaseException("Could not resolve property " + name);\r
- }\r
-\r
- @Override\r
- public <T> T getPropertyValue(ReadGraph graph, Resource property, Binding binding) throws DatabaseException {\r
- throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));\r
- }\r
-\r
- @Override\r
- public <T> T getPossiblePropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException {\r
- throw new DatabaseException("Could not resolve property " + name);\r
- }\r
-\r
- @Override\r
- public <T> T getPossiblePropertyValue(ReadGraph graph, Resource property, Binding binding) throws DatabaseException {\r
- return proxy.getPossiblePropertyValue(graph, property, binding);\r
- }\r
-\r
- @Override\r
- public PropertyInfo getPropertyInfo(ReadGraph graph) throws DatabaseException {\r
- return proxy.getPropertyInfo(graph);\r
- }\r
- \r
- @Override\r
- public Resource getIndexRoot(ReadGraph graph) throws DatabaseException {\r
- return proxy.getIndexRoot(graph);\r
- }\r
- \r
- @Override\r
- public abstract <T> T getValue(ReadGraph graph) throws DatabaseException;\r
-\r
- @Override\r
- public abstract <T> T getPossibleValue(ReadGraph graph) throws DatabaseException;\r
-\r
- @Override\r
- public abstract <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException;\r
-\r
- @Override\r
- public abstract <T> T getPossibleValue(ReadGraph graph, Binding binding) throws DatabaseException;\r
-\r
- @Override\r
- public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException {\r
- throw new DatabaseException("Not supported");\r
- }\r
-\r
- @Override\r
- public void setValue(WriteGraph graph, Object value) throws DatabaseException {\r
- throw new DatabaseException("Not supported");\r
- }\r
-\r
- @Override\r
- public void setPropertyValue(WriteGraph graph, String name, Object value, Binding binding) throws DatabaseException {\r
- throw new DatabaseException("Not supported");\r
- }\r
-\r
- @Override\r
- public void setPropertyValue(WriteGraph graph, Resource property, Object value, Binding binding) throws DatabaseException {\r
- throw new DatabaseException("Not supported");\r
- }\r
-\r
- @Override\r
- public void setPropertyValue(WriteGraph graph, String name, Object value) throws DatabaseException {\r
- throw new DatabaseException("Not supported");\r
- }\r
-\r
- @Override\r
- public void setPropertyValue(WriteGraph graph, Resource property, Object value) throws DatabaseException {\r
- throw new DatabaseException("Not supported");\r
- }\r
-\r
- @Override\r
- public Variable getChild(ReadGraph graph, String name) throws DatabaseException {\r
- throw new DatabaseException("Could not resolve child " + name);\r
- }\r
-\r
- @Override\r
- public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {\r
- return null;\r
- }\r
-\r
- @Override\r
- public Variable getProperty(ReadGraph graph, String name) throws DatabaseException {\r
- throw new DatabaseException("Could not resolve property " + name);\r
- }\r
-\r
- @Override\r
- public Variable getProperty(ReadGraph graph, Resource property) throws DatabaseException {\r
- throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));\r
- }\r
-\r
- @Override\r
- public Variable getPossibleProperty(ReadGraph graph, String name) throws DatabaseException {\r
- return null;\r
- }\r
-\r
- @Override\r
- public Variable getPossibleProperty(ReadGraph graph, Resource property) throws DatabaseException {\r
- return null;\r
- }\r
-\r
- @Override\r
- public Collection<Variable> browseChildren(ReadGraph graph) throws DatabaseException {\r
- return getChildren(graph);\r
- }\r
-\r
- @Override\r
- public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {\r
- return Collections.emptyList();\r
- }\r
-\r
- @Override\r
- public Collection<Variable> browseProperties(ReadGraph graph) throws DatabaseException {\r
- return getProperties(graph);\r
- }\r
-\r
- @Override\r
- public Collection<Variable> getProperties(ReadGraph graph) throws DatabaseException {\r
- return Collections.emptyList();\r
- }\r
-\r
- @Override\r
- public Collection<Variable> getProperties(ReadGraph graph, String classification) throws DatabaseException {\r
- return Collections.emptyList();\r
- }\r
-\r
- @Override\r
- public Collection<Variable> getProperties(ReadGraph graph, Resource classification) throws DatabaseException {\r
- return Collections.emptyList();\r
- }\r
-\r
- @Override\r
- public Variable browse(ReadGraph graph, String suffix) throws DatabaseException {\r
- if (suffix.isEmpty())\r
- return this;\r
- throw new DatabaseException("Could not browse with suffix '" + suffix + "'");\r
- }\r
-\r
- @Override\r
- public Variable browsePossible(ReadGraph graph, String suffix) throws DatabaseException {\r
- if (suffix.isEmpty())\r
- return this;\r
- return null;\r
- }\r
-\r
- @Override\r
- public Variable browse(ReadGraph graph, Resource config) throws DatabaseException {\r
- throw new DatabaseException("Could not browse '" + NameUtils.getSafeName(graph, config, true) + "'");\r
- }\r
-\r
- @Override\r
- public Variable browsePossible(ReadGraph graph, Resource config) throws DatabaseException {\r
- return null;\r
- }\r
-\r
- @Override\r
- public <T> T getInterface(ReadGraph graph, Class<T> clazz) throws DatabaseException {\r
- return null;\r
- }\r
-\r
- @Override\r
- public <T> T adapt(ReadGraph graph, Class<T> clazz) throws DatabaseException {\r
- return null;\r
- }\r
-\r
- @Override\r
- public <T> T adaptPossible(ReadGraph graph, Class<T> clazz) throws DatabaseException {\r
- return null;\r
- }\r
-\r
- @Override\r
- public abstract String getURI(ReadGraph graph) throws DatabaseException;\r
-\r
- @Override\r
- public abstract int hashCode();\r
-\r
- @Override\r
- public abstract boolean equals(Object obj);\r
-\r
- @Override\r
- public Variable resolve(ReadGraph graph, RVIPart part) throws DatabaseException {\r
- throw new DatabaseException("not supported");\r
- }\r
-\r
- @Override\r
- public Variable resolvePossible(ReadGraph graph, RVIPart part) throws DatabaseException {\r
- return null;\r
- }\r
-\r
- @Override\r
- public abstract String getName(ReadGraph graph) throws DatabaseException;\r
-\r
- @Override\r
- public String getLabel(ReadGraph graph) throws DatabaseException {\r
- throw new DatabaseException("not supported");\r
- }\r
-\r
- @Override\r
- public abstract Datatype getDatatype(ReadGraph graph) throws DatabaseException;\r
-\r
- @Override\r
- public Datatype getPossibleDatatype(ReadGraph graph) throws DatabaseException {\r
- try {\r
- return getDatatype(graph);\r
- } catch (DatabaseException e) {\r
- return null;\r
- }\r
- }\r
-\r
- @Override\r
- public Variable getPredicate(ReadGraph graph) throws DatabaseException {\r
- throw new DatabaseException("not supported");\r
- }\r
-\r
- @Override\r
- public Variable getPossiblePredicate(ReadGraph graph) throws DatabaseException {\r
- throw new DatabaseException("not supported");\r
- }\r
-\r
- @Override\r
- public Resource getPredicateResource(ReadGraph graph) throws DatabaseException {\r
- throw new DatabaseException("not supported");\r
- }\r
-\r
- @Override\r
- public Resource getPossiblePredicateResource(ReadGraph graph) throws DatabaseException {\r
- try {\r
- return getPredicateResource(graph);\r
- } catch (DatabaseException e) {\r
- return null;\r
- }\r
- }\r
-\r
- @Override\r
- public Variable getParent(ReadGraph graph) throws DatabaseException {\r
- return parent;\r
- }\r
-\r
- @Override\r
- public Resource getRepresents(ReadGraph graph) throws DatabaseException {\r
- throw new DatabaseException("no resource representation");\r
- }\r
-\r
- @Override\r
- public Resource getPossibleRepresents(ReadGraph graph) throws DatabaseException {\r
- return null;\r
- }\r
-\r
- @Override\r
- public Resource getType(ReadGraph graph) throws DatabaseException {\r
- throw new DatabaseException("not supported");\r
- }\r
-\r
- @Override\r
- public Resource getPossibleType(ReadGraph graph) throws DatabaseException {\r
- return null;\r
- }\r
-\r
- @Override\r
- public Resource getType(ReadGraph graph, Resource baseType) throws DatabaseException {\r
- throw new DatabaseException("not supported");\r
- }\r
-\r
- @Override\r
- public Resource getPossibleType(ReadGraph graph, Resource baseType) throws DatabaseException {\r
- return null;\r
- }\r
-\r
- @Override\r
- public abstract RVI getRVI(ReadGraph graph) throws DatabaseException;\r
-\r
- @Override\r
- public RVI getPossibleRVI(ReadGraph graph) throws DatabaseException {\r
- try {\r
- return getRVI(graph);\r
- } catch (DatabaseException e) {\r
- return null;\r
- }\r
- }\r
-\r
- @Override\r
- public Role getRole(ReadGraph graph) throws DatabaseException {\r
- return Role.PROPERTY;\r
- }\r
- \r
- @Override\r
- public Role getPossibleRole(ReadGraph graph) throws DatabaseException {\r
- return Role.PROPERTY;\r
- }\r
- \r
- @Override\r
- public Set<String> getClassifications(ReadGraph graph) throws DatabaseException {\r
- return Collections.emptySet();\r
- }\r
-\r
- public abstract Variant getVariantValue(ReadGraph graph) throws DatabaseException;\r
-\r
-}\r
+package org.simantics.db.layer0.variable;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+
+import org.simantics.databoard.binding.Binding;
+import org.simantics.databoard.binding.mutable.Variant;
+import org.simantics.databoard.type.Datatype;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.request.PropertyInfo;
+import org.simantics.db.layer0.variable.RVI.RVIPart;
+import org.simantics.db.layer0.variable.Variables.Role;
+
+/**
+ * An abstract base proxy implementation for value container variables that are
+ * leaves of the variable tree. This means by default the variable has no
+ * support for children or properties, only for returning a single value that it
+ * wraps.
+ *
+ * @author Tuukka Lehtonen
+ */
+public abstract class ValueProxyVariable implements Variable {
+
+ protected final Variable proxy;
+ protected final Variable parent;
+
+ public ValueProxyVariable(Variable proxy, Variable parent) {
+ if (proxy == null)
+ throw new NullPointerException("null proxy");
+ if (parent == null)
+ throw new NullPointerException("null parent");
+ this.parent = parent;
+ this.proxy = proxy;
+ }
+
+ @Override
+ public <T> T getPropertyValue(ReadGraph graph, String name) throws DatabaseException {
+ throw new DatabaseException("Could not resolve property " + name);
+ }
+
+ @Override
+ public <T> T getPropertyValue(ReadGraph graph, Resource property) throws DatabaseException {
+ throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));
+ }
+
+ @Override
+ public <T> T getPossiblePropertyValue(ReadGraph graph, String name) throws DatabaseException {
+ throw new DatabaseException("Could not resolve property " + name);
+ }
+
+ @Override
+ public <T> T getPossiblePropertyValue(ReadGraph graph, Resource property) throws DatabaseException {
+ throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));
+ }
+
+ @Override
+ public <T> T getPropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException {
+ throw new DatabaseException("Could not resolve property " + name);
+ }
+
+ @Override
+ public <T> T getPropertyValue(ReadGraph graph, Resource property, Binding binding) throws DatabaseException {
+ throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));
+ }
+
+ @Override
+ public <T> T getPossiblePropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException {
+ throw new DatabaseException("Could not resolve property " + name);
+ }
+
+ @Override
+ public <T> T getPossiblePropertyValue(ReadGraph graph, Resource property, Binding binding) throws DatabaseException {
+ return proxy.getPossiblePropertyValue(graph, property, binding);
+ }
+
+ @Override
+ public PropertyInfo getPropertyInfo(ReadGraph graph) throws DatabaseException {
+ return proxy.getPropertyInfo(graph);
+ }
+
+ @Override
+ public Resource getIndexRoot(ReadGraph graph) throws DatabaseException {
+ return proxy.getIndexRoot(graph);
+ }
+
+ @Override
+ public abstract <T> T getValue(ReadGraph graph) throws DatabaseException;
+
+ @Override
+ public abstract <T> T getPossibleValue(ReadGraph graph) throws DatabaseException;
+
+ @Override
+ public abstract <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException;
+
+ @Override
+ public abstract <T> T getPossibleValue(ReadGraph graph, Binding binding) throws DatabaseException;
+
+ @Override
+ public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException {
+ throw new DatabaseException("Not supported");
+ }
+
+ @Override
+ public void setValue(WriteGraph graph, Object value) throws DatabaseException {
+ throw new DatabaseException("Not supported");
+ }
+
+ @Override
+ public void setPropertyValue(WriteGraph graph, String name, Object value, Binding binding) throws DatabaseException {
+ throw new DatabaseException("Not supported");
+ }
+
+ @Override
+ public void setPropertyValue(WriteGraph graph, Resource property, Object value, Binding binding) throws DatabaseException {
+ throw new DatabaseException("Not supported");
+ }
+
+ @Override
+ public void setPropertyValue(WriteGraph graph, String name, Object value) throws DatabaseException {
+ throw new DatabaseException("Not supported");
+ }
+
+ @Override
+ public void setPropertyValue(WriteGraph graph, Resource property, Object value) throws DatabaseException {
+ throw new DatabaseException("Not supported");
+ }
+
+ @Override
+ public Variable getChild(ReadGraph graph, String name) throws DatabaseException {
+ throw new DatabaseException("Could not resolve child " + name);
+ }
+
+ @Override
+ public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {
+ return null;
+ }
+
+ @Override
+ public Variable getProperty(ReadGraph graph, String name) throws DatabaseException {
+ throw new DatabaseException("Could not resolve property " + name);
+ }
+
+ @Override
+ public Variable getProperty(ReadGraph graph, Resource property) throws DatabaseException {
+ throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true));
+ }
+
+ @Override
+ public Variable getPossibleProperty(ReadGraph graph, String name) throws DatabaseException {
+ return null;
+ }
+
+ @Override
+ public Variable getPossibleProperty(ReadGraph graph, Resource property) throws DatabaseException {
+ return null;
+ }
+
+ @Override
+ public Collection<Variable> browseChildren(ReadGraph graph) throws DatabaseException {
+ return getChildren(graph);
+ }
+
+ @Override
+ public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public Collection<Variable> browseProperties(ReadGraph graph) throws DatabaseException {
+ return getProperties(graph);
+ }
+
+ @Override
+ public Collection<Variable> getProperties(ReadGraph graph) throws DatabaseException {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public Collection<Variable> getProperties(ReadGraph graph, String classification) throws DatabaseException {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public Collection<Variable> getProperties(ReadGraph graph, Resource classification) throws DatabaseException {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public Variable browse(ReadGraph graph, String suffix) throws DatabaseException {
+ if (suffix.isEmpty())
+ return this;
+ throw new DatabaseException("Could not browse with suffix '" + suffix + "'");
+ }
+
+ @Override
+ public Variable browsePossible(ReadGraph graph, String suffix) throws DatabaseException {
+ if (suffix.isEmpty())
+ return this;
+ return null;
+ }
+
+ @Override
+ public Variable browse(ReadGraph graph, Resource config) throws DatabaseException {
+ throw new DatabaseException("Could not browse '" + NameUtils.getSafeName(graph, config, true) + "'");
+ }
+
+ @Override
+ public Variable browsePossible(ReadGraph graph, Resource config) throws DatabaseException {
+ return null;
+ }
+
+ @Override
+ public <T> T getInterface(ReadGraph graph, Class<T> clazz) throws DatabaseException {
+ return null;
+ }
+
+ @Override
+ public <T> T adapt(ReadGraph graph, Class<T> clazz) throws DatabaseException {
+ return null;
+ }
+
+ @Override
+ public <T> T adaptPossible(ReadGraph graph, Class<T> clazz) throws DatabaseException {
+ return null;
+ }
+
+ @Override
+ public abstract String getURI(ReadGraph graph) throws DatabaseException;
+
+ @Override
+ public abstract int hashCode();
+
+ @Override
+ public abstract boolean equals(Object obj);
+
+ @Override
+ public Variable resolve(ReadGraph graph, RVIPart part) throws DatabaseException {
+ throw new DatabaseException("not supported");
+ }
+
+ @Override
+ public Variable resolvePossible(ReadGraph graph, RVIPart part) throws DatabaseException {
+ return null;
+ }
+
+ @Override
+ public abstract String getName(ReadGraph graph) throws DatabaseException;
+
+ @Override
+ public String getLabel(ReadGraph graph) throws DatabaseException {
+ throw new DatabaseException("not supported");
+ }
+
+ @Override
+ public abstract Datatype getDatatype(ReadGraph graph) throws DatabaseException;
+
+ @Override
+ public Datatype getPossibleDatatype(ReadGraph graph) throws DatabaseException {
+ try {
+ return getDatatype(graph);
+ } catch (DatabaseException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public Variable getPredicate(ReadGraph graph) throws DatabaseException {
+ throw new DatabaseException("not supported");
+ }
+
+ @Override
+ public Variable getPossiblePredicate(ReadGraph graph) throws DatabaseException {
+ throw new DatabaseException("not supported");
+ }
+
+ @Override
+ public Resource getPredicateResource(ReadGraph graph) throws DatabaseException {
+ throw new DatabaseException("not supported");
+ }
+
+ @Override
+ public Resource getPossiblePredicateResource(ReadGraph graph) throws DatabaseException {
+ try {
+ return getPredicateResource(graph);
+ } catch (DatabaseException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public Variable getParent(ReadGraph graph) throws DatabaseException {
+ return parent;
+ }
+
+ @Override
+ public Resource getRepresents(ReadGraph graph) throws DatabaseException {
+ throw new DatabaseException("no resource representation");
+ }
+
+ @Override
+ public Resource getPossibleRepresents(ReadGraph graph) throws DatabaseException {
+ return null;
+ }
+
+ @Override
+ public Resource getType(ReadGraph graph) throws DatabaseException {
+ throw new DatabaseException("not supported");
+ }
+
+ @Override
+ public Resource getPossibleType(ReadGraph graph) throws DatabaseException {
+ return null;
+ }
+
+ @Override
+ public Resource getType(ReadGraph graph, Resource baseType) throws DatabaseException {
+ throw new DatabaseException("not supported");
+ }
+
+ @Override
+ public Resource getPossibleType(ReadGraph graph, Resource baseType) throws DatabaseException {
+ return null;
+ }
+
+ @Override
+ public abstract RVI getRVI(ReadGraph graph) throws DatabaseException;
+
+ @Override
+ public RVI getPossibleRVI(ReadGraph graph) throws DatabaseException {
+ try {
+ return getRVI(graph);
+ } catch (DatabaseException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public Role getRole(ReadGraph graph) throws DatabaseException {
+ return Role.PROPERTY;
+ }
+
+ @Override
+ public Role getPossibleRole(ReadGraph graph) throws DatabaseException {
+ return Role.PROPERTY;
+ }
+
+ @Override
+ public Set<String> getClassifications(ReadGraph graph) throws DatabaseException {
+ return Collections.emptySet();
+ }
+
+ public abstract Variant getVariantValue(ReadGraph graph) throws DatabaseException;
+
+}