Package org.apache.velocity
Class VelocityContext
java.lang.Object
org.apache.velocity.context.InternalContextBase
org.apache.velocity.context.AbstractContext
org.apache.velocity.VelocityContext
- All Implemented Interfaces:
Serializable
,Cloneable
,Context
,InternalEventContext
,InternalHousekeepingContext
General purpose implementation of the application Context
interface for general application use. This class should
be used in place of the original Context class.
This implementation uses a HashMap (@see java.util.HashMap )
for data storage.
This context implementation cannot be shared between threads
without those threads synchronizing access between them, as
the HashMap is not synchronized, nor are some of the fundamentals
of AbstractContext. If you need to share a Context between
threads with simultaneous access for some reason, please create
your own and extend the interface Context
- Version:
- $Id$
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionStorage for key/value pairs.private static final long
Version Id for serializable -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance (with no inner context).VelocityContext
(Map<String, Object> context) Creates a new instance with the provided storage (and no inner context).VelocityContext
(Map<String, Object> context, Context innerContext) Initializes internal storage (never tonull
), and inner context.VelocityContext
(Context innerContext) Chaining constructor, used when you want to wrap a context in another. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Clones this context object.boolean
determines if there is a value for the given keyinternalGet
(String key) retrieves value for key from internal storageString[]
returns array of keysinternalPut
(String key, Object value) stores the value for key to internal storageinternalRemove
(String key) remove a key/value pair from the internal storageMethods inherited from class org.apache.velocity.context.AbstractContext
containsKey, get, getChainedContext, getKeys, put, remove
Methods inherited from class org.apache.velocity.context.InternalContextBase
attachEventCartridge, getCurrentMacroCallDepth, getCurrentMacroName, getCurrentResource, getCurrentTemplateName, getEventCartridge, getMacroLibraries, getMacroNameStack, getTemplateNameStack, icacheGet, icachePut, popCurrentMacroName, popCurrentTemplateName, pushCurrentMacroName, pushCurrentTemplateName, setCurrentResource, setMacroLibraries
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDVersion Id for serializable- See Also:
-
context
Storage for key/value pairs.
-
-
Constructor Details
-
VelocityContext
public VelocityContext()Creates a new instance (with no inner context). -
VelocityContext
Creates a new instance with the provided storage (and no inner context).- Parameters:
context
-
-
VelocityContext
Chaining constructor, used when you want to wrap a context in another. The inner context will be 'read only' - put() calls to the wrapping context will only effect the outermost context- Parameters:
innerContext
- TheContext
implementation to wrap.
-
VelocityContext
Initializes internal storage (never tonull
), and inner context.- Parameters:
context
- Internal storage, ornull
to create default storage.innerContext
- Inner context.
-
-
Method Details
-
internalGet
retrieves value for key from internal storage- Specified by:
internalGet
in classAbstractContext
- Parameters:
key
- name of value to get- Returns:
- value as object
-
internalPut
stores the value for key to internal storage- Specified by:
internalPut
in classAbstractContext
- Parameters:
key
- name of value to storevalue
- value to store- Returns:
- previous value of key as Object
-
internalContainsKey
determines if there is a value for the given key- Specified by:
internalContainsKey
in classAbstractContext
- Parameters:
key
- name of value to check- Returns:
- true if non-null value in store
-
internalGetKeys
returns array of keys- Specified by:
internalGetKeys
in classAbstractContext
- Returns:
- keys as []
-
internalRemove
remove a key/value pair from the internal storage- Specified by:
internalRemove
in classAbstractContext
- Parameters:
key
- name of value to remove- Returns:
- value removed
-
clone
Clones this context object.
-