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 put() of references that aren't args to the VM are considered local to the vm, protecting the global context.

Version:
$Id: VMContext.java 471908 2006-11-06 22:39:28Z henning $
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)
          Indicates whether the specified key is in the context.
 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()
          Get all the keys for the values in the context.
 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
 Object localPut(String key, Object value)
          Allows callers to explicitly put objects in the local context, no matter what the velocimacro.context.local setting says.
 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.
protected  Object put(String key, Object value, boolean forceLocal)
          Internal put method to select between local and global scope.
 Object remove(Object key)
          Removes the value associated with the specified key from the context.
 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

Parameters:
inner -
rsvc -
Method Detail

getInternalUserContext

public Context getInternalUserContext()
Return the inner / user context.

Specified by:
getInternalUserContext in interface InternalWrapperContext
Returns:
The inner / user context.

getBaseContext

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

Specified by:
getBaseContext in interface InternalWrapperContext
Returns:
The base full context impl.
See Also:
InternalWrapperContext.getBaseContext()

addVMProxyArg

public void addVMProxyArg(VMProxyArg vmpa)
                   throws MethodInvocationException
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
Throws:
MethodInvocationException

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

localPut

public Object localPut(String key,
                       Object value)
Allows callers to explicitly put objects in the local context, no matter what the velocimacro.context.local setting says. Needed e.g. for loop variables in foreach.

Specified by:
localPut in interface InternalWrapperContext
Parameters:
key - name of item to set.
value - object to set to key.
Returns:
old stored object

put

protected Object put(String key,
                     Object value,
                     boolean forceLocal)
Internal put method to select between local and global scope.

Parameters:
key - name of item to set
value - object to set to key
forceLocal - True forces the object into the local scope.
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)
Description copied from interface: Context
Indicates whether the specified key is in the context.

Specified by:
containsKey in interface Context
Parameters:
key - The key to look for.
Returns:
Whether the key is in the context.
See Also:
Context.containsKey(java.lang.Object)

getKeys

public Object[] getKeys()
Description copied from interface: Context
Get all the keys for the values in the context.

Specified by:
getKeys in interface Context
Returns:
All the keys for the values in the context.
See Also:
Context.getKeys()

remove

public Object remove(Object key)
Description copied from interface: Context
Removes the value associated with the specified key from the context.

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.
See Also:
Context.remove(java.lang.Object)

pushCurrentTemplateName

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

Parameters:
s - current template name
See Also:
InternalHousekeepingContext.pushCurrentTemplateName(java.lang.String)

popCurrentTemplateName

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

See Also:
InternalHousekeepingContext.popCurrentTemplateName()

getCurrentTemplateName

public String getCurrentTemplateName()
get the current template name

Returns:
String current template name
See Also:
InternalHousekeepingContext.getCurrentTemplateName()

getTemplateNameStack

public Object[] getTemplateNameStack()
Returns the template name stack in form of an array.

Returns:
Object[] with the template name stack contents.
See Also:
InternalHousekeepingContext.getTemplateNameStack()

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
See Also:
InternalHousekeepingContext.icacheGet(java.lang.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
See Also:
InternalHousekeepingContext.icachePut(java.lang.Object, org.apache.velocity.util.introspection.IntrospectionCacheData)

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
See Also:
InternalHousekeepingContext.getAllowRendering()

setAllowRendering

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

See Also:
InternalHousekeepingContext.setAllowRendering(boolean)

attachEventCartridge

public EventCartridge attachEventCartridge(EventCartridge ec)
Specified by:
attachEventCartridge in interface InternalEventContext
Returns:
The old EventCartridge.
See Also:
InternalEventContext.attachEventCartridge(org.apache.velocity.app.event.EventCartridge)

getEventCartridge

public EventCartridge getEventCartridge()
Specified by:
getEventCartridge in interface InternalEventContext
Returns:
The current EventCartridge.
See Also:
InternalEventContext.getEventCartridge()

setCurrentResource

public void setCurrentResource(Resource r)
See Also:
InternalHousekeepingContext.setCurrentResource(org.apache.velocity.runtime.resource.Resource)

getCurrentResource

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

Returns:
The current resource.
See Also:
InternalHousekeepingContext.getCurrentResource()


Copyright © 2000-2007 The Apache Software Foundation. All Rights Reserved.