KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > filter > etcl > AbstractTCLNode


1 package org.jacorb.notification.filter.etcl;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2004 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */

23
24 import java.lang.reflect.Field JavaDoc;
25
26 import org.jacorb.notification.filter.EvaluationContext;
27 import org.jacorb.notification.filter.EvaluationException;
28 import org.jacorb.notification.filter.EvaluationResult;
29
30 import antlr.BaseAST;
31 import antlr.Token;
32 import antlr.collections.AST;
33
34 /**
35  * Base Class for TCLTree Nodes.
36  *
37  * @author Alphonse Bendt
38  * @version $Id: AbstractTCLNode.java,v 1.7 2005/02/14 00:07:08 alphonse.bendt Exp $
39  */

40
41 public abstract class AbstractTCLNode extends BaseAST implements TCLParserTokenTypes
42 {
43     private int astNodeType_;
44
45     // private TCKind tcKind_;
46

47     private String JavaDoc name_;
48
49     ////////////////////////////////////////////////////////////
50
// Constructor
51

52     public AbstractTCLNode(Token tok)
53     {
54         super();
55
56         setType(tok.getType());
57     }
58
59     protected AbstractTCLNode()
60     {
61         super();
62     }
63
64     //////////////////////////////////////////////////
65

66     /**
67      * Evaluate this Node.
68      *
69      * @param context
70      * an <code>EvaluationContext</code> value contains all context information
71      * necessary for the evaluation
72      * @return an <code>EvaluationResult</code> value
73      *
74      * @exception EvaluationException
75      * occurs if e.g. an expression contains a reference to a non-existent struct
76      * member or if it is tried to add a string and a number
77      */

78     public EvaluationResult evaluate(EvaluationContext context) throws EvaluationException
79     {
80         throw new UnsupportedOperationException JavaDoc();
81     }
82
83     /**
84      * accept a visitor for traversal Inorder
85      *
86      * @param visitor
87      */

88     public abstract void acceptInOrder(AbstractTCLVisitor visitor) throws VisitorException;
89
90     /**
91      * accept a visitor for traversal in Preorder.
92      *
93      * the root node is visited before the left and the right subtrees are visited.
94      *
95      * @param visitor
96      */

97     public abstract void acceptPreOrder(AbstractTCLVisitor visitor) throws VisitorException;
98
99     /**
100      * accept a visitor for traversal in Postorder.
101      *
102      * the right and left subtrees are visited before the root node is visited.
103      *
104      * @param visitor
105      */

106     public abstract void acceptPostOrder(AbstractTCLVisitor visitor) throws VisitorException;
107
108     ////////////////////////////////////////////////////////////
109

110     public final String JavaDoc getName()
111     {
112         return name_;
113     }
114
115     void setName(String JavaDoc name)
116     {
117         name_ = name;
118     }
119
120     /**
121      * Check wether this node has a Sibling.
122      *
123      * @return true, if this node has a Sibling
124      */

125     public boolean hasNextSibling()
126     {
127         return (getNextSibling() != null);
128     }
129
130     public void printToStringBuffer(StringBuffer JavaDoc buffer)
131     {
132         if (getFirstChild() != null)
133         {
134             buffer.append(" (");
135         }
136
137         buffer.append(" ");
138         buffer.append(toString());
139
140         if (getFirstChild() != null)
141         {
142             buffer.append(((AbstractTCLNode) getFirstChild()).toStringList());
143         }
144
145         if (getFirstChild() != null)
146         {
147             buffer.append(" )");
148         }
149     }
150
151     /**
152      * create a visualization of this node and all its children.
153      *
154      * @return a String representation of this Node and all its children
155      */

156     public String JavaDoc toStringTree()
157     {
158         StringBuffer JavaDoc _buffer = new StringBuffer JavaDoc();
159
160         printToStringBuffer(_buffer);
161
162         return _buffer.toString();
163     }
164
165     /**
166      * Access the left child. This method returns null if this node has no left child
167      *
168      * @return the left Child or null.
169      */

170     public AbstractTCLNode left()
171     {
172         return (AbstractTCLNode) getFirstChild();
173     }
174
175     /**
176      * Access the right child. This method returns null if this node has no right child
177      *
178      * @return the right Child or null.
179      */

180     public AbstractTCLNode right()
181     {
182         return (AbstractTCLNode) getFirstChild().getNextSibling();
183     }
184
185     ////////////////////////////////////////////////////////////
186

187     public boolean isStatic()
188     {
189         return false;
190     }
191
192     public boolean isNumber()
193     {
194         return false;
195     }
196
197     public boolean isString()
198     {
199         return false;
200     }
201
202     public boolean isBoolean()
203     {
204         return false;
205     }
206
207     /**
208      * Get the AST Token Type for this node.
209      *
210      * @return the AST Token Type value
211      * @see TCLParserTokenTypes
212      */

213     public int getType()
214     {
215         return astNodeType_;
216     }
217
218     /**
219      * Set AST Token Type for this node.
220      *
221      * @param type
222      * must be a valid TCLTokenType.
223      * @see TCLParserTokenTypes
224      */

225     public void setType(int type)
226     {
227         astNodeType_ = type;
228     }
229
230     /**
231      * converts an int tree token type to a name. Does this by reflecting on
232      * nsdidl.IDLTreeTokenTypes, and is dependent on how ANTLR 2.00 outputs that class. this snippet
233      * was taken from http://www.codetransform.com/
234      */

235     public static String JavaDoc getNameForType(int t)
236     {
237         try
238         {
239             Field JavaDoc[] _fields = TCLParserTokenTypes.class.getDeclaredFields();
240
241             if (t - 6 < _fields.length)
242             {
243                 return _fields[t - 6].getName();
244             }
245         } catch (Exception JavaDoc e)
246         {
247             // ignore
248
}
249
250         return "unknown type: " + t;
251     }
252
253     /**
254      * satisfy abstract method from BaseAST. Not used.
255      */

256     public void initialize(int t, String JavaDoc txt)
257     {
258         // no op
259
}
260
261     /**
262      * satisfy abstract method from BaseAST. Not used.
263      */

264     public void initialize(AST t)
265     {
266         // no op
267
}
268
269     /**
270      * satisfy abstract method from BaseAST. Not used.
271      */

272     public void initialize(Token tok)
273     {
274         // no op
275
}
276 }
Popular Tags