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 517553 2007-03-13 06:09:58Z wglass $
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      public void jjtClose();
49  
50      /**
51       * This pair of methods are used to inform the node of its
52       * parent.
53       * @param n
54       * */
55      public void jjtSetParent(Node n);
56  
57      /**
58       * @return The node parent.
59       */
60      public Node jjtGetParent();
61  
62      /**
63       * This method tells the node to add its argument to the node's
64       * list of children.
65       * @param n
66       * @param i
67       */
68      public void jjtAddChild(Node n, int i);
69  
70      /**
71       * This method returns a child node.  The children are numbered
72       * from zero, left to right.
73       * @param i
74       * @return A child node.
75       */
76      public Node jjtGetChild(int i);
77  
78      /**
79       * Return the number of children the node has.
80       * @return The number of children of this node.
81       */
82      public int jjtGetNumChildren();
83  
84      /**
85       * @param visitor
86       * @param data
87       * @return The Node execution result object.
88       */
89      public Object jjtAccept(ParserVisitor visitor, Object data);
90  
91      /*
92       * ========================================================================
93       *
94       * The following methods are not generated automatically be the Parser but
95       * added manually to be used by Velocity.
96       *
97       * ========================================================================
98       */
99  
100     /**
101      * @see #jjtAccept(ParserVisitor, Object)
102      * @param visitor
103      * @param data
104      * @return The node execution result.
105      */
106     public Object childrenAccept(ParserVisitor visitor, Object data);
107 
108     /**
109      * @return The first token.
110      */
111     public Token getFirstToken();
112     /**
113      * @return The last token.
114      */
115     public Token getLastToken();
116     /**
117      * @return The NodeType.
118      */
119     public int getType();
120 
121     /**
122      * @param context
123      * @param data
124      * @return The init result.
125      * @throws TemplateInitException 
126      */
127     public Object init( InternalContextAdapter context, Object data) throws TemplateInitException;
128 
129     /**
130      * @param context
131      * @return The evaluation result.
132      * @throws MethodInvocationException
133      */
134     public boolean evaluate( InternalContextAdapter context)
135         throws MethodInvocationException;
136 
137     /**
138      * @param context
139      * @return The node value.
140      * @throws MethodInvocationException
141      */
142     public Object value( InternalContextAdapter context)
143         throws MethodInvocationException;
144 
145     /**
146      * @param context
147      * @param writer
148      * @return True if the node rendered successfully.
149      * @throws IOException
150      * @throws MethodInvocationException
151      * @throws ParseErrorException
152      * @throws ResourceNotFoundException
153      */
154     public boolean render( InternalContextAdapter context, Writer writer)
155         throws IOException,MethodInvocationException, ParseErrorException, ResourceNotFoundException;
156 
157     /**
158      * @param o
159      * @param context
160      * @return The execution result.
161      * @throws MethodInvocationException
162      */
163     public Object execute(Object o, InternalContextAdapter context)
164       throws MethodInvocationException;
165 
166     /**
167      * @param info
168      */
169     public void setInfo(int info);
170 
171     /**
172      * @return The current node info.
173      */
174     public int getInfo();
175 
176     /**
177      * @return A literal.
178      */
179     public String literal();
180 
181     /**
182      * Mark the node as invalid.
183      */
184     public void setInvalid();
185 
186     /**
187      * @return True if the node is invalid.
188      */
189     public boolean isInvalid();
190 
191     /**
192      * @return The current line position.
193      */
194     public int getLine();
195 
196     /**
197      * @return The current column position.
198      */
199     public int getColumn();
200 }