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;
15 import org.simantics.structural.stubs.StructuralResource2;
17 public class ImmutableComponentVariable extends AbstractChildVariable {
20 public int hashCode() {
23 result = prime * result + ((content == null) ? 0 : content.hashCode());
24 result = prime * result + ((parent == null) ? 0 : parent.hashCode());
29 public boolean equals(Object obj) {
34 if (getClass() != obj.getClass())
36 ImmutableComponentVariable other = (ImmutableComponentVariable) obj;
37 if (content == null) {
38 if (other.content != null)
40 } else if (!content.equals(other.content))
43 if (other.parent != null)
45 } else if (!parent.equals(other.parent))
50 final private Variable parent;
51 final private ImmutableComponentVariableContent content;
53 ImmutableComponentVariable(Variable parent, ImmutableComponentVariableContent content) {
55 this.content = content;
59 public String getName(ReadGraph graph) throws DatabaseException {
64 public Variable getParent(ReadGraph graph) throws DatabaseException {
69 public Resource getRepresents(ReadGraph graph) throws DatabaseException {
70 return content.resource;
74 public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {
76 if(content.procedural) {
77 return new StandardGraphChildVariable(parent, null, content.resource).getPossibleChild(graph, name);
80 if(content.children == null) return null;
81 ImmutableComponentVariableContent c = content.children.get(name);
82 if(c == null) return null;
83 return new ImmutableComponentVariable(this, c);
87 public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {
89 if(content.procedural) {
90 return new StandardGraphChildVariable(parent, null, content.resource).getChildren(graph);
93 if(content.children == null) return Collections.emptyList();
94 ArrayList<Variable> result = new ArrayList<Variable>(content.children.size());
95 for(ImmutableComponentVariableContent c : content.children.values()) {
96 result.add(new ImmutableComponentVariable(this, c));
103 protected Variable getPossibleDomainProperty(ReadGraph graph, String name) throws DatabaseException {
105 if(content.properties == null)
108 ImmutableComponentPropertyContent p = content.properties.get(name);
110 return new ImmutableComponentPropertyVariable(this, p);
112 return new StandardGraphChildVariable(parent, node, content.resource).getPossibleProperty(graph, name);
117 public Map<String, Variable> collectDomainProperties(ReadGraph graph, Map<String, Variable> map)
118 throws DatabaseException {
120 if(content.properties == null)
124 map = new HashMap<>();
126 for(ImmutableComponentPropertyContent p : content.properties.values()) {
127 map.put(p.pi.name, new ImmutableComponentPropertyVariable(this, p));