1 package org.simantics.modeling;
3 import java.util.HashMap;
7 import org.simantics.Simantics;
8 import org.simantics.databoard.binding.Binding;
9 import org.simantics.databoard.type.Datatype;
10 import org.simantics.db.ReadGraph;
11 import org.simantics.db.Resource;
12 import org.simantics.db.WriteGraph;
13 import org.simantics.db.exception.DatabaseException;
14 import org.simantics.db.layer0.util.Layer0Utils;
15 import org.simantics.db.layer0.variable.AbstractPropertyVariable;
16 import org.simantics.db.layer0.variable.Variable;
18 class ImmutableComponentPropertyVariable extends AbstractPropertyVariable {
20 final Variable parent;
21 final ImmutableComponentPropertyContent content;
24 public int hashCode() {
27 result = prime * result + ((content == null) ? 0 : content.hashCode());
28 result = prime * result + ((parent == null) ? 0 : parent.hashCode());
33 public boolean equals(Object obj) {
38 if (getClass() != obj.getClass())
40 ImmutableComponentPropertyVariable other = (ImmutableComponentPropertyVariable) obj;
41 if (content == null) {
42 if (other.content != null)
44 } else if (!content.equals(other.content))
47 if (other.parent != null)
49 } else if (!parent.equals(other.parent))
54 ImmutableComponentPropertyVariable(Variable parent, ImmutableComponentPropertyContent content) {
56 this.content = content;
60 public Resource getPropertyResource(ReadGraph graph) throws DatabaseException {
61 return content.pi.predicate;
65 public Resource getPossiblePredicateResource(ReadGraph graph) throws DatabaseException {
66 return content.pi.predicate;
70 public Resource getContainerResource(ReadGraph graph) throws DatabaseException {
71 throw new IllegalStateException();
75 public Datatype getDatatype(ReadGraph graph) throws DatabaseException {
76 return Layer0Utils.getDatatype(graph, this);
80 public Resource getPredicateResource(ReadGraph graph) throws DatabaseException {
81 return content.pi.predicate;
85 public Variable getPredicate(ReadGraph graph) throws DatabaseException {
86 throw new IllegalStateException();
90 public <T> T getValue(ReadGraph graph) throws DatabaseException {
91 if(content.value != null) return (T)content.value;
92 return (T)Simantics.applySCLRead(graph, content.expression, this);
96 public <T> T getValue(ReadGraph graph, Binding binding) throws DatabaseException {
97 if(content.value != null) return (T)content.value;
98 return (T)Simantics.applySCLRead(graph, content.expression, this);
102 public void setValue(WriteGraph graph, Object value, Binding binding) throws DatabaseException {
103 throw new IllegalStateException();
107 public String getName(ReadGraph graph) throws DatabaseException {
108 return content.pi.name;
112 public Variable getParent(ReadGraph graph) throws DatabaseException {
117 public Set<String> getClassifications(ReadGraph graph) throws DatabaseException {
118 return content.pi.classifications;
122 protected Variable getPossibleDomainProperty(ReadGraph graph, String name) throws DatabaseException {
124 if(content.properties == null)
127 ImmutableComponentPropertyContent p = content.properties.get(name);
129 return new ImmutableComponentPropertyVariable(this, p);
136 public Map<String, Variable> collectDomainProperties(ReadGraph graph, Map<String, Variable> map)
137 throws DatabaseException {
139 if(content.properties == null)
143 map = new HashMap<>();
145 for(ImmutableComponentPropertyContent p : content.properties.values()) {
146 map.put(p.pi.name, new ImmutableComponentPropertyVariable(this, p));