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