1 package org.simantics.structural2.variables;
\r
3 import java.util.Collections;
\r
4 import java.util.Map;
\r
5 import java.util.Set;
\r
7 import org.simantics.databoard.binding.Binding;
\r
8 import org.simantics.databoard.type.Datatype;
\r
9 import org.simantics.db.ReadGraph;
\r
10 import org.simantics.db.Resource;
\r
11 import org.simantics.db.WriteGraph;
\r
12 import org.simantics.db.exception.DatabaseException;
\r
13 import org.simantics.db.layer0.variable.AbstractPropertyVariable;
\r
14 import org.simantics.db.layer0.variable.Variable;
\r
15 import org.simantics.db.layer0.variable.Variables;
\r
16 import org.simantics.utils.ObjectUtils;
\r
19 * TODO: consider removing this, doesn't seem to be used
\r
21 public class MutablePropertyVariable extends AbstractPropertyVariable {
\r
23 final protected Variable parent;
\r
26 public Object value;
\r
27 public Binding binding;
\r
29 public MutablePropertyVariable(Variable parent, String name) {
\r
30 assert parent != null;
\r
31 assert name != null;
\r
32 this.parent = parent;
\r
36 @SuppressWarnings("unchecked")
\r
38 public <T> T getValue(ReadGraph graph) throws DatabaseException {
\r
42 @SuppressWarnings("unchecked")
\r
44 public <T> T getValue(ReadGraph graph, Binding binding)
\r
45 throws DatabaseException {
\r
50 public void setValue(WriteGraph graph, Object value, Binding binding)
\r
51 throws DatabaseException {
\r
52 throw new DatabaseException("Value is constant.");
\r
56 public String getName(ReadGraph graph) throws DatabaseException {
\r
61 public Resource getType(ReadGraph graph) throws DatabaseException {
\r
66 public Resource getPossibleType(ReadGraph graph) throws DatabaseException {
\r
71 public Resource getType(ReadGraph graph, Resource baseType)throws DatabaseException {
\r
76 public Resource getPossibleType(ReadGraph graph, Resource baseType) throws DatabaseException {
\r
81 // public Object getSerialized(ReadGraph graph) throws DatabaseException {
\r
86 public Variable getParent(ReadGraph graph) throws DatabaseException {
\r
91 public Resource getRepresents(ReadGraph graph) throws DatabaseException {
\r
96 public Datatype getDatatype(ReadGraph graph) throws DatabaseException {
\r
97 return binding != null ? binding.type() : null;
\r
101 public Resource getPropertyResource(ReadGraph graph) throws DatabaseException {
\r
106 public Resource getContainerResource(ReadGraph graph) throws DatabaseException {
\r
111 public Variable getPredicate(ReadGraph graph) throws DatabaseException {
\r
116 protected Variable getPossibleDomainProperty(ReadGraph graph, String name)
\r
117 throws DatabaseException {
\r
122 public Map<String, Variable> collectDomainProperties(ReadGraph graph,
\r
123 Map<String, Variable> properties) throws DatabaseException {
\r
128 public Set<String> getClassifications(ReadGraph graph) throws DatabaseException {
\r
129 Variable property = getPossibleDomainProperty(graph, Variables.CLASSIFICATIONS);
\r
130 if(property != null) return property.getValue(graph);
\r
131 else return Collections.emptySet();
\r
135 public int hashCode() {
\r
136 final int prime = 31;
\r
138 result = prime * result + name.hashCode();
\r
139 result = prime * result + parent.hashCode();
\r
140 result = prime * result + ((value == null) ? 0 : value.hashCode());
\r
141 result = prime * result + ((binding == null) ? 0 : binding.hashCode());
\r
146 public boolean equals(Object obj) {
\r
151 if (getClass() != obj.getClass())
\r
153 MutablePropertyVariable other = (MutablePropertyVariable) obj;
\r
154 if (!name.equals(other.name))
\r
156 if (!parent.equals(other.parent))
\r
158 if (!ObjectUtils.objectEquals(value, other.value))
\r
160 return ObjectUtils.objectEquals(binding, other.binding);
\r