1 2 12 package com.versant.core.jdo.query; 13 14 import com.versant.core.metadata.ClassMetaData; 15 import com.versant.core.common.Debug; 16 import com.versant.core.common.CmdBitSet; 17 18 import com.versant.core.common.BindingSupportImpl; 19 20 23 public abstract class Node { 24 25 28 public Node parent; 29 33 public Node next; 34 37 public Node childList; 38 39 public String asValue; 40 41 public Node() { 42 } 43 44 public String toString() { 45 return toStr(); 46 } 47 48 private String toStr() { 49 String n = getClass().getName(); 50 int i = n.lastIndexOf('.'); 51 if (i >= 0) n = n.substring(i + 1); 52 return n + "@" + Integer.toHexString(System.identityHashCode(this)); 53 } 54 55 58 public void dump(String indent) { 59 dumpThis(indent); 60 indent = indent + " "; 61 for (Node c = childList; c != null; c = c.next) c.dump(indent); 62 } 63 64 67 protected void dumpThis(String indent) { 68 Debug.OUT.println(indent + this + " parent " + 69 (parent == null ? "(null)" : parent.toStr())); 70 } 71 72 75 public void dumpList() { 76 dumpThis(""); 77 for (Node c = next; c != null; c = c.next) c.dumpThis(" -> "); 78 } 79 80 84 public void resolve(QueryParser comp, ClassMetaData cmd, boolean ordering) { 85 if (Debug.DEBUG) System.out.println("### Node.resolve " + this); 86 for (Node c = childList; c != null; c = c.next) c.resolve(comp, cmd, ordering); 87 } 88 89 92 public void setParentOnChildren() { 93 for (Node c = childList; c != null; c = c.next) c.parent = this; 94 } 95 96 99 public void replaceChild(Node old, Node nw) { 100 if (childList == old) { 101 nw.next = childList.next; 102 childList = nw; 103 nw.parent = this; 104 return; 105 } 106 for (Node c = childList; ; ) { 107 Node next = c.next; 108 if (next == old) { 109 nw.next = next.next; 110 c.next = nw; 111 nw.parent = this; 112 return; 113 } 114 if (next == null) break; 115 c = next; 116 } 117 throw BindingSupportImpl.getInstance().internal("no such Node: " + old); 118 } 119 120 123 public void insertChildBefore(Node pos, Node nw) { 124 if (childList == pos) { 125 nw.next = pos; 126 childList = nw; 127 nw.parent = this; 128 return; 129 } 130 for (Node c = childList; ; ) { 131 Node next = c.next; 132 if (next == pos) { 133 nw.next = pos; 134 c.next = nw; 135 nw.parent = this; 136 return; 137 } 138 if (next == null) break; 139 c = next; 140 } 141 throw BindingSupportImpl.getInstance().internal("no such Node: " + pos); 142 } 143 144 147 public final void normalize() { 148 normalizeImp(); 149 if (Debug.DEBUG) checkIntegrity(); 150 } 151 152 155 protected void normalizeImp() { 156 for (Node c = childList; c != null; c = c.next) { 157 c.normalizeImp(); 158 } 159 } 160 161 164 public abstract Field visit(MemVisitor visitor, Object obj); 165 166 public Object accept(NodeVisitor visitor, Object [] results) { 167 throw BindingSupportImpl.getInstance().internal("Not supported for node " + 168 this.getClass().getName()); 169 } 170 171 177 public void updateEvictionDependency(CmdBitSet bitSet) { 178 } 179 180 185 public void checkIntegrity() { 186 for (Node i = childList; i != null; i = i.next) { 187 if (i.parent != this) { 188 throw new IllegalStateException ( 189 "Bad child node parent reference:\n" + 190 "Parent: " + this + "\n" + 191 "Child: " + i); 192 } 193 } 194 for (Node i = childList; i != null; i = i.next) i.checkIntegrity(); 195 } 196 197 200 public abstract Object arrive(NodeVisitor v, Object msg); 201 202 } 203 | Popular Tags |