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 boolean
active
private java.lang.String
loopVariableKey
-
Fields inherited from class org.apache.velocity.context.ChainedInternalContextAdapter
innerContext
-
-
Constructor Summary
Constructors Modifier Constructor Description private
NullHolderContext(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.Object
get(java.lang.String key)
Get an object from the context, or null if the key is equal to the loop variablejava.lang.Object
localPut(java.lang.String key, java.lang.Object value)
Allows callers to explicitly put objects in the local context.java.lang.Object
put(java.lang.String key, java.lang.Object value)
Put method also stores values in parent contextjava.lang.Object
remove(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 MethodInvocationException
Get an object from the context, or null if the key is equal to the loop variable- Specified by:
get
in interfaceContext
- Overrides:
get
in 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:ChainedInternalContextAdapter
Put method also stores values in parent context- Specified by:
put
in interfaceContext
- Overrides:
put
in 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:
localPut
in interfaceInternalWrapperContext
- Overrides:
localPut
in 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:
remove
in interfaceContext
- Overrides:
remove
in classChainedInternalContextAdapter
- Parameters:
key
- The name of the value to remove.- Returns:
- The value that the key was mapped to, or
null
if unmapped. - See Also:
Context.remove(java.lang.Object key)
-
-