X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fvariable%2FAbstractPropertyVariable.java;h=86989fd36b6ce363a4a3c2584ee6b3b23bbeb1a8;hb=035118aa5f35c9e5acd1f34d22065055dfdee486;hp=e33ad89b6dbd3cb9ae80720029e88d9c0926d483;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractPropertyVariable.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractPropertyVariable.java index e33ad89b6..86989fd36 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractPropertyVariable.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/AbstractPropertyVariable.java @@ -1,173 +1,173 @@ -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.Bindings; -import org.simantics.databoard.binding.Binding; -import org.simantics.databoard.type.ArrayType; -import org.simantics.databoard.type.Datatype; -import org.simantics.databoard.type.NumberType; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.common.request.PropertyMapOfResource; -import org.simantics.db.exception.DatabaseException; -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 AbstractPropertyVariable extends AbstractVariable { - - final protected static Binding datatype_binding = Bindings.getBindingUnchecked(Datatype.class); - - public abstract Resource getPropertyResource(ReadGraph graph) throws DatabaseException; - public abstract Resource getContainerResource(ReadGraph graph) throws DatabaseException; - public abstract Datatype getDatatype(ReadGraph graph) throws DatabaseException; - public abstract Variable getPredicate(ReadGraph graph) throws DatabaseException; - - public AbstractPropertyVariable() { - this(null); - } - - public AbstractPropertyVariable(VariableNode node) { - super(node); - } - - public String getLabel(ReadGraph graph) throws DatabaseException { - - /* - * This should work but doesn't. REPRESENTS incorrectly returns the predicate resource. - * - * - */ - - Object value = getPossibleValue(graph); - return value == null ? "" : value.toString(); - - } - - - public String getUnit(ReadGraph graph) throws DatabaseException { - Datatype dt = getPossibleDatatype(graph); - if (dt == null) - return ""; - else if (dt instanceof NumberType) { - String result = ((NumberType) dt).getUnit(); - return result != null ? result : ""; - } else if (dt instanceof ArrayType) { - ArrayType at = (ArrayType) dt; - Datatype cdt = at.componentType(); - if (cdt instanceof NumberType) { - String result = ((NumberType) cdt).getUnit(); - return result != null ? result : ""; - } - } - return null; - } - - @Override - public Role getRole(ReadGraph graph) throws DatabaseException { - return Role.PROPERTY; - } - - @Override - public Collection getChildren(ReadGraph graph) - throws DatabaseException { - return Collections.emptyList(); - } - - @Override - public Variable getPossibleChild(ReadGraph graph, String name) - throws DatabaseException { - return null; - } - - @Override - protected Variable getPossibleDomainProperty(ReadGraph graph, String name) - throws DatabaseException { - return null; - } - - @Override - public Map collectDomainProperties(ReadGraph graph, - Map properties) throws DatabaseException { - return properties; - } - - /** - * @see org.simantics.db.layer0.variable.AbstractVariable#getRepresents(org.simantics.db.ReadGraph) - * - * FIXME: change this method to throw exceptions if representation is - * not found and leave the current logic to - * {@link #getPossibleRepresents(ReadGraph)}. - */ - @Override - public Resource getRepresents(ReadGraph graph) throws DatabaseException { - Variable parent = getParent(graph); - if(parent == null) - return null; - Resource parentRepresents = parent.getPossibleRepresents(graph); - if (parentRepresents == null) - return null; - Resource predicate = graph.syncRequest(new PropertyMapOfResource(parentRepresents)) - .get(getName(graph)); - if (predicate == null) - return null; - return graph.getPossibleObject(parentRepresents, predicate); - } - - @Override - public Resource getPossibleRepresents(ReadGraph graph) throws DatabaseException { - Variable parent = getParent(graph); - if(parent == null) - return null; - Resource parentRepresents = parent.getPossibleRepresents(graph); - if (parentRepresents == null) - return null; - Resource predicate = graph.syncRequest(new PropertyMapOfResource(parentRepresents)) - .get(getName(graph)); - if (predicate == null) - return null; - return graph.getPossibleObject(parentRepresents, predicate); - } - - @Override - public Variable getPossibleExtraProperty(ReadGraph graph, String name) throws DatabaseException { - /*if(Variables.DATATYPE.equals(name)) { - Object value = getPossibleDatatype(graph); - if (value != null) - return new ConstantPropertyVariable(this, name, value, datatype_binding); - } else if(Variables.UNIT.equals(name)) { - Object value = getUnit(graph); - return new ConstantPropertyVariable(this, name, value, Bindings.STRING); - } else if(Variables.PREDICATE.equals(name)) { - Object value = getPossiblePredicate(graph); - if (value != null) - return new ConstantPropertyVariable(this, name, value, null); - } */ - return null; - } - - @Override - public void collectExtraProperties(ReadGraph graph, Map properties) throws DatabaseException { -// addProperty(properties, Variables.PREDICATE, getPossiblePredicate(graph), null); -// Datatype dt = getPossibleDatatype(graph); -// if(dt != null) -// addProperty(properties, Variables.DATATYPE, dt, datatype_binding); - //addProperty(properties, Variables.UNIT, getUnit(graph), Bindings.STRING); - } - - - @Override - public RVIPart getRVIPart(ReadGraph graph) throws DatabaseException { - return new StringRVIPart(Role.PROPERTY, 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.Bindings; +import org.simantics.databoard.binding.Binding; +import org.simantics.databoard.type.ArrayType; +import org.simantics.databoard.type.Datatype; +import org.simantics.databoard.type.NumberType; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.PropertyMapOfResource; +import org.simantics.db.exception.DatabaseException; +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 AbstractPropertyVariable extends AbstractVariable { + + final protected static Binding datatype_binding = Bindings.getBindingUnchecked(Datatype.class); + + public abstract Resource getPropertyResource(ReadGraph graph) throws DatabaseException; + public abstract Resource getContainerResource(ReadGraph graph) throws DatabaseException; + public abstract Datatype getDatatype(ReadGraph graph) throws DatabaseException; + public abstract Variable getPredicate(ReadGraph graph) throws DatabaseException; + + public AbstractPropertyVariable() { + this(null); + } + + public AbstractPropertyVariable(VariableNode node) { + super(node); + } + + public String getLabel(ReadGraph graph) throws DatabaseException { + + /* + * This should work but doesn't. REPRESENTS incorrectly returns the predicate resource. + * + * + */ + + Object value = getPossibleValue(graph); + return value == null ? "" : value.toString(); + + } + + + public String getUnit(ReadGraph graph) throws DatabaseException { + Datatype dt = getPossibleDatatype(graph); + if (dt == null) + return ""; + else if (dt instanceof NumberType) { + String result = ((NumberType) dt).getUnit(); + return result != null ? result : ""; + } else if (dt instanceof ArrayType) { + ArrayType at = (ArrayType) dt; + Datatype cdt = at.componentType(); + if (cdt instanceof NumberType) { + String result = ((NumberType) cdt).getUnit(); + return result != null ? result : ""; + } + } + return null; + } + + @Override + public Role getRole(ReadGraph graph) throws DatabaseException { + return Role.PROPERTY; + } + + @Override + public Collection getChildren(ReadGraph graph) + throws DatabaseException { + return Collections.emptyList(); + } + + @Override + public Variable getPossibleChild(ReadGraph graph, String name) + throws DatabaseException { + return null; + } + + @Override + protected Variable getPossibleDomainProperty(ReadGraph graph, String name) + throws DatabaseException { + return null; + } + + @Override + public Map collectDomainProperties(ReadGraph graph, + Map properties) throws DatabaseException { + return properties; + } + + /** + * @see org.simantics.db.layer0.variable.AbstractVariable#getRepresents(org.simantics.db.ReadGraph) + * + * FIXME: change this method to throw exceptions if representation is + * not found and leave the current logic to + * {@link #getPossibleRepresents(ReadGraph)}. + */ + @Override + public Resource getRepresents(ReadGraph graph) throws DatabaseException { + Variable parent = getParent(graph); + if(parent == null) + return null; + Resource parentRepresents = parent.getPossibleRepresents(graph); + if (parentRepresents == null) + return null; + Resource predicate = graph.syncRequest(new PropertyMapOfResource(parentRepresents)) + .get(getName(graph)); + if (predicate == null) + return null; + return graph.getPossibleObject(parentRepresents, predicate); + } + + @Override + public Resource getPossibleRepresents(ReadGraph graph) throws DatabaseException { + Variable parent = getParent(graph); + if(parent == null) + return null; + Resource parentRepresents = parent.getPossibleRepresents(graph); + if (parentRepresents == null) + return null; + Resource predicate = graph.syncRequest(new PropertyMapOfResource(parentRepresents)) + .get(getName(graph)); + if (predicate == null) + return null; + return graph.getPossibleObject(parentRepresents, predicate); + } + + @Override + public Variable getPossibleExtraProperty(ReadGraph graph, String name) throws DatabaseException { + /*if(Variables.DATATYPE.equals(name)) { + Object value = getPossibleDatatype(graph); + if (value != null) + return new ConstantPropertyVariable(this, name, value, datatype_binding); + } else if(Variables.UNIT.equals(name)) { + Object value = getUnit(graph); + return new ConstantPropertyVariable(this, name, value, Bindings.STRING); + } else if(Variables.PREDICATE.equals(name)) { + Object value = getPossiblePredicate(graph); + if (value != null) + return new ConstantPropertyVariable(this, name, value, null); + } */ + return null; + } + + @Override + public void collectExtraProperties(ReadGraph graph, Map properties) throws DatabaseException { +// addProperty(properties, Variables.PREDICATE, getPossiblePredicate(graph), null); +// Datatype dt = getPossibleDatatype(graph); +// if(dt != null) +// addProperty(properties, Variables.DATATYPE, dt, datatype_binding); + //addProperty(properties, Variables.UNIT, getUnit(graph), Bindings.STRING); + } + + + @Override + public RVIPart getRVIPart(ReadGraph graph) throws DatabaseException { + return new StringRVIPart(Role.PROPERTY, getName(graph)); + } + + @Override + public Set getClassifications(ReadGraph graph) throws DatabaseException { + return Collections.emptySet(); + } + +}