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