org.apache.velocity
Class VelocityContext

java.lang.Object
  extended by org.apache.velocity.context.AbstractContext
      extended by org.apache.velocity.VelocityContext
All Implemented Interfaces:
Serializable, Cloneable, Context, InternalEventContext

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 191743 2005-06-21 23:22:20Z dlr $
Author:
Geir Magnusson Jr., Jason van Zyl, Fedor Karpelevitch, Daniel Rall
See Also:
Context, Serialized Form

Constructor Summary
VelocityContext()
          Creates a new instance (with no inner context).
VelocityContext(Context innerContext)
          Chaining constructor, used when you want to wrap a context in another.
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.
 
Method Summary
 EventCartridge attachEventCartridge(EventCartridge ec)
           
 Object clone()
          Clones this context object.
 boolean getAllowRendering()
          Checks to see if rendering should be allowed.
 Resource getCurrentResource()
          temporary fix to enable #include() to figure out current encoding.
 String getCurrentTemplateName()
          get the current template name
 EventCartridge getEventCartridge()
           
 Object[] getTemplateNameStack()
          get the current template name stack
 IntrospectionCacheData icacheGet(Object key)
          returns an IntrospectionCache Data (@see IntrospectionCacheData) object if exists for the key
 void icachePut(Object key, IntrospectionCacheData o)
          places an IntrospectionCache Data (@see IntrospectionCacheData) element in the cache for specified key
 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
 void popCurrentTemplateName()
          remove the current template name from stack
 void pushCurrentTemplateName(String s)
          set the current template name on top of stack
 void setAllowRendering(boolean v)
          Set whether rendering is allowed.
 void setCurrentResource(Resource r)
           
 
Methods inherited from class org.apache.velocity.context.AbstractContext
containsKey, get, getChainedContext, getKeys, put, remove
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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(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.

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.
Method Detail

internalGet

public Object internalGet(String key)
retrieves value for key from internal storage

Specified by:
internalGet in class AbstractContext
Parameters:
key - name of value to get
Returns:
value as object

internalPut

public Object internalPut(String key,
                          Object value)
stores the value for key to internal storage

Specified by:
internalPut in class AbstractContext
Parameters:
key - name of value to store
value - value to store
Returns:
previous value of key as Object

internalContainsKey

public boolean internalContainsKey(Object key)
determines if there is a value for the given key

Specified by:
internalContainsKey in class AbstractContext
Parameters:
key - name of value to check
Returns:
true if non-null value in store

internalGetKeys

public Object[] internalGetKeys()
returns array of keys

Specified by:
internalGetKeys in class AbstractContext
Returns:
keys as []

internalRemove

public Object internalRemove(Object key)
remove a key/value pair from the internal storage

Specified by:
internalRemove in class AbstractContext
Parameters:
key - name of value to remove
Returns:
value removed

clone

public Object clone()
Clones this context object.

Overrides:
clone in class Object
Returns:
A deep copy of this Context.

pushCurrentTemplateName

public void pushCurrentTemplateName(String s)
set the current template name on top of stack

Parameters:
s - current template name

popCurrentTemplateName

public void popCurrentTemplateName()
remove the current template name from stack


getCurrentTemplateName

public String getCurrentTemplateName()
get the current template name

Returns:
String current template name

getTemplateNameStack

public Object[] getTemplateNameStack()
get the current template name stack

Returns:
Object[] with the template name stack contents.

icacheGet

public IntrospectionCacheData icacheGet(Object key)
returns an IntrospectionCache Data (@see IntrospectionCacheData) object if exists for the key

Parameters:
key - key to find in cache
Returns:
cache object

icachePut

public void icachePut(Object key,
                      IntrospectionCacheData o)
places an IntrospectionCache Data (@see IntrospectionCacheData) element in the cache for specified key

Parameters:
key - key
o - IntrospectionCacheData object to place in cache

setCurrentResource

public void setCurrentResource(Resource r)

getCurrentResource

public Resource getCurrentResource()
temporary fix to enable #include() to figure out current encoding.


getAllowRendering

public boolean getAllowRendering()
Checks to see if rendering should be allowed. Defaults to true but will return false after a #stop directive.

Returns:
true if rendering is allowed, false if no rendering should occur

setAllowRendering

public void setAllowRendering(boolean v)
Set whether rendering is allowed. Defaults to true but is set to false after a #stop directive.


attachEventCartridge

public EventCartridge attachEventCartridge(EventCartridge ec)
Specified by:
attachEventCartridge in interface InternalEventContext

getEventCartridge

public EventCartridge getEventCartridge()
Specified by:
getEventCartridge in interface InternalEventContext


Copyright © 2002 Apache Software Foundation. All Rights Reserved.