1 package org.simantics.modeling;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6 import java.util.HashMap;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.Resource;
11 import org.simantics.db.exception.DatabaseException;
12 import org.simantics.db.layer0.variable.AbstractChildVariable;
13 import org.simantics.db.layer0.variable.StandardGraphChildVariable;
14 import org.simantics.db.layer0.variable.Variable;
16 public class ImmutableComponentVariable extends AbstractChildVariable {
19 public int hashCode() {
22 result = prime * result + ((content == null) ? 0 : content.hashCode());
23 result = prime * result + ((parent == null) ? 0 : parent.hashCode());
28 public boolean equals(Object obj) {
33 if (getClass() != obj.getClass())
35 ImmutableComponentVariable other = (ImmutableComponentVariable) obj;
36 if (content == null) {
37 if (other.content != null)
39 } else if (!content.equals(other.content))
42 if (other.parent != null)
44 } else if (!parent.equals(other.parent))
49 final private Variable parent;
50 final private ImmutableComponentVariableContent content;
52 ImmutableComponentVariable(Variable parent, ImmutableComponentVariableContent content) {
54 this.content = content;
58 public String getName(ReadGraph graph) throws DatabaseException {
63 public Variable getParent(ReadGraph graph) throws DatabaseException {
68 public Resource getRepresents(ReadGraph graph) throws DatabaseException {
69 return content.resource;
73 public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {
74 if(content.children == null) return null;
75 ImmutableComponentVariableContent c = content.children.get(name);
76 if(c == null) return null;
77 return new ImmutableComponentVariable(this, c);
81 public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {
82 if(content.children == null) return Collections.emptyList();
83 ArrayList<Variable> result = new ArrayList<Variable>(content.children.size());
84 for(ImmutableComponentVariableContent c : content.children.values()) {
85 result.add(new ImmutableComponentVariable(this, c));
91 protected Variable getPossibleDomainProperty(ReadGraph graph, String name) throws DatabaseException {
93 if(content.properties == null)
96 ImmutableComponentPropertyContent p = content.properties.get(name);
98 return new ImmutableComponentPropertyVariable(this, p);
100 return new StandardGraphChildVariable(parent, node, content.resource).getPossibleProperty(graph, name);
105 public Map<String, Variable> collectDomainProperties(ReadGraph graph, Map<String, Variable> map)
106 throws DatabaseException {
108 if(content.properties == null)
112 map = new HashMap<>();
114 for(ImmutableComponentPropertyContent p : content.properties.values()) {
115 map.put(p.pi.name, new ImmutableComponentPropertyVariable(this, p));