org.apache.velocity.runtime.directive

Class VelocimacroProxy

Implemented Interfaces:
Cloneable, DirectiveConstants

public class VelocimacroProxy
extends Directive

VelocimacroProxy.java a proxy Directive-derived object to fit with the current directive system
Version:
$Id: VelocimacroProxy.java,v 1.27.4.1 2004/03/03 23:22:56 geirm Exp $
Author:
Geir Magnusson Jr.

Field Summary

private String[]
argArray
private int[]
callingArgTypes
private String[]
callingArgs
private boolean
init
private String
macroBody
private String
macroName
private String
namespace
private SimpleNode
nodeTree
private int
numMacroArgs
private HashMap
proxyArgHash

Fields inherited from class org.apache.velocity.runtime.directive.Directive

column, line, rsvc

Fields inherited from interface org.apache.velocity.runtime.directive.DirectiveConstants

BLOCK, LINE

Method Summary

private String[]
getArgArray(Node node)
gets the args to the VM from the instance-use AST
String
getName()
Return name of this Velocimacro.
int
getNumArgs()
returns the number of ars needed for this VM
int
getType()
Velocimacros are always LINE type directives.
void
init(RuntimeServices rs, InternalContextAdapter context, Node node)
The major meat of VelocimacroProxy, init() checks the # of arguments, patches the macro body, renders the macro into an AST, and then inits the AST, so it is ready for quick rendering.
private void
parseTree(String[] callArgs)
parses the macro.
boolean
render(InternalContextAdapter context, Writer writer, Node node)
Renders the macro using the context
void
setArgArray(String[] arr)
sets the array of arguments specified in the macro definition
void
setMacrobody(String mb)
Sets the orignal macro body.
void
setName(String name)
sets the directive name of this VM
void
setNamespace(String ns)
void
setNodeTree(SimpleNode tree)
boolean
setupMacro(String[] callArgs, int[] callArgTypes)
basic VM setup.
private void
setupProxyArgs(String[] callArgs, int[] callArgTypes)

Methods inherited from class org.apache.velocity.runtime.directive.Directive

getColumn, getLine, getName, getType, init, render, setLocation

Field Details

argArray

private String[] argArray

callingArgTypes

private int[] callingArgTypes

callingArgs

private String[] callingArgs

init

private boolean init

macroBody

private String macroBody

macroName

private String macroName

namespace

private String namespace

nodeTree

private SimpleNode nodeTree

numMacroArgs

private int numMacroArgs

proxyArgHash

private HashMap proxyArgHash

Method Details

getArgArray

private String[] getArgArray(Node node)
gets the args to the VM from the instance-use AST

getName

public String getName()
Return name of this Velocimacro.
Overrides:
getName in interface Directive

getNumArgs

public int getNumArgs()
returns the number of ars needed for this VM

getType

public int getType()
Velocimacros are always LINE type directives.
Overrides:
getType in interface Directive

init

public void init(RuntimeServices rs,
                 InternalContextAdapter context,
                 Node node)
            throws Exception
The major meat of VelocimacroProxy, init() checks the # of arguments, patches the macro body, renders the macro into an AST, and then inits the AST, so it is ready for quick rendering. Note that this is only AST dependant stuff. Not context.
Overrides:
init in interface Directive

parseTree

private void parseTree(String[] callArgs)
parses the macro. We need to do this here, at init time, or else the local-scope template feature is hard to get to work :)

render

public boolean render(InternalContextAdapter context,
                      Writer writer,
                      Node node)
            throws IOException,
                   MethodInvocationException
Renders the macro using the context
Overrides:
render in interface Directive

setArgArray

public void setArgArray(String[] arr)
sets the array of arguments specified in the macro definition

setMacrobody

public void setMacrobody(String mb)
Sets the orignal macro body. This is simply the cat of the macroArray, but the Macro object creates this once during parsing, and everyone shares it. Note : it must not be modified.

setName

public void setName(String name)
sets the directive name of this VM

setNamespace

public void setNamespace(String ns)

setNodeTree

public void setNodeTree(SimpleNode tree)

setupMacro

public boolean setupMacro(String[] callArgs,
                          int[] callArgTypes)
basic VM setup. Sets up the proxy args for this use, and parses the tree

setupProxyArgs

private void setupProxyArgs(String[] callArgs,
                            int[] callArgTypes)

Copyright B) 2002 Apache Software Foundation. All Rights Reserved.