X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fvariable%2FValueProxyVariable.java;h=1f6b18030e6747339179b0b99fde35443aa5f33d;hb=85c1daf4b3d4a48613e0c61c359cb8aac2157f01;hp=b2f02501741328e9c011665839b9d15dab1cc43c;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git 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 index b2f025017..1f6b18030 100644 --- 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 @@ -1,359 +1,359 @@ -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 getPropertyValue(ReadGraph graph, String name) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + name); - } - - @Override - public T getPropertyValue(ReadGraph graph, Resource property) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true)); - } - - @Override - public T getPossiblePropertyValue(ReadGraph graph, String name) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + name); - } - - @Override - public T getPossiblePropertyValue(ReadGraph graph, Resource property) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true)); - } - - @Override - public T getPropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + name); - } - - @Override - public 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 getPossiblePropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException { - throw new DatabaseException("Could not resolve property " + name); - } - - @Override - public 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 getValue(ReadGraph graph) throws DatabaseException; - - @Override - public abstract T getPossibleValue(ReadGraph graph) throws DatabaseException; - - @Override - public abstract T getValue(ReadGraph graph, Binding binding) throws DatabaseException; - - @Override - public abstract 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 browseChildren(ReadGraph graph) throws DatabaseException { - return getChildren(graph); - } - - @Override - public Collection getChildren(ReadGraph graph) throws DatabaseException { - return Collections.emptyList(); - } - - @Override - public Collection browseProperties(ReadGraph graph) throws DatabaseException { - return getProperties(graph); - } - - @Override - public Collection getProperties(ReadGraph graph) throws DatabaseException { - return Collections.emptyList(); - } - - @Override - public Collection getProperties(ReadGraph graph, String classification) throws DatabaseException { - return Collections.emptyList(); - } - - @Override - public Collection 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 getInterface(ReadGraph graph, Class clazz) throws DatabaseException { - return null; - } - - @Override - public T adapt(ReadGraph graph, Class clazz) throws DatabaseException { - return null; - } - - @Override - public T adaptPossible(ReadGraph graph, Class 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 getClassifications(ReadGraph graph) throws DatabaseException { - return Collections.emptySet(); - } - - public abstract Variant getVariantValue(ReadGraph graph) throws DatabaseException; - -} +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 getPropertyValue(ReadGraph graph, String name) throws DatabaseException { + throw new DatabaseException("Could not resolve property " + name); + } + + @Override + public T getPropertyValue(ReadGraph graph, Resource property) throws DatabaseException { + throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true)); + } + + @Override + public T getPossiblePropertyValue(ReadGraph graph, String name) throws DatabaseException { + throw new DatabaseException("Could not resolve property " + name); + } + + @Override + public T getPossiblePropertyValue(ReadGraph graph, Resource property) throws DatabaseException { + throw new DatabaseException("Could not resolve property " + NameUtils.getSafeName(graph, property, true)); + } + + @Override + public T getPropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException { + throw new DatabaseException("Could not resolve property " + name); + } + + @Override + public 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 getPossiblePropertyValue(ReadGraph graph, String name, Binding binding) throws DatabaseException { + throw new DatabaseException("Could not resolve property " + name); + } + + @Override + public 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 getValue(ReadGraph graph) throws DatabaseException; + + @Override + public abstract T getPossibleValue(ReadGraph graph) throws DatabaseException; + + @Override + public abstract T getValue(ReadGraph graph, Binding binding) throws DatabaseException; + + @Override + public abstract 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 browseChildren(ReadGraph graph) throws DatabaseException { + return getChildren(graph); + } + + @Override + public Collection getChildren(ReadGraph graph) throws DatabaseException { + return Collections.emptyList(); + } + + @Override + public Collection browseProperties(ReadGraph graph) throws DatabaseException { + return getProperties(graph); + } + + @Override + public Collection getProperties(ReadGraph graph) throws DatabaseException { + return Collections.emptyList(); + } + + @Override + public Collection getProperties(ReadGraph graph, String classification) throws DatabaseException { + return Collections.emptyList(); + } + + @Override + public Collection 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 getInterface(ReadGraph graph, Class clazz) throws DatabaseException { + return null; + } + + @Override + public T adapt(ReadGraph graph, Class clazz) throws DatabaseException { + return null; + } + + @Override + public T adaptPossible(ReadGraph graph, Class 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 getClassifications(ReadGraph graph) throws DatabaseException { + return Collections.emptySet(); + } + + public abstract Variant getVariantValue(ReadGraph graph) throws DatabaseException; + +}