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: /**
14: * An 'and' node. These may participate in joins.
15: */
16: public class AndNode extends Node {
17:
18: public AndNode() {
19: }
20:
21: public Object accept(NodeVisitor visitor, Object[] results) {
22: return visitor.visitAndNode(this , results);
23: }
24:
25: /**
26: * Create a new instance of us.
27: */
28: protected AndNode createInstance() {
29: return new AndNode();
30: }
31:
32: /**
33: * Simplify this node tree as much as possible.
34: */
35: protected void normalizeImp() {
36: if (getClass() != AndNode.class) {
37: super .normalizeImp();
38: return;
39: }
40: // merge children of nested AndNode's into our child list
41: Node prev = null;
42: for (Node n = childList; n != null;) {
43: n.normalizeImp();
44: if (n.getClass() == AndNode.class) {
45: if (n.childList == null) {
46: // no children?? remove it from the list
47: n = n.next;
48: if (prev == null) {
49: childList = n;
50: } else {
51: prev.next = n;
52: }
53: } else {
54: // walk to the end of n's childList and splice that into ours
55: // in place of n
56: Node pos;
57: for (pos = n.childList; pos.next != null; pos = pos.next) {
58: pos.parent = this ;
59: }
60: pos.parent = this ;
61: pos.next = n.next;
62: if (prev == null) {
63: childList = n.childList;
64: } else {
65: prev.next = n.childList;
66: }
67: prev = pos;
68: n = n.next;
69: }
70: } else {
71: prev = n;
72: n = n.next;
73: }
74: }
75: }
76:
77: public Field visit(MemVisitor visitor, Object obj) {
78: return visitor.visitAndNode(this , obj);
79: }
80:
81: public Object arrive(NodeVisitor v, Object msg) {
82: return v.arriveAndNode(this, msg);
83: }
84:
85: }
|