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.jdo.query;
12:
13: import com.versant.core.metadata.ClassMetaData;
14:
15: import com.versant.core.common.Debug;
16:
17: import com.versant.core.common.BindingSupportImpl;
18:
19: /**
20: * A node with a single child. This is optimized to treat childList as a
21: * single node and not a list.
22: */
23: public class UnaryNode extends Node {
24:
25: public UnaryNode() {
26: }
27:
28: public UnaryNode(Node child) {
29: childList = child;
30: child.parent = this ;
31: }
32:
33: public Object accept(NodeVisitor visitor, Object[] results) {
34: return visitor.visitUnaryNode(this , results);
35: }
36:
37: /**
38: * Resolve field refs and so on relative to the compiler. This must
39: * recursively resolve any child nodes.
40: */
41: public void resolve(QueryParser comp, ClassMetaData cmd,
42: boolean ordering) {
43: if (Debug.DEBUG)
44: System.out.println("### UnaryNode.resolve " + this );
45: childList.resolve(comp, cmd, false);
46: }
47:
48: /**
49: * Replace one node with another.
50: */
51: public void replaceChild(Node old, Node nw) {
52: if (childList == old)
53: childList = nw;
54: else
55: throw BindingSupportImpl.getInstance().internal(
56: "no such Node: " + old);
57: nw.parent = this ;
58: nw.next = null;
59: }
60:
61: /**
62: * Simplify this node tree as much as possible.
63: */
64: protected void normalizeImp() {
65: if (childList != null)
66: childList.normalizeImp();
67: }
68:
69: public Field visit(MemVisitor visitor, Object obj) {
70: return visitor.visitUnaryNode(this , obj);
71: }
72:
73: public Object arrive(NodeVisitor v, Object msg) {
74: return v.arriveUnaryNode(this, msg);
75: }
76:
77: }
|