01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.ejb.query;
12:
13: /**
14: * An expression. Has a next pointer so these can be easily chained together
15: * into lists.
16: */
17: public abstract class Node {
18:
19: private Node next;
20:
21: public Node() {
22: }
23:
24: public Node getNext() {
25: return next;
26: }
27:
28: public void setNext(Node next) {
29: this .next = next;
30: }
31:
32: public void appendList(StringBuffer s) {
33: appendList(s, ", ");
34: }
35:
36: public void appendList(StringBuffer s, String separator) {
37: s.append(this );
38: if (next != null) {
39: for (Node i = next; i != null; i = i.next) {
40: s.append(separator);
41: s.append(i);
42: }
43: }
44: }
45:
46: public String toString() {
47: String s = getClass().getName();
48: int i = s.lastIndexOf('.') + 1;
49: int j = s.lastIndexOf("Node");
50: StringBuffer b = new StringBuffer();
51: b.append('{');
52: if (j >= 0) {
53: b.append(s.substring(i, j));
54: } else {
55: b.append(s.substring(i));
56: }
57: b.append(' ');
58: b.append(toStringImp());
59: b.append('}');
60: return b.toString();
61: }
62:
63: public abstract String toStringImp();
64:
65: /**
66: * Attach type information to the Nodes using rc.
67: */
68: public void resolve(ResolveContext rc) {
69: }
70:
71: /**
72: * Call resolve on each node in list. NOP if list is null.
73: */
74: protected static void resolve(Node list, ResolveContext rc) {
75: for (; list != null; list = list.next) {
76: list.resolve(rc);
77: }
78: }
79:
80: /**
81: * Invoke v's arriveXXX method for the node.
82: */
83: public abstract Object arrive(NodeVisitor v, Object msg);
84:
85: }
|