1 package org.simantics.db.layer0.variable;
3 import java.util.ArrayList;
4 import java.util.Collection;
6 import org.simantics.db.ReadGraph;
7 import org.simantics.db.exception.DatabaseException;
9 public class ProxyChildVariable extends AbstractChildVariable {
11 public static final String CONTEXT_BEGIN = ">>>";
12 public static final String CONTEXT_END = "<<<";
14 // This is the variable that shall be returned to
15 protected final Variable base;
16 // Actual parent of this variable
17 protected final Variable parent;
18 // This is the accumulated context variable that is queries for children
19 protected final Variable other;
20 protected final String name;
22 public ProxyChildVariable(Variable base, Variable parent, Variable other, String name) {
24 assert(parent != null);
25 assert(other != null);
33 public Variable other() {
37 public Variable base() {
42 public String getName(ReadGraph graph) throws DatabaseException {
46 public Variable getParent(ReadGraph graph) throws DatabaseException {
50 public Variable getPossibleChild(ReadGraph graph, String name) throws DatabaseException {
51 Variable otherChild = other.getPossibleChild(graph, name);
52 if(otherChild == null) return null;
53 return create(base, this, otherChild, name);
56 public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {
58 ArrayList<Variable> result = new ArrayList<Variable>();
59 Collection<Variable> otherChildren = other.browseChildren(graph);
60 for(Variable o : otherChildren) {
61 result.add(create(base, this, o, o.getName(graph)));
67 public Variable getPossibleProperty(ReadGraph graph, String name) throws DatabaseException {
68 Variable otherChild = other.getPossibleProperty(graph, name);
69 if(otherChild == null) return null;
70 return create(base, this, otherChild, name);
73 public Variable create(Variable base, Variable parent, Variable other, String name) {
74 return new ProxyChildVariable(base, parent, other, name);
78 public int hashCode() {
81 result = prime * result + (base != null ? base.hashCode() : 0);
82 result = prime * result + (parent != null ? parent.hashCode() : 0);
83 result = prime * result + (other != null ? other.hashCode() : 0);
84 result = prime * result + (name != null ? name.hashCode() : 0);
89 public boolean equals(Object obj) {
95 if (getClass() != obj.getClass())
98 ProxyChildVariable proxy = (ProxyChildVariable) obj;
101 if(!base.equals(proxy.base)) return false;
102 } else if (proxy.base != null) return false;
105 if(!parent.equals(proxy.parent)) return false;
106 } else if (proxy.parent != null) return false;
109 if(!other.equals(proxy.other)) return false;
110 } else if (proxy.other != null) return false;
113 if(!name.equals(proxy.name)) return false;
114 } else if (proxy.name != null) return false;