-package org.simantics.db.layer0.variable;\r
-\r
-import java.util.Collection;\r
-import java.util.Collections;\r
-import java.util.Map;\r
-import java.util.Set;\r
-\r
-import org.simantics.databoard.Bindings;\r
-import org.simantics.databoard.binding.Binding;\r
-import org.simantics.databoard.type.ArrayType;\r
-import org.simantics.databoard.type.Datatype;\r
-import org.simantics.databoard.type.NumberType;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.request.PropertyMapOfResource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.layer0.variable.RVI.RVIPart;\r
-import org.simantics.db.layer0.variable.RVI.StringRVIPart;\r
-import org.simantics.db.layer0.variable.Variables.Role;\r
-\r
-public abstract class AbstractPropertyVariable extends AbstractVariable {\r
-\r
- final protected static Binding datatype_binding = Bindings.getBindingUnchecked(Datatype.class);\r
-\r
- public abstract Resource getPropertyResource(ReadGraph graph) throws DatabaseException;\r
- public abstract Resource getContainerResource(ReadGraph graph) throws DatabaseException;\r
- public abstract Datatype getDatatype(ReadGraph graph) throws DatabaseException;\r
- public abstract Variable getPredicate(ReadGraph graph) throws DatabaseException;\r
-\r
- public AbstractPropertyVariable() {\r
- this(null);\r
- }\r
-\r
- public AbstractPropertyVariable(VariableNode node) {\r
- super(node);\r
- }\r
- \r
- public String getLabel(ReadGraph graph) throws DatabaseException {\r
-\r
- /*\r
- * This should work but doesn't. REPRESENTS incorrectly returns the predicate resource.\r
- * \r
- * \r
- */\r
- \r
- Object value = getPossibleValue(graph);\r
- return value == null ? "<no value>" : value.toString(); \r
- \r
- }\r
- \r
- \r
- public String getUnit(ReadGraph graph) throws DatabaseException {\r
- Datatype dt = getPossibleDatatype(graph);\r
- if (dt == null)\r
- return "";\r
- else if (dt instanceof NumberType) {\r
- String result = ((NumberType) dt).getUnit(); \r
- return result != null ? result : "";\r
- } else if (dt instanceof ArrayType) {\r
- ArrayType at = (ArrayType) dt;\r
- Datatype cdt = at.componentType();\r
- if (cdt instanceof NumberType) {\r
- String result = ((NumberType) cdt).getUnit(); \r
- return result != null ? result : "";\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- @Override\r
- public Role getRole(ReadGraph graph) throws DatabaseException {\r
- return Role.PROPERTY;\r
- }\r
- \r
- @Override\r
- public Collection<Variable> getChildren(ReadGraph graph)\r
- throws DatabaseException {\r
- return Collections.emptyList();\r
- }\r
- \r
- @Override\r
- public Variable getPossibleChild(ReadGraph graph, String name)\r
- throws DatabaseException {\r
- return null;\r
- }\r
- \r
- @Override\r
- protected Variable getPossibleDomainProperty(ReadGraph graph, String name)\r
- throws DatabaseException {\r
- return null;\r
- }\r
- \r
- @Override\r
- public Map<String, Variable> collectDomainProperties(ReadGraph graph,\r
- Map<String, Variable> properties) throws DatabaseException {\r
- return properties;\r
- }\r
-\r
- /**\r
- * @see org.simantics.db.layer0.variable.AbstractVariable#getRepresents(org.simantics.db.ReadGraph)\r
- * \r
- * FIXME: change this method to throw exceptions if representation is\r
- * not found and leave the current logic to\r
- * {@link #getPossibleRepresents(ReadGraph)}.\r
- */\r
- @Override\r
- public Resource getRepresents(ReadGraph graph) throws DatabaseException {\r
- Variable parent = getParent(graph);\r
- if(parent == null)\r
- return null;\r
- Resource parentRepresents = parent.getPossibleRepresents(graph);\r
- if (parentRepresents == null)\r
- return null;\r
- Resource predicate = graph.syncRequest(new PropertyMapOfResource(parentRepresents))\r
- .get(getName(graph));\r
- if (predicate == null)\r
- return null;\r
- return graph.getPossibleObject(parentRepresents, predicate);\r
- }\r
-\r
- @Override\r
- public Resource getPossibleRepresents(ReadGraph graph) throws DatabaseException {\r
- Variable parent = getParent(graph);\r
- if(parent == null)\r
- return null;\r
- Resource parentRepresents = parent.getPossibleRepresents(graph);\r
- if (parentRepresents == null)\r
- return null;\r
- Resource predicate = graph.syncRequest(new PropertyMapOfResource(parentRepresents))\r
- .get(getName(graph));\r
- if (predicate == null)\r
- return null;\r
- return graph.getPossibleObject(parentRepresents, predicate);\r
- }\r
-\r
- @Override\r
- public Variable getPossibleExtraProperty(ReadGraph graph, String name) throws DatabaseException {\r
- /*if(Variables.DATATYPE.equals(name)) {\r
- Object value = getPossibleDatatype(graph);\r
- if (value != null)\r
- return new ConstantPropertyVariable(this, name, value, datatype_binding);\r
- } else if(Variables.UNIT.equals(name)) {\r
- Object value = getUnit(graph);\r
- return new ConstantPropertyVariable(this, name, value, Bindings.STRING);\r
- } else if(Variables.PREDICATE.equals(name)) {\r
- Object value = getPossiblePredicate(graph);\r
- if (value != null)\r
- return new ConstantPropertyVariable(this, name, value, null);\r
- } */\r
- return null;\r
- }\r
- \r
- @Override\r
- public void collectExtraProperties(ReadGraph graph, Map<String, Variable> properties) throws DatabaseException {\r
-// addProperty(properties, Variables.PREDICATE, getPossiblePredicate(graph), null);\r
-// Datatype dt = getPossibleDatatype(graph);\r
-// if(dt != null)\r
-// addProperty(properties, Variables.DATATYPE, dt, datatype_binding);\r
- //addProperty(properties, Variables.UNIT, getUnit(graph), Bindings.STRING);\r
- }\r
- \r
- \r
- @Override\r
- public RVIPart getRVIPart(ReadGraph graph) throws DatabaseException {\r
- return new StringRVIPart(Role.PROPERTY, getName(graph));\r
- }\r
- \r
- @Override\r
- public Set<String> getClassifications(ReadGraph graph) throws DatabaseException {\r
- return Collections.emptySet();\r
- }\r
- \r
-}\r
+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 ? "<no value>" : 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<Variable> 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<String, Variable> collectDomainProperties(ReadGraph graph,
+ Map<String, Variable> 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<String, Variable> 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<String> getClassifications(ReadGraph graph) throws DatabaseException {
+ return Collections.emptySet();
+ }
+
+}