001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb.plugins.cmp.ejbql;
023:
024: /**
025: * Parent class of all abstract syntax tree nodes.
026: *
027: * @author <a href="mailto:dain@daingroup.com">Dain Sundstrom</a>
028: * @version $Revision: 57209 $
029: */
030: public class SimpleNode implements Node {
031: protected Node parent;
032: protected Node[] children;
033: protected final int id;
034:
035: public SimpleNode(int i) {
036: id = i;
037: }
038:
039: public void jjtOpen() {
040: }
041:
042: public void jjtClose() {
043: }
044:
045: public void jjtSetParent(Node n) {
046: parent = n;
047: }
048:
049: public Node jjtGetParent() {
050: return parent;
051: }
052:
053: public void jjtAddChild(Node n, int i) {
054: if (children == null) {
055: children = new Node[i + 1];
056: } else if (i >= children.length) {
057: Node c[] = new Node[i + 1];
058: System.arraycopy(children, 0, c, 0, children.length);
059: children = c;
060: }
061: children[i] = n;
062: }
063:
064: public Node jjtGetChild(int i) {
065: return children[i];
066: }
067:
068: public int jjtGetNumChildren() {
069: return (children == null) ? 0 : children.length;
070: }
071:
072: /** Accept the visitor. **/
073: public Object jjtAccept(JBossQLParserVisitor visitor, Object data) {
074: return visitor.visit(this , data);
075: }
076:
077: /* You can override these two methods in subclasses of SimpleNode to
078: customize the way the node appears when the tree is dumped. If
079: your output uses more than one line you should override
080: toString(String), otherwise overriding toString() is probably all
081: you need to do. */
082:
083: public String toString() {
084: return EJBQLParserTreeConstants.jjtNodeName[id];
085: }
086:
087: public String toString(String prefix) {
088: return prefix + toString();
089: }
090:
091: /* Override this method if you want to customize how the node dumps
092: out its children. */
093:
094: public void dump(String prefix) {
095: System.out.println(toString(prefix));
096: if (children != null) {
097: for (int i = 0; i < children.length; ++i) {
098: SimpleNode n = (SimpleNode) children[i];
099: if (n != null) {
100: n.dump(prefix + ' ');
101: }
102: }
103: }
104: }
105: }
|