KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aop > pointcut > ast > 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
23 package org.jboss.aop.pointcut.ast;
24
25 public class SimpleNode implements Node {
26   protected Node parent;
27   protected Node[] children;
28   protected int id;
29   protected Object JavaDoc parser;
30
31   public SimpleNode(int i) {
32     id = i;
33   }
34
35   public SimpleNode(Object JavaDoc p, int i) {
36     this(i);
37     parser = p;
38   }
39
40   public void jjtOpen() {
41   }
42
43   public void jjtClose() {
44   }
45   
46   public void jjtSetParent(Node n) { parent = n; }
47   public Node jjtGetParent() { return parent; }
48
49   public void jjtAddChild(Node n, int i) {
50     if (children == null) {
51       children = new Node[i + 1];
52     } else if (i >= children.length) {
53       Node c[] = new Node[i + 1];
54       System.arraycopy(children, 0, c, 0, children.length);
55       children = c;
56     }
57     children[i] = n;
58   }
59
60   public Node jjtGetChild(int i) {
61     return children[i];
62   }
63
64   public int jjtGetNumChildren() {
65     return (children == null) ? 0 : children.length;
66   }
67
68   /** Accept the visitor. **/
69   public Object JavaDoc jjtAccept(PointcutExpressionParserVisitor visitor, Object JavaDoc data) {
70     return visitor.visit(this, data);
71   }
72
73    /** Accept the visitor. **/
74    public Object JavaDoc jjtAccept(TypeExpressionParserVisitor visitor, Object JavaDoc data)
75    {
76       return visitor.visit(this, data);
77    }
78
79   /** Accept the visitor. **/
80   public Object JavaDoc childrenAccept(PointcutExpressionParserVisitor visitor, Object JavaDoc data) {
81     if (children != null) {
82       for (int i = 0; i < children.length; ++i) {
83         children[i].jjtAccept(visitor, data);
84       }
85     }
86     return data;
87   }
88
89    /** Accept the visitor. **/
90    public Object JavaDoc childrenAccept(TypeExpressionParserVisitor visitor, Object JavaDoc data) {
91      if (children != null) {
92        for (int i = 0; i < children.length; ++i) {
93          children[i].jjtAccept(visitor, data);
94        }
95      }
96      return data;
97    }
98
99   /* You can override these two methods in subclasses of SimpleNode to
100      customize the way the node appears when the tree is dumped. If
101      your output uses more than one line you should override
102      toString(String), otherwise overriding toString() is probably all
103      you need to do. */

104
105   public String JavaDoc toString() { return PointcutExpressionParserTreeConstants.jjtNodeName[id]; }
106   public String JavaDoc toString(String JavaDoc prefix) { return prefix + toString(); }
107
108   /* Override this method if you want to customize how the node dumps
109      out its children. */

110
111   public void dump(String JavaDoc prefix) {
112     System.out.println(toString(prefix));
113     if (children != null) {
114       for (int i = 0; i < children.length; ++i) {
115     SimpleNode n = (SimpleNode)children[i];
116     if (n != null) {
117       n.dump(prefix + " ");
118     }
119       }
120     }
121   }
122 }
123
124
Popular Tags