ProxyVMContext (Velocity 1.7 API)
Keywords: org.apache.velocity.context.ProxyVMContext class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.velocity.context
Class ProxyVMContext

    java.lang.Object
      org.apache.velocity.context.ChainedInternalContextAdapter
          org.apache.velocity.context.ProxyVMContext

All Implemented Interfaces:
  Context, InternalContextAdapter, InternalEventContext, org.apache.velocity.context.InternalHousekeepingContext, InternalWrapperContext

public class ProxyVMContext
extends ChainedInternalContextAdapter

Context for Velocity macro arguments. This special context combines ideas of earlier VMContext and VMProxyArgs by implementing routing functionality internally. This significantly reduces memory allocation upon macro invocations. Since the macro AST is now shared and RuntimeMacro directive is used, the earlier implementation of precalculating VMProxyArgs would not work. See Issue 607 for more info on this class.

Since:
  1.6
Version:
  $Id$
Author:
  Jarkko Viinamaki

Field Summary

Fields inherited from class org.apache.velocity.context.ChainedInternalContextAdapter
`innerContext`

Constructor Summary
`ProxyVMContext(InternalContextAdapter inner, RuntimeServices rsvc, boolean localContextScope)`

Method Summary
`void` | `addVMProxyArg(InternalContextAdapter context, String macroArgumentName, String literalMacroArgumentName, Node argumentValue)` Used to put Velocity macro arguments into this context.
`void` | `addVMProxyArg(InternalContextAdapter context, String macroArgumentName, String literalMacroArgumentName, Renderable argumentValue)` Used to put Velocity macro bodyContext arguments into this context.
`boolean` | `containsKey(Object key)` Indicates whether the specified key is in the context.
`Object` | `get(String key)` Implementation of the Context.get() method.
`Object[]` | `getKeys()` Get all the keys for the values in the context.
`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.
`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.

Methods inherited from class org.apache.velocity.context.ChainedInternalContextAdapter
`attachEventCartridge, getBaseContext, getCurrentMacroCallDepth, getCurrentMacroName, getCurrentResource, getCurrentTemplateName, getEventCartridge, getInternalUserContext, getMacroLibraries, getMacroNameStack, getTemplateNameStack, icacheGet, icachePut, popCurrentMacroName, popCurrentTemplateName, pushCurrentMacroName, pushCurrentTemplateName, setCurrentResource, setMacroLibraries`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ProxyVMContext

    public ProxyVMContext(InternalContextAdapter inner,
                          RuntimeServices rsvc,
                          boolean localContextScope)

Parameters:
  `inner` - Velocity context for processing
  `rsvc` - RuntimeServices provides logging reference
  `localContextScope` - if true, all references are set to be local

Method Detail

### addVMProxyArg

    public void addVMProxyArg(InternalContextAdapter context,
                              String macroArgumentName,
                              String literalMacroArgumentName,
                              Node argumentValue)
                       throws MethodInvocationException

  Used to put Velocity macro arguments into this context.

  Parameters:
    `context` - rendering context
    `macroArgumentName` - name of the macro argument that we received
    `literalMacroArgumentName` - ".literal.$"+macroArgumentName
    `argumentValue` - actual value of the macro argument
  Throws:
    `MethodInvocationException`

### addVMProxyArg

    public void addVMProxyArg(InternalContextAdapter context,
                              String macroArgumentName,
                              String literalMacroArgumentName,
                              Renderable argumentValue)
                       throws MethodInvocationException

  Used to put Velocity macro bodyContext arguments into this context.

  Parameters:
    `context` - rendering context
    `macroArgumentName` - name of the macro argument that we received
    `literalMacroArgumentName` - ".literal.$"+macroArgumentName
    `argumentValue` - actual value of the macro body
  Throws:
    `MethodInvocationException`

### put

    public Object put(String key,
                      Object value)

  Impl of the Context.put() method.

  Specified by:
    `put` in interface `Context`
  Overrides:
    `put` in class `ChainedInternalContextAdapter`
  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`
  Overrides:
    `localPut` in class `ChainedInternalContextAdapter`
  Parameters:
    `key` - name of item to set.
    `value` - object to set to key.
  Returns:
    old stored object
  See Also:
    `InternalWrapperContext.localPut(java.lang.String,java.lang.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)

  Implementation of the Context.get() method. First checks localcontext, then arguments, then global context.

  Specified by:
    `get` in interface `Context`
  Overrides:
    `get` in class `ChainedInternalContextAdapter`
  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`
  Overrides:
    `containsKey` in class `ChainedInternalContextAdapter`
  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`
  Overrides:
    `getKeys` in class `ChainedInternalContextAdapter`
  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`
  Overrides:
    `remove` in class `ChainedInternalContextAdapter`
  See Also:
    `Context.remove(java.lang.Object)`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2010 Apache Software Foundation. All Rights Reserved.