Package org.apache.velocity.context
Class ProxyVMContext
- java.lang.Object
-
- org.apache.velocity.context.ChainedInternalContextAdapter
-
- org.apache.velocity.context.ProxyVMContext
-
- All Implemented Interfaces:
Context,InternalContextAdapter,InternalEventContext,InternalHousekeepingContext,InternalWrapperContext
public class ProxyVMContext extends ChainedInternalContextAdapter
Context for Velocity macro arguments. This special context combines ideas of earlier VMContext and VMProxyArgs by implementing routing functionality internally. This significantly reduces memory allocation upon macro invocations. Since the macro AST is now shared and RuntimeMacro directive is used, the earlier implementation of precalculating VMProxyArgs would not work. See Issue 607 for more info on this class.- Since:
- 1.6
- Version:
- $Id$
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.Maplocalcontextcontainer for any local or constant macro arguments.private booleanlocalContextScopesupport for local context scope feature, where all references are localprivate RuntimeServicesrsvcneeded for writing log entries.(package private) java.util.Mapvmproxyhashcontainer for our macro AST node arguments.-
Fields inherited from class org.apache.velocity.context.ChainedInternalContextAdapter
innerContext
-
-
Constructor Summary
Constructors Constructor Description ProxyVMContext(InternalContextAdapter inner, RuntimeServices rsvc, boolean localContextScope)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddVMProxyArg(InternalContextAdapter context, java.lang.String macroArgumentName, java.lang.String literalMacroArgumentName, Node argumentValue)Used to put Velocity macro arguments into this context.voidaddVMProxyArg(InternalContextAdapter context, java.lang.String macroArgumentName, java.lang.String literalMacroArgumentName, Renderable argumentValue)Used to put Velocity macro bodyContext arguments into this context.booleancontainsKey(java.lang.Object key)Indicates whether the specified key is in the context.java.lang.Objectget(java.lang.String key)Implementation of the Context.get() method.java.lang.Object[]getKeys()Get all the keys for the values in the context.private booleanisConstant(Node node)AST nodes that are considered constants can be directly saved into the context.java.lang.ObjectlocalPut(java.lang.String key, java.lang.Object value)Allows callers to explicitly put objects in the local context, no matter what the velocimacro.context.local setting says.java.lang.Objectput(java.lang.String key, java.lang.Object value)Impl of the Context.put() method.protected java.lang.Objectput(java.lang.String key, java.lang.Object value, boolean forceLocal)Internal put method to select between local and global scope.java.lang.Objectremove(java.lang.Object key)Removes the value associated with the specified key from the context.-
Methods inherited from class org.apache.velocity.context.ChainedInternalContextAdapter
attachEventCartridge, getBaseContext, getCurrentMacroCallDepth, getCurrentMacroName, getCurrentResource, getCurrentTemplateName, getEventCartridge, getInternalUserContext, getMacroLibraries, getMacroNameStack, getTemplateNameStack, icacheGet, icachePut, popCurrentMacroName, popCurrentTemplateName, pushCurrentMacroName, pushCurrentTemplateName, setCurrentResource, setMacroLibraries
-
-
-
-
Field Detail
-
vmproxyhash
java.util.Map vmproxyhash
container for our macro AST node arguments. Size must be power of 2.
-
localcontext
java.util.Map localcontext
container for any local or constant macro arguments. Size must be power of 2.
-
localContextScope
private boolean localContextScope
support for local context scope feature, where all references are local
-
rsvc
private RuntimeServices rsvc
needed for writing log entries.
-
-
Constructor Detail
-
ProxyVMContext
public ProxyVMContext(InternalContextAdapter inner, RuntimeServices rsvc, boolean localContextScope)
- Parameters:
inner- Velocity context for processingrsvc- RuntimeServices provides logging referencelocalContextScope- if true, all references are set to be local
-
-
Method Detail
-
addVMProxyArg
public void addVMProxyArg(InternalContextAdapter context, java.lang.String macroArgumentName, java.lang.String literalMacroArgumentName, Node argumentValue) throws MethodInvocationException
Used to put Velocity macro arguments into this context.- Parameters:
context- rendering contextmacroArgumentName- name of the macro argument that we receivedliteralMacroArgumentName- ".literal.$"+macroArgumentNameargumentValue- actual value of the macro argument- Throws:
MethodInvocationException
-
addVMProxyArg
public void addVMProxyArg(InternalContextAdapter context, java.lang.String macroArgumentName, java.lang.String literalMacroArgumentName, Renderable argumentValue) throws MethodInvocationException
Used to put Velocity macro bodyContext arguments into this context.- Parameters:
context- rendering contextmacroArgumentName- name of the macro argument that we receivedliteralMacroArgumentName- ".literal.$"+macroArgumentNameargumentValue- actual value of the macro body- Throws:
MethodInvocationException
-
isConstant
private boolean isConstant(Node node)
AST nodes that are considered constants can be directly saved into the context. Dynamic values are stored in another argument hashmap.- Parameters:
node- macro argument as AST node- Returns:
- true if the node is a constant value
-
put
public java.lang.Object put(java.lang.String key, java.lang.Object value)Impl of the Context.put() method.- Specified by:
putin interfaceContext- Overrides:
putin classChainedInternalContextAdapter- Parameters:
key- name of item to setvalue- object to set to key- Returns:
- old stored object
-
localPut
public java.lang.Object localPut(java.lang.String key, java.lang.Object value)Allows callers to explicitly put objects in the local context, no matter what the velocimacro.context.local setting says. Needed e.g. for loop variables in foreach.- Specified by:
localPutin interfaceInternalWrapperContext- Overrides:
localPutin classChainedInternalContextAdapter- Parameters:
key- name of item to set.value- object to set to key.- Returns:
- old stored object
- See Also:
InternalWrapperContext.localPut(java.lang.String,java.lang.Object)
-
put
protected java.lang.Object put(java.lang.String key, java.lang.Object value, boolean forceLocal)Internal put method to select between local and global scope.- Parameters:
key- name of item to setvalue- object to set to keyforceLocal- True forces the object into the local scope.- Returns:
- old stored object
-
get
public java.lang.Object get(java.lang.String key)
Implementation of the Context.get() method. First checks localcontext, then arguments, then global context.- Specified by:
getin interfaceContext- Overrides:
getin classChainedInternalContextAdapter- Parameters:
key- name of item to get- Returns:
- stored object or null
-
containsKey
public boolean containsKey(java.lang.Object key)
Description copied from interface:ContextIndicates whether the specified key is in the context.- Specified by:
containsKeyin interfaceContext- Overrides:
containsKeyin classChainedInternalContextAdapter- Parameters:
key- The key to look for.- Returns:
- Whether the key is in the context.
- See Also:
Context.containsKey(java.lang.Object)
-
getKeys
public java.lang.Object[] getKeys()
Description copied from interface:ContextGet all the keys for the values in the context.- Specified by:
getKeysin interfaceContext- Overrides:
getKeysin classChainedInternalContextAdapter- Returns:
- All the keys for the values in the context.
- See Also:
Context.getKeys()
-
remove
public java.lang.Object remove(java.lang.Object key)
Description copied from interface:ContextRemoves the value associated with the specified key from the context.- Specified by:
removein interfaceContext- Overrides:
removein classChainedInternalContextAdapter- Parameters:
key- The name of the value to remove.- Returns:
- The value that the key was mapped to, or
nullif unmapped. - See Also:
Context.remove(java.lang.Object)
-
-