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