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 System.err.println("other: " + other.getURI(graph) + " " + name );
52 Variable otherChild = other.getPossibleChild(graph, name);
53 if(otherChild == null) return null;
54 return create(base, this, otherChild, name);
57 public Collection<Variable> getChildren(ReadGraph graph) throws DatabaseException {
59 ArrayList<Variable> result = new ArrayList<Variable>();
60 Collection<Variable> otherChildren = other.browseChildren(graph);
61 for(Variable o : otherChildren) {
62 result.add(create(base, this, o, o.getName(graph)));
68 public Variable getPossibleProperty(ReadGraph graph, String name) throws DatabaseException {
69 Variable otherChild = other.getPossibleProperty(graph, name);
70 if(otherChild == null) return null;
71 return create(base, this, otherChild, name);
74 public Variable create(Variable base, Variable parent, Variable other, String name) {
75 return new ProxyChildVariable(base, parent, other, name);
79 public int hashCode() {
82 result = prime * result + (base != null ? base.hashCode() : 0);
83 result = prime * result + (parent != null ? parent.hashCode() : 0);
84 result = prime * result + (other != null ? other.hashCode() : 0);
85 result = prime * result + (name != null ? name.hashCode() : 0);
90 public boolean equals(Object obj) {
96 if (getClass() != obj.getClass())
99 ProxyChildVariable proxy = (ProxyChildVariable) obj;
102 if(!base.equals(proxy.base)) return false;
103 } else if (proxy.base != null) return false;
106 if(!parent.equals(proxy.parent)) return false;
107 } else if (proxy.parent != null) return false;
110 if(!other.equals(proxy.other)) return false;
111 } else if (proxy.other != null) return false;
114 if(!name.equals(proxy.name)) return false;
115 } else if (proxy.name != null) return false;