org.apache.velocity.context

Class VMContext

Implemented Interfaces:
Context, InternalContextAdapter, InternalEventContext, InternalHousekeepingContext, InternalWrapperContext

public class VMContext
extends java.lang.Object
implements InternalContextAdapter

This is a special, internal-use-only context implementation to be used for the new Velocimacro implementation. The main distinguishing feature is the management of the VMProxyArg objects in the put() and get() methods. Further, this context also supports the 'VM local context' mode, where any get() or put() of references that aren't args to the VM are considered local to the vm, protecting the global context.

Version:
$Id: VMContext.java,v 1.9.10.1 2004/03/03 23:22:54 geirm Exp $

Author:
Geir Magnusson Jr.

Field Summary

(package private) InternalContextAdapter
innerContext
the base context store.
(package private) HashMap
localcontext
container for any local or constant VMProxy items
private boolean
localcontextscope
support for local context scope feature, where all references are local
(package private) HashMap
vmproxyhash
container for our VMProxy Objects
(package private) InternalContextAdapter
wrappedContext
context that we are wrapping

Constructor Summary

VMContext(InternalContextAdapter inner, RuntimeServices rsvc)
CTOR, wraps an ICA

Method Summary

void
addVMProxyArg(VMProxyArg vmpa)
Used to put VMProxyArgs into this context.
EventCartridge
attachEventCartridge(EventCartridge ec)
boolean
containsKey(Object key)
not yet impl
Object
get(String key)
Impl of the Context.gut() method.
InternalContextAdapter
getBaseContext()
returns the base full context impl
Resource
getCurrentResource()
temporary fix to enable #include() to figure out current encoding.
String
getCurrentTemplateName()
get the current template name
EventCartridge
getEventCartridge()
Context
getInternalUserContext()
return the inner / user context
Object[]
getKeys()
impl badly
Object[]
getTemplateNameStack()
Returns the template name stack in form of an array.
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
void
popCurrentTemplateName()
remove the current template name from stack
void
pushCurrentTemplateName(String s)
set the current template name on top of stack
Object
put(String key, Object value)
Impl of the Context.put() method.
Object
remove(Object key)
impl badly
void
setCurrentResource(Resource r)

Field Details

innerContext

(package private)  InternalContextAdapter innerContext
the base context store. This is the 'global' context


localcontext

(package private)  HashMap localcontext
container for any local or constant VMProxy items


localcontextscope

private boolean localcontextscope
support for local context scope feature, where all references are local


vmproxyhash

(package private)  HashMap vmproxyhash
container for our VMProxy Objects


wrappedContext

(package private)  InternalContextAdapter wrappedContext
context that we are wrapping

Constructor Details

VMContext

public VMContext(InternalContextAdapter inner,
                 RuntimeServices rsvc)
CTOR, wraps an ICA

Method Details

addVMProxyArg

public void addVMProxyArg(VMProxyArg vmpa)
Used to put VMProxyArgs into this context. It separates the VMProxyArgs into constant and non-constant types pulling out the value of the constant types so they can be modified w/o damaging the VMProxyArg, and leaving the dynamic ones, as they modify context rather than their own state

Parameters:
vmpa - VMProxyArg to add


attachEventCartridge

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


containsKey

public boolean containsKey(Object key)
not yet impl
Specified by:
containsKey in interface Context


get

public Object get(String key)
Impl of the Context.gut() method.
Specified by:
get in interface Context

Parameters:
key - name of item to get

Returns:
stored object or null


getBaseContext

public InternalContextAdapter getBaseContext()
returns the base full context impl
Specified by:
getBaseContext in interface InternalWrapperContext


getCurrentResource

public Resource getCurrentResource()
temporary fix to enable #include() to figure out current encoding.
Specified by:
getCurrentResource in interface InternalHousekeepingContext


getCurrentTemplateName

public String getCurrentTemplateName()
get the current template name
Specified by:
getCurrentTemplateName in interface InternalHousekeepingContext

Returns:
String current template name


getEventCartridge

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


getInternalUserContext

public Context getInternalUserContext()
return the inner / user context
Specified by:
getInternalUserContext in interface InternalWrapperContext


getKeys

public Object[] getKeys()
impl badly
Specified by:
getKeys in interface Context


getTemplateNameStack

public Object[] getTemplateNameStack()
Returns the template name stack in form of an array.
Specified by:
getTemplateNameStack in interface InternalHousekeepingContext

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
Specified by:
icacheGet in interface InternalHousekeepingContext

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
Specified by:
icachePut in interface InternalHousekeepingContext

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


popCurrentTemplateName

public void popCurrentTemplateName()
remove the current template name from stack
Specified by:
popCurrentTemplateName in interface InternalHousekeepingContext


pushCurrentTemplateName

public void pushCurrentTemplateName(String s)
set the current template name on top of stack
Specified by:
pushCurrentTemplateName in interface InternalHousekeepingContext

Parameters:
s - current template name


put

public Object put(String key,
                  Object value)
Impl of the Context.put() method.
Specified by:
put in interface Context

Parameters:
key - name of item to set
value - object to set to key

Returns:
old stored object


remove

public Object remove(Object key)
impl badly
Specified by:
remove in interface Context


setCurrentResource

public void setCurrentResource(Resource r)
Specified by:
setCurrentResource in interface InternalHousekeepingContext


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