org.apache.velocity

Class VelocityContext

Implemented Interfaces:
Cloneable, Context, Serializable, InternalEventContext, InternalHousekeepingContext, Serializable

public class VelocityContext
extends AbstractContext
implements Cloneable

General purpose implemention 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: VelocityContext.java,v 1.6.8.1 2004/03/03 22:27:36 geirm Exp $

Authors:
Geir Magnusson Jr.
Jason van Zyl
Fedor Karpelevitch
Daniel Rall

See Also:
Context

Field Summary

private Map
context
Storage for key/value pairs.

Fields inherited from class org.apache.velocity.context.AbstractContext

innerContext

Fields inherited from class org.apache.velocity.context.InternalContextBase

currentResource, eventCartridge, introspectionCache, templateNameStack

Constructor Summary

VelocityContext()
Creates a new instance (with no inner context).
VelocityContext(Map context)
Creates a new instance with the provided storage (and no inner context).
VelocityContext(Map context, Context innerContext)
Initializes internal storage (never to null), and inner context.
VelocityContext(Context innerContext)
Chaining constructor, used when you want to wrap a context in another.

Method Summary

Object
clone()
Clones this context object.
boolean
internalContainsKey(Object key)
determines if there is a value for the given key
Object
internalGet(String key)
retrieves value for key from internal storage
Object[]
internalGetKeys()
returns array of keys
Object
internalPut(String key, Object value)
stores the value for key to internal storage
Object
internalRemove(Object key)
remove a key/value pair from the internal storage

Methods inherited from class org.apache.velocity.context.AbstractContext

containsKey, get, getChainedContext, getKeys, internalContainsKey, internalGet, internalGetKeys, internalPut, internalRemove, put, remove

Methods inherited from class org.apache.velocity.context.InternalContextBase

attachEventCartridge, getCurrentResource, getCurrentTemplateName, getEventCartridge, getTemplateNameStack, icacheGet, icachePut, popCurrentTemplateName, pushCurrentTemplateName, setCurrentResource

Field Details

context

private Map context
Storage for key/value pairs.

Constructor Details

VelocityContext

public VelocityContext()
Creates a new instance (with no inner context).


VelocityContext

public VelocityContext(Map context)
Creates a new instance with the provided storage (and no inner context).


VelocityContext

public VelocityContext(Map context,
                       Context innerContext)
Initializes internal storage (never to null), and inner context.

Parameters:
context - Internal storage, or null to create default storage.
innerContext - Inner context.


VelocityContext

public VelocityContext(Context innerContext)
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 - The Context implementation to wrap.

Method Details

clone

public Object clone()
Clones this context object.

Returns:
A deep copy of this Context.


internalContainsKey

public boolean internalContainsKey(Object key)
determines if there is a value for the given key
Overrides:
internalContainsKey in interface AbstractContext

Parameters:
key - name of value to check

Returns:
true if non-null value in store


internalGet

public Object internalGet(String key)
retrieves value for key from internal storage
Overrides:
internalGet in interface AbstractContext

Parameters:
key - name of value to get

Returns:
value as object


internalGetKeys

public Object[] internalGetKeys()
returns array of keys
Overrides:
internalGetKeys in interface AbstractContext

Returns:
keys as []


internalPut

public Object internalPut(String key,
                          Object value)
stores the value for key to internal storage
Overrides:
internalPut in interface AbstractContext

Parameters:
key - name of value to store
value - value to store

Returns:
previous value of key as Object


internalRemove

public Object internalRemove(Object key)
remove a key/value pair from the internal storage
Overrides:
internalRemove in interface AbstractContext

Parameters:
key - name of value to remove

Returns:
value removed


Copyright B) 2002 Apache Software Foundation. All Rights Reserved.