org.apache.velocity.context
Class VMContext

java.lang.Object
  extended by org.apache.velocity.context.VMContext
All Implemented Interfaces:
Context, InternalContextAdapter, InternalEventContext, InternalWrapperContext

public class VMContext
extends 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 151591 2005-02-06 15:42:19Z wglass $
Author:
Geir Magnusson Jr.

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.
 boolean getAllowRendering()
          Checks to see if rendering should be allowed.
 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 setAllowRendering(boolean v)
          Set whether rendering is allowed.
 void setCurrentResource(Resource r)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VMContext

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

Method Detail

getInternalUserContext

public Context getInternalUserContext()
return the inner / user context

Specified by:
getInternalUserContext in interface InternalWrapperContext

getBaseContext

public InternalContextAdapter getBaseContext()
Description copied from interface: InternalWrapperContext
returns the base full context impl

Specified by:
getBaseContext in interface InternalWrapperContext

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

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

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

containsKey

public boolean containsKey(Object key)
not yet impl

Specified by:
containsKey in interface Context
Parameters:
key - The key to look for.
Returns:
Whether the key is in the context.

getKeys

public Object[] getKeys()
impl badly

Specified by:
getKeys in interface Context

remove

public Object remove(Object key)
impl badly

Specified by:
remove in interface Context
Parameters:
key - The name of the value to remove.
Returns:
The value that the key was mapped to, or null if unmapped.

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()
Returns the template name stack in form of an array.

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

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

setCurrentResource

public void setCurrentResource(Resource r)

getCurrentResource

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



Copyright © 2002 Apache Software Foundation. All Rights Reserved.