]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ValueProxyVariable.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / variable / ValueProxyVariable.java
diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ValueProxyVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/ValueProxyVariable.java
new file mode 100644 (file)
index 0000000..b2f0250
--- /dev/null
@@ -0,0 +1,359 @@
+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