X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fvariable%2FAbstractChildVariable.java;h=7df21813027ab198fd3ccf5c4d0ca3fb6d3fcd99;hb=3c2807a26920491016a1887d2c1a95609c082a19;hp=2b6cd0595dc71390875d052e0303a28f3b8ce8cf;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractChildVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractChildVariable.java index 2b6cd0595..7df218130 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractChildVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractChildVariable.java @@ -1,109 +1,109 @@ -package org.simantics.db.layer0.variable; - -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.Set; - -import org.simantics.databoard.binding.Binding; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.WriteGraph; -import org.simantics.db.common.uri.UnescapedChildMapOfResource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.db.layer0.exception.MissingVariableValueException; -import org.simantics.db.layer0.variable.RVI.RVIPart; -import org.simantics.db.layer0.variable.RVI.StringRVIPart; -import org.simantics.db.layer0.variable.Variables.Role; - -public abstract class AbstractChildVariable extends AbstractVariable { - - public AbstractChildVariable() { - this(null); - } - - public AbstractChildVariable(VariableNode node) { - super(node); - } - - @Override - public Role getRole(ReadGraph graph) throws DatabaseException { - return Role.CHILD; - } - - @Override - public T getValue(ReadGraph graph) throws DatabaseException { - throw new MissingVariableValueException("No value in child variable."); - } - - @Override - public T getValue(ReadGraph graph, Binding binding) throws DatabaseException { - throw new MissingVariableValueException("No value in child variable."); - } - - @Override - public void setValue(WriteGraph graph, Object value, Binding binding) - throws DatabaseException { - throw new DatabaseException("Cannot write value to a child variable."); - } - - - @Override - public Resource getRepresents(ReadGraph graph) throws DatabaseException { - Variable parent = getParent(graph); - if(!(parent instanceof AbstractChildVariable)) - return null; - Resource parentRepresents = - ((AbstractChildVariable)parent).getRepresentsForBrowsingChildResources(graph); - if(parentRepresents == null) - return null; - Resource result = graph.syncRequest(new UnescapedChildMapOfResource(parentRepresents)) - .get(getName(graph)); -// System.err.println("getRepresents " + getURI(graph) + " -> parent " + parentRepresents + " " + this + " => " + result + " " + getName(graph)); - return result; - } - - public Resource getRepresentsForBrowsingChildResources(ReadGraph graph) throws DatabaseException { - return getRepresents(graph); - } - - @Override - public Variable getPossibleExtraProperty(ReadGraph graph, String name) throws DatabaseException { - return null; - } - - @Override - public void collectExtraProperties(ReadGraph graph, Map properties) throws DatabaseException { - } - - @Override - protected Variable getPossibleDomainProperty(ReadGraph graph, String name) throws DatabaseException { - return null; - } - - @Override - public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException { - return null; - } - - @Override - public Map collectDomainProperties(ReadGraph graph, Map map) throws DatabaseException { - return map; - } - - @Override - public Collection getChildren(ReadGraph graph) throws DatabaseException { - return Collections.emptyList(); - } - - @Override - public RVIPart getRVIPart(ReadGraph graph) throws DatabaseException { - return new StringRVIPart(Role.CHILD, getName(graph)); - } - - @Override - public Set getClassifications(ReadGraph graph) throws DatabaseException { - return Collections.emptySet(); - } - -} +package org.simantics.db.layer0.variable; + +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.Set; + +import org.simantics.databoard.binding.Binding; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.uri.UnescapedChildMapOfResource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.exception.MissingVariableValueException; +import org.simantics.db.layer0.variable.RVI.RVIPart; +import org.simantics.db.layer0.variable.RVI.StringRVIPart; +import org.simantics.db.layer0.variable.Variables.Role; + +public abstract class AbstractChildVariable extends AbstractVariable { + + public AbstractChildVariable() { + this(null); + } + + public AbstractChildVariable(VariableNode node) { + super(node); + } + + @Override + public Role getRole(ReadGraph graph) throws DatabaseException { + return Role.CHILD; + } + + @Override + public T getValue(ReadGraph graph) throws DatabaseException { + throw new MissingVariableValueException("No value in child variable."); + } + + @Override + public T getValue(ReadGraph graph, Binding binding) throws DatabaseException { + throw new MissingVariableValueException("No value in child variable."); + } + + @Override + public void setValue(WriteGraph graph, Object value, Binding binding) + throws DatabaseException { + throw new DatabaseException("Cannot write value to a child variable."); + } + + + @Override + public Resource getRepresents(ReadGraph graph) throws DatabaseException { + Variable parent = getParent(graph); + if(!(parent instanceof AbstractChildVariable)) + return null; + Resource parentRepresents = + ((AbstractChildVariable)parent).getRepresentsForBrowsingChildResources(graph); + if(parentRepresents == null) + return null; + Resource result = graph.syncRequest(new UnescapedChildMapOfResource(parentRepresents)) + .get(getName(graph)); +// System.err.println("getRepresents " + getURI(graph) + " -> parent " + parentRepresents + " " + this + " => " + result + " " + getName(graph)); + return result; + } + + public Resource getRepresentsForBrowsingChildResources(ReadGraph graph) throws DatabaseException { + return getRepresents(graph); + } + + @Override + public Variable getPossibleExtraProperty(ReadGraph graph, String name) throws DatabaseException { + return null; + } + + @Override + public void collectExtraProperties(ReadGraph graph, Map properties) throws DatabaseException { + } + + @Override + protected Variable getPossibleDomainProperty(ReadGraph graph, String name) throws DatabaseException { + return null; + } + + @Override + public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException { + return null; + } + + @Override + public Map collectDomainProperties(ReadGraph graph, Map map) throws DatabaseException { + return map; + } + + @Override + public Collection getChildren(ReadGraph graph) throws DatabaseException { + return Collections.emptyList(); + } + + @Override + public RVIPart getRVIPart(ReadGraph graph) throws DatabaseException { + return new StringRVIPart(Role.CHILD, getName(graph)); + } + + @Override + public Set getClassifications(ReadGraph graph) throws DatabaseException { + return Collections.emptySet(); + } + +}