View Javadoc

1   package org.apache.velocity.runtime.visitor;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.    
20   */
21  
22  import java.io.Writer;
23  
24  import org.apache.velocity.context.InternalContextAdapter;
25  import org.apache.velocity.runtime.parser.node.ASTAddNode;
26  import org.apache.velocity.runtime.parser.node.ASTAndNode;
27  import org.apache.velocity.runtime.parser.node.ASTAssignment;
28  import org.apache.velocity.runtime.parser.node.ASTBlock;
29  import org.apache.velocity.runtime.parser.node.ASTComment;
30  import org.apache.velocity.runtime.parser.node.ASTDirective;
31  import org.apache.velocity.runtime.parser.node.ASTDivNode;
32  import org.apache.velocity.runtime.parser.node.ASTEQNode;
33  import org.apache.velocity.runtime.parser.node.ASTElseIfStatement;
34  import org.apache.velocity.runtime.parser.node.ASTElseStatement;
35  import org.apache.velocity.runtime.parser.node.ASTEscape;
36  import org.apache.velocity.runtime.parser.node.ASTEscapedDirective;
37  import org.apache.velocity.runtime.parser.node.ASTExpression;
38  import org.apache.velocity.runtime.parser.node.ASTFalse;
39  import org.apache.velocity.runtime.parser.node.ASTFloatingPointLiteral;
40  import org.apache.velocity.runtime.parser.node.ASTGENode;
41  import org.apache.velocity.runtime.parser.node.ASTGTNode;
42  import org.apache.velocity.runtime.parser.node.ASTIdentifier;
43  import org.apache.velocity.runtime.parser.node.ASTIfStatement;
44  import org.apache.velocity.runtime.parser.node.ASTIntegerLiteral;
45  import org.apache.velocity.runtime.parser.node.ASTIntegerRange;
46  import org.apache.velocity.runtime.parser.node.ASTLENode;
47  import org.apache.velocity.runtime.parser.node.ASTLTNode;
48  import org.apache.velocity.runtime.parser.node.ASTMap;
49  import org.apache.velocity.runtime.parser.node.ASTMethod;
50  import org.apache.velocity.runtime.parser.node.ASTModNode;
51  import org.apache.velocity.runtime.parser.node.ASTMulNode;
52  import org.apache.velocity.runtime.parser.node.ASTNENode;
53  import org.apache.velocity.runtime.parser.node.ASTNotNode;
54  import org.apache.velocity.runtime.parser.node.ASTObjectArray;
55  import org.apache.velocity.runtime.parser.node.ASTOrNode;
56  import org.apache.velocity.runtime.parser.node.ASTReference;
57  import org.apache.velocity.runtime.parser.node.ASTSetDirective;
58  import org.apache.velocity.runtime.parser.node.ASTStop;
59  import org.apache.velocity.runtime.parser.node.ASTStringLiteral;
60  import org.apache.velocity.runtime.parser.node.ASTSubtractNode;
61  import org.apache.velocity.runtime.parser.node.ASTText;
62  import org.apache.velocity.runtime.parser.node.ASTTrue;
63  import org.apache.velocity.runtime.parser.node.ASTWord;
64  import org.apache.velocity.runtime.parser.node.ASTprocess;
65  import org.apache.velocity.runtime.parser.node.ParserVisitor;
66  import org.apache.velocity.runtime.parser.node.SimpleNode;
67  
68  /**
69   * This is the base class for all visitors.
70   * For each AST node, this class will provide
71   * a bare-bones method for traversal.
72   *
73   * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
74   * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
75   * @version $Id: BaseVisitor.java 517553 2007-03-13 06:09:58Z wglass $
76   */
77  public abstract class BaseVisitor implements ParserVisitor
78  {
79      /** Context used during traversal */
80      protected InternalContextAdapter context;
81  
82      /** Writer used as the output sink */
83      protected Writer writer;
84  
85      /**
86       * @param writer
87       */
88      public void setWriter( Writer writer )
89      {
90          this.writer = writer;
91      }
92  
93      /**
94       * @param context
95       */
96      public void setContext( InternalContextAdapter context)
97      {
98          this.context = context;
99      }
100 
101     /**
102      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.SimpleNode, java.lang.Object)
103      */
104     public Object visit(SimpleNode node, Object data)
105     {
106         data = node.childrenAccept(this, data);
107         return data;
108     }
109 
110     /**
111      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTprocess, java.lang.Object)
112      */
113     public Object visit(ASTprocess node, Object data)
114     {
115         data = node.childrenAccept(this, data);
116         return data;
117     }
118 
119     /**
120      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTExpression, java.lang.Object)
121      */
122     public Object visit(ASTExpression node, Object data)
123     {
124         data = node.childrenAccept(this, data);
125         return data;
126     }
127 
128     /**
129      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTAssignment, java.lang.Object)
130      */
131     public Object visit(ASTAssignment node, Object data)
132     {
133         data = node.childrenAccept(this, data);
134         return data;
135     }
136 
137     /**
138      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTOrNode, java.lang.Object)
139      */
140     public Object visit(ASTOrNode node, Object data)
141     {
142         data = node.childrenAccept(this, data);
143         return data;
144     }
145 
146     /**
147      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTAndNode, java.lang.Object)
148      */
149     public Object visit(ASTAndNode node, Object data)
150     {
151         data = node.childrenAccept(this, data);
152         return data;
153     }
154 
155     /**
156      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTEQNode, java.lang.Object)
157      */
158     public Object visit(ASTEQNode node, Object data)
159     {
160         data = node.childrenAccept(this, data);
161         return data;
162     }
163 
164     /**
165      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTNENode, java.lang.Object)
166      */
167     public Object visit(ASTNENode node, Object data)
168     {
169         data = node.childrenAccept(this, data);
170         return data;
171     }
172 
173     /**
174      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTLTNode, java.lang.Object)
175      */
176     public Object visit(ASTLTNode node, Object data)
177     {
178         data = node.childrenAccept(this, data);
179         return data;
180     }
181 
182     /**
183      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTGTNode, java.lang.Object)
184      */
185     public Object visit(ASTGTNode node, Object data)
186     {
187         data = node.childrenAccept(this, data);
188         return data;
189     }
190 
191     /**
192      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTLENode, java.lang.Object)
193      */
194     public Object visit(ASTLENode node, Object data)
195     {
196         data = node.childrenAccept(this, data);
197         return data;
198     }
199 
200     /**
201      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTGENode, java.lang.Object)
202      */
203     public Object visit(ASTGENode node, Object data)
204     {
205         data = node.childrenAccept(this, data);
206         return data;
207     }
208 
209     /**
210      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTAddNode, java.lang.Object)
211      */
212     public Object visit(ASTAddNode node, Object data)
213     {
214         data = node.childrenAccept(this, data);
215         return data;
216     }
217 
218     /**
219      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTSubtractNode, java.lang.Object)
220      */
221     public Object visit(ASTSubtractNode node, Object data)
222     {
223         data = node.childrenAccept(this, data);
224         return data;
225     }
226 
227     /**
228      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTMulNode, java.lang.Object)
229      */
230     public Object visit(ASTMulNode node, Object data)
231     {
232         data = node.childrenAccept(this, data);
233         return data;
234     }
235 
236     /**
237      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTDivNode, java.lang.Object)
238      */
239     public Object visit(ASTDivNode node, Object data)
240     {
241         data = node.childrenAccept(this, data);
242         return data;
243     }
244 
245     /**
246      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTModNode, java.lang.Object)
247      */
248     public Object visit(ASTModNode node, Object data)
249     {
250         data = node.childrenAccept(this, data);
251         return data;
252     }
253 
254     /**
255      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTNotNode, java.lang.Object)
256      */
257     public Object visit(ASTNotNode node, Object data)
258     {
259         data = node.childrenAccept(this, data);
260         return data;
261     }
262 
263     /**
264      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIntegerLiteral, java.lang.Object)
265      */
266     public Object visit(ASTIntegerLiteral node, Object data)
267     {
268         data = node.childrenAccept(this, data);
269         return data;
270     }
271 
272     /**
273      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTFloatingPointLiteral, java.lang.Object)
274      */
275     public Object visit(ASTFloatingPointLiteral node, Object data)
276     {
277         data = node.childrenAccept(this, data);
278         return data;
279     }
280 
281     /**
282      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTStringLiteral, java.lang.Object)
283      */
284     public Object visit(ASTStringLiteral node, Object data)
285     {
286         data = node.childrenAccept(this, data);
287         return data;
288     }
289 
290     /**
291      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIdentifier, java.lang.Object)
292      */
293     public Object visit(ASTIdentifier node, Object data)
294     {
295         data = node.childrenAccept(this, data);
296         return data;
297     }
298 
299     /**
300      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTMethod, java.lang.Object)
301      */
302     public Object visit(ASTMethod node, Object data)
303     {
304         data = node.childrenAccept(this, data);
305         return data;
306     }
307 
308     /**
309      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTReference, java.lang.Object)
310      */
311     public Object visit(ASTReference node, Object data)
312     {
313         data = node.childrenAccept(this, data);
314         return data;
315     }
316 
317     /**
318      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTTrue, java.lang.Object)
319      */
320     public Object visit(ASTTrue node, Object data)
321     {
322         data = node.childrenAccept(this, data);
323         return data;
324     }
325 
326     /**
327      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTFalse, java.lang.Object)
328      */
329     public Object visit(ASTFalse node, Object data)
330     {
331         data = node.childrenAccept(this, data);
332         return data;
333     }
334 
335     /**
336      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTBlock, java.lang.Object)
337      */
338     public Object visit(ASTBlock node, Object data)
339     {
340         data = node.childrenAccept(this, data);
341         return data;
342     }
343 
344     /**
345      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTText, java.lang.Object)
346      */
347     public Object visit(ASTText node, Object data)
348     {
349         data = node.childrenAccept(this, data);
350         return data;
351     }
352 
353     /**
354      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIfStatement, java.lang.Object)
355      */
356     public Object visit(ASTIfStatement node, Object data)
357     {
358         data = node.childrenAccept(this, data);
359         return data;
360     }
361 
362     /**
363      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTElseStatement, java.lang.Object)
364      */
365     public Object visit(ASTElseStatement node, Object data)
366     {
367         data = node.childrenAccept(this, data);
368         return data;
369     }
370 
371     /**
372      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTElseIfStatement, java.lang.Object)
373      */
374     public Object visit(ASTElseIfStatement node, Object data)
375     {
376         data = node.childrenAccept(this, data);
377         return data;
378     }
379 
380     /**
381      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTComment, java.lang.Object)
382      */
383     public Object visit(ASTComment node, Object data)
384     {
385         data = node.childrenAccept(this, data);
386         return data;
387     }
388 
389     /**
390      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTObjectArray, java.lang.Object)
391      */
392     public Object visit(ASTObjectArray node, Object data)
393     {
394         data = node.childrenAccept(this, data);
395         return data;
396     }
397 
398     /**
399      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTWord, java.lang.Object)
400      */
401     public Object visit(ASTWord node, Object data)
402     {
403         data = node.childrenAccept(this, data);
404         return data;
405     }
406 
407     /**
408      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTSetDirective, java.lang.Object)
409      */
410     public Object visit(ASTSetDirective node, Object data)
411     {
412         data = node.childrenAccept(this, data);
413         return data;
414     }
415 
416     /**
417      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTDirective, java.lang.Object)
418      */
419     public Object visit(ASTDirective node, Object data)
420     {
421         data = node.childrenAccept(this, data);
422         return data;
423     }
424 
425     /**
426      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTEscapedDirective, java.lang.Object)
427      */
428     public Object visit(ASTEscapedDirective node, Object data)
429     {
430         data = node.childrenAccept(this, data);
431         return data;
432     }
433 
434     /**
435      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTEscape, java.lang.Object)
436      */
437     public Object visit(ASTEscape node, Object data)
438     {
439         data = node.childrenAccept(this, data);
440         return data;
441     }
442 
443     /**
444      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTMap, java.lang.Object)
445      */
446     public Object visit(ASTMap node, Object data)
447     {
448         data = node.childrenAccept(this, data);
449         return data;
450     }
451 
452     /**
453      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTIntegerRange, java.lang.Object)
454      */
455     public Object visit(ASTIntegerRange node, Object data)
456     {
457         data = node.childrenAccept(this, data);
458         return data;
459     }
460 
461     /**
462      * @see org.apache.velocity.runtime.parser.node.ParserVisitor#visit(org.apache.velocity.runtime.parser.node.ASTStop, java.lang.Object)
463      */
464     public Object visit(ASTStop node, Object data)
465     {
466         data = node.childrenAccept(this, data);
467         return data;
468     }
469 }