KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > cmp > ejbql > SimpleNode


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb.plugins.cmp.ejbql;
23
24 /**
25  * Parent class of all abstract syntax tree nodes.
26  *
27  * @author <a HREF="mailto:dain@daingroup.com">Dain Sundstrom</a>
28  * @version $Revision: 37459 $
29  */

30 public class SimpleNode implements Node {
31    protected Node parent;
32    protected Node[] children;
33    protected final int id;
34
35    public SimpleNode(int i) {
36       id = i;
37    }
38
39    public void jjtOpen() {
40    }
41
42    public void jjtClose() {
43    }
44    
45    public void jjtSetParent(Node n) { parent = n; }
46    public Node jjtGetParent() { return parent; }
47
48    public void jjtAddChild(Node n, int i) {
49       if (children == null) {
50          children = new Node[i + 1];
51       } else if (i >= children.length) {
52          Node c[] = new Node[i + 1];
53          System.arraycopy(children, 0, c, 0, children.length);
54          children = c;
55       }
56       children[i] = n;
57    }
58
59    public Node jjtGetChild(int i) {
60       return children[i];
61    }
62
63    public int jjtGetNumChildren() {
64       return (children == null) ? 0 : children.length;
65    }
66
67    /** Accept the visitor. **/
68    public Object JavaDoc jjtAccept(JBossQLParserVisitor visitor, Object JavaDoc data) {
69       return visitor.visit(this, data);
70    }
71
72    /* You can override these two methods in subclasses of SimpleNode to
73        customize the way the node appears when the tree is dumped. If
74        your output uses more than one line you should override
75        toString(String), otherwise overriding toString() is probably all
76        you need to do. */

77
78    public String JavaDoc toString() { return EJBQLParserTreeConstants.jjtNodeName[id]; }
79    public String JavaDoc toString(String JavaDoc prefix) { return prefix + toString(); }
80
81    /* Override this method if you want to customize how the node dumps
82        out its children. */

83
84    public void dump(String JavaDoc prefix) {
85       System.out.println(toString(prefix));
86       if (children != null) {
87          for (int i = 0; i < children.length; ++i) {
88             SimpleNode n = (SimpleNode)children[i];
89             if (n != null) {
90                n.dump(prefix + ' ');
91             }
92          }
93       }
94    }
95 }
96
97
Popular Tags