]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.structural2/src/org/simantics/structural2/variables/MutablePropertyVariable.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.structural2 / src / org / simantics / structural2 / variables / MutablePropertyVariable.java
1 package org.simantics.structural2.variables;\r
2 \r
3 import java.util.Collections;\r
4 import java.util.Map;\r
5 import java.util.Set;\r
6 \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
17 \r
18 /**\r
19  * TODO: consider removing this, doesn't seem to be used\r
20  */\r
21 public class MutablePropertyVariable extends AbstractPropertyVariable {\r
22 \r
23     final protected Variable parent;\r
24     final String name;\r
25 \r
26     public Object value;\r
27     public Binding binding;\r
28     \r
29     public MutablePropertyVariable(Variable parent, String name) {\r
30         assert parent != null;\r
31         assert name != null;\r
32         this.parent = parent;\r
33         this.name = name;\r
34     }\r
35 \r
36     @SuppressWarnings("unchecked")\r
37     @Override\r
38     public <T> T getValue(ReadGraph graph) throws DatabaseException {\r
39         return (T)value;\r
40     }\r
41 \r
42     @SuppressWarnings("unchecked")\r
43     @Override\r
44     public <T> T getValue(ReadGraph graph, Binding binding)\r
45             throws DatabaseException {\r
46         return (T)value;\r
47     }\r
48 \r
49     @Override\r
50     public void setValue(WriteGraph graph, Object value, Binding binding)\r
51             throws DatabaseException {\r
52         throw new DatabaseException("Value is constant.");\r
53     }\r
54 \r
55     @Override\r
56     public String getName(ReadGraph graph) throws DatabaseException {\r
57         return name;\r
58     }\r
59 \r
60     @Override\r
61     public Resource getType(ReadGraph graph) throws DatabaseException {\r
62         return null;\r
63     }\r
64 \r
65     @Override\r
66     public Resource getPossibleType(ReadGraph graph) throws DatabaseException {\r
67         return null;\r
68     }\r
69 \r
70     @Override\r
71     public Resource getType(ReadGraph graph, Resource baseType)throws DatabaseException {\r
72         return null;\r
73     }\r
74 \r
75     @Override\r
76     public Resource getPossibleType(ReadGraph graph, Resource baseType) throws DatabaseException {\r
77         return null;\r
78     }\r
79 \r
80 //    @Override\r
81 //    public Object getSerialized(ReadGraph graph) throws DatabaseException {\r
82 //        return name;\r
83 //    }\r
84 \r
85     @Override\r
86     public Variable getParent(ReadGraph graph) throws DatabaseException {\r
87         return parent;\r
88     }\r
89 \r
90     @Override\r
91     public Resource getRepresents(ReadGraph graph) throws DatabaseException {\r
92         return null;\r
93     }\r
94     \r
95     @Override\r
96     public Datatype getDatatype(ReadGraph graph) throws DatabaseException {\r
97         return binding != null ? binding.type() : null;\r
98     }\r
99     \r
100     @Override\r
101     public Resource getPropertyResource(ReadGraph graph) throws DatabaseException {\r
102         return null;\r
103     }\r
104 \r
105     @Override\r
106     public Resource getContainerResource(ReadGraph graph) throws DatabaseException {\r
107         return null;\r
108     }\r
109     \r
110     @Override\r
111     public Variable getPredicate(ReadGraph graph) throws DatabaseException {\r
112         return null;\r
113     }\r
114     \r
115     @Override\r
116     protected Variable getPossibleDomainProperty(ReadGraph graph, String name)\r
117                 throws DatabaseException {\r
118         return null;\r
119     }\r
120 \r
121     @Override\r
122     public Map<String, Variable> collectDomainProperties(ReadGraph graph,\r
123                 Map<String, Variable> properties) throws DatabaseException {\r
124         return properties;\r
125     }\r
126     \r
127     @Override\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
132     }\r
133     \r
134     @Override\r
135     public int hashCode() {\r
136         final int prime = 31;\r
137         int result = 1;\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
142         return result;\r
143     }\r
144 \r
145     @Override\r
146     public boolean equals(Object obj) {\r
147         if (this == obj)\r
148             return true;\r
149         if (obj == null)\r
150             return false;\r
151         if (getClass() != obj.getClass())\r
152             return false;\r
153         MutablePropertyVariable other = (MutablePropertyVariable) obj;\r
154         if (!name.equals(other.name))\r
155             return false;\r
156         if (!parent.equals(other.parent))\r
157             return false;\r
158         if (!ObjectUtils.objectEquals(value, other.value))\r
159             return false;\r
160         return ObjectUtils.objectEquals(binding, other.binding);\r
161     }\r
162 \r
163 }\r