View Javadoc

1   package org.apache.velocity.runtime.parser.node;
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.IOException;
23  import java.io.Writer;
24  
25  import org.apache.velocity.context.InternalContextAdapter;
26  import org.apache.velocity.exception.MethodInvocationException;
27  import org.apache.velocity.exception.ParseErrorException;
28  import org.apache.velocity.exception.ResourceNotFoundException;
29  import org.apache.velocity.exception.TemplateInitException;
30  import org.apache.velocity.runtime.parser.Token;
31  
32  /**
33   *  This file describes the interface between the Velocity code
34   *  and the JavaCC generated code.
35   *
36   * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
37   * @version $Id: Node.java 720228 2008-11-24 16:58:33Z nbubna $
38   */
39  
40  public interface Node
41  {
42      /** This method is called after the node has been made the current
43       * node.  It indicates that child nodes can now be added to it. */
44      public void jjtOpen();
45  
46      /** This method is called after all the child nodes have been
47        added.
48       */
49      public void jjtClose();
50  
51      /**
52       * This pair of methods are used to inform the node of its
53       * parent.
54       * @param n
55       *
56       */
57      public void jjtSetParent(Node n);
58  
59      /**
60       * @return The node parent.
61       */
62      public Node jjtGetParent();
63  
64      /**
65       * This method tells the node to add its argument to the node's
66       * list of children.
67       * @param n
68       * @param i
69       */
70      public void jjtAddChild(Node n, int i);
71  
72      /**
73       * This method returns a child node.  The children are numbered
74       * from zero, left to right.
75       * @param i
76       * @return A child node.
77       */
78      public Node jjtGetChild(int i);
79  
80      /**
81       * Return the number of children the node has.
82       * @return The number of children of this node.
83       */
84      public int jjtGetNumChildren();
85  
86      /**
87       * @param visitor
88       * @param data
89       * @return The Node execution result object.
90       */
91      public Object jjtAccept(ParserVisitor visitor, Object data);
92  
93      /*
94       * ========================================================================
95       *
96       * The following methods are not generated automatically be the Parser but
97       * added manually to be used by Velocity.
98       *
99       * ========================================================================
100      */
101 
102     /**
103      * @see #jjtAccept(ParserVisitor, Object)
104      * @param visitor
105      * @param data
106      * @return The node execution result.
107      */
108     public Object childrenAccept(ParserVisitor visitor, Object data);
109 
110     /**
111      * @return The first token.
112      */
113     public Token getFirstToken();
114     /**
115      * @return The last token.
116      */
117     public Token getLastToken();
118     /**
119      * @return The NodeType.
120      */
121     public int getType();
122 
123     /**
124      * @param context
125      * @param data
126      * @return The init result.
127      * @throws TemplateInitException
128      */
129     public Object init( InternalContextAdapter context, Object data) throws TemplateInitException;
130 
131     /**
132      * @param context
133      * @return The evaluation result.
134      * @throws MethodInvocationException
135      */
136     public boolean evaluate( InternalContextAdapter context)
137         throws MethodInvocationException;
138 
139     /**
140      * @param context
141      * @return The node value.
142      * @throws MethodInvocationException
143      */
144     public Object value( InternalContextAdapter context)
145         throws MethodInvocationException;
146 
147     /**
148      * @param context
149      * @param writer
150      * @return True if the node rendered successfully.
151      * @throws IOException
152      * @throws MethodInvocationException
153      * @throws ParseErrorException
154      * @throws ResourceNotFoundException
155      */
156     public boolean render( InternalContextAdapter context, Writer writer)
157         throws IOException,MethodInvocationException, ParseErrorException, ResourceNotFoundException;
158 
159     /**
160      * @param o
161      * @param context
162      * @return The execution result.
163      * @throws MethodInvocationException
164      */
165     public Object execute(Object o, InternalContextAdapter context)
166       throws MethodInvocationException;
167 
168     /**
169      * @param info
170      */
171     public void setInfo(int info);
172 
173     /**
174      * @return The current node info.
175      */
176     public int getInfo();
177 
178     /**
179      * @return A literal.
180      */
181     public String literal();
182 
183     /**
184      * Mark the node as invalid.
185      */
186     public void setInvalid();
187 
188     /**
189      * @return True if the node is invalid.
190      */
191     public boolean isInvalid();
192 
193     /**
194      * @return The current line position.
195      */
196     public int getLine();
197 
198     /**
199      * @return The current column position.
200      */
201     public int getColumn();
202     
203     /**
204      * @return the file name of the template
205      */
206     public String getTemplateName();
207 }