Class Foreach.NullHolderContext
- java.lang.Object
-
- org.apache.velocity.context.ChainedInternalContextAdapter
-
- org.apache.velocity.runtime.directive.Foreach.NullHolderContext
-
- All Implemented Interfaces:
Context,InternalContextAdapter,InternalEventContext,InternalHousekeepingContext,InternalWrapperContext
- Enclosing class:
- Foreach
protected static class Foreach.NullHolderContext extends ChainedInternalContextAdapter
A special context to use when the foreach iterator returns a null. This is required since the standard context may not support nulls. All puts and gets are passed through, except for the foreach iterator key.- Since:
- 1.5
-
-
Field Summary
Fields Modifier and Type Field Description private booleanactiveprivate java.lang.StringloopVariableKey-
Fields inherited from class org.apache.velocity.context.ChainedInternalContextAdapter
innerContext
-
-
Constructor Summary
Constructors Modifier Constructor Description privateNullHolderContext(java.lang.String key, InternalContextAdapter context)Create the context as a wrapper to be used within the foreach
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectget(java.lang.String key)Get an object from the context, or null if the key is equal to the loop variablejava.lang.ObjectlocalPut(java.lang.String key, java.lang.Object value)Allows callers to explicitly put objects in the local context.java.lang.Objectput(java.lang.String key, java.lang.Object value)Put method also stores values in parent contextjava.lang.Objectremove(java.lang.Object key)Remove an object from the context-
Methods inherited from class org.apache.velocity.context.ChainedInternalContextAdapter
attachEventCartridge, containsKey, getBaseContext, getCurrentMacroCallDepth, getCurrentMacroName, getCurrentResource, getCurrentTemplateName, getEventCartridge, getInternalUserContext, getKeys, getMacroLibraries, getMacroNameStack, getTemplateNameStack, icacheGet, icachePut, popCurrentMacroName, popCurrentTemplateName, pushCurrentMacroName, pushCurrentTemplateName, setCurrentResource, setMacroLibraries
-
-
-
-
Constructor Detail
-
NullHolderContext
private NullHolderContext(java.lang.String key, InternalContextAdapter context)Create the context as a wrapper to be used within the foreach- Parameters:
key- the reference used in the foreachcontext- the parent context
-
-
Method Detail
-
get
public java.lang.Object get(java.lang.String key) throws MethodInvocationExceptionGet an object from the context, or null if the key is equal to the loop variable- Specified by:
getin interfaceContext- Overrides:
getin classChainedInternalContextAdapter- Parameters:
key- name of item to get- Returns:
- stored object or null
- Throws:
MethodInvocationException- passes on potential exception from reference method call- See Also:
Context.get(java.lang.String)
-
put
public java.lang.Object put(java.lang.String key, java.lang.Object value)Description copied from class:ChainedInternalContextAdapterPut method also stores values in parent context- Specified by:
putin interfaceContext- Overrides:
putin classChainedInternalContextAdapter- Parameters:
key- name of item to setvalue- object to set to key- Returns:
- old stored object
- See Also:
Context.put(java.lang.String key, java.lang.Object value)
-
localPut
public java.lang.Object localPut(java.lang.String key, java.lang.Object value)Allows callers to explicitly put objects in the local context. Objects added to the context through this method always end up in the top-level context of possible wrapped contexts.- 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(String, Object)
-
remove
public java.lang.Object remove(java.lang.Object key)
Remove an object 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 key)
-
-