KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > velocity > runtime > visitor > VMReferenceMungeVisitor


1 package org.apache.velocity.runtime.visitor;
2
3 /*
4  * Copyright 2001,2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.util.Map JavaDoc;
20
21 import org.apache.velocity.runtime.parser.node.ASTReference;
22
23 /**
24  * This class is a visitor used by the VM proxy to change the
25  * literal representation of a reference in a VM. The reason is
26  * to preserve the 'render literal if null' behavior w/o making
27  * the VMProxy stuff more complicated than it is already.
28  *
29  * @author <a HREF="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
30  * @version $Id: VMReferenceMungeVisitor.java,v 1.2.4.1 2004/03/03 23:23:03 geirm Exp $
31  */

32 public class VMReferenceMungeVisitor extends BaseVisitor
33 {
34     /**
35      * Map containing VM arg to instance-use reference
36      * Passed in with CTOR
37      */

38     private Map JavaDoc argmap = null;
39
40     /**
41      * CTOR - takes a map of args to reference
42      */

43     public VMReferenceMungeVisitor( Map JavaDoc map )
44     {
45         argmap = map;
46     }
47
48     /**
49      * Visitor method - if the literal is right, will
50      * set the literal in the ASTReference node
51      *
52      * @param node ASTReference to work on
53      * @param data Object to pass down from caller
54      */

55     public Object JavaDoc visit( ASTReference node, Object JavaDoc data)
56     {
57         /*
58          * see if there is an override value for this
59          * reference
60          */

61         String JavaDoc override = (String JavaDoc) argmap.get( node.literal().substring(1) );
62
63         /*
64          * if so, set in the node
65          */

66         if( override != null)
67         {
68             node.setLiteral( override );
69         }
70
71         /*
72          * feed the children...
73          */

74         data = node.childrenAccept(this, data);
75
76         return data;
77     }
78 }
79
80
Popular Tags