Class ProxyVMContext

  • All Implemented Interfaces:
    Context, InternalContextAdapter, InternalEventContext, 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
    • 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,
                                  java.lang.String macroArgumentName,
                                  java.lang.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,
                                  java.lang.String macroArgumentName,
                                  java.lang.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 java.lang.Object put​(java.lang.String key,
                                    java.lang.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
      • put

        protected java.lang.Object put​(java.lang.String key,
                                       java.lang.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 java.lang.Object get​(java.lang.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
      • remove

        public java.lang.Object remove​(java.lang.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
        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)