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