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.exception.NonWritableVariableException; 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 NonWritableVariableException("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(); } }