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
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
FieldsFields inherited from class org.apache.velocity.context.ChainedInternalContextAdapter
innerContext
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
NullHolderContext
(String key, InternalContextAdapter context) Create the context as a wrapper to be used within the foreach -
Method Summary
Modifier and TypeMethodDescriptionGet an object from the context, or null if the key is equal to the loop variableAllows callers to explicitly put objects in the local context.Put method also stores values in parent contextRemove an object from the contextMethods 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
-
Field Details
-
loopVariableKey
-
active
private boolean active
-
-
Constructor Details
-
NullHolderContext
Create the context as a wrapper to be used within the foreach- Parameters:
key
- the reference used in the foreachcontext
- the parent context
-
-
Method Details
-
get
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:
-
put
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:
-
localPut
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:
-
remove
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:
-