VMProxyArg (Velocity 1.4 API)
Keywords: org.apache.velocity.runtime.directive.VMProxyArg 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.runtime.directive
Class VMProxyArg

    java.lang.Object
      org.apache.velocity.runtime.directive.VMProxyArg

public class VMProxyArg
extends java.lang.Object

The function of this class is to proxy for the calling parameter to the VM. This class is designed to be used in conjunction with the VMContext class which knows how to get and set values via it, rather than a simple get() or put() from a hashtable-like object. There is probably a lot of undocumented subtlty here, so step lightly. We rely on the observation that an instance of this object has a constant state throughout its lifetime as it's bound to the use-instance of a VM. In other words, it's created by the VelocimacroProxy class, to represent one of the arguments to a VM in a specific template. Since the template is fixed (it's a file...), we don't have to worry that the args to the VM will change. Yes, the VM will be called in other templates, or in other places on the same template, bit those are different use-instances. These arguments can be, in the lingo of the parser, one of :

- Reference() : anything that starts with '$'
- StringLiteral() : something like "$foo" or "hello geir"
- NumberLiteral() : 1, 2 etc
- IntegerRange() : [ 1..2] or [$foo .. $bar]
- ObjectArray() : [ "a", "b", "c"]
- True() : true
- False() : false
- Word() : not likely - this is simply allowed by the parser so we can have syntactical sugar like #foreach($a in $b) where 'in' is the Word

Now, Reference(), StringLit, NumberLit, IntRange, ObjArr are all dynamic things, so their value is gotten with the use of a context. The others are constants. The trick we rely on is that the context rather than this class really represents the state of the argument. We are simply proxying for the thing, returning the proper value when asked, and storing the proper value in the appropriate context when asked. So, the hope here, so an instance of this can be shared across threads, is to keep any dynamic stuff out of it, relying on trick of having the appropriate context handed to us, and when a constant argument, letting VMContext punch that into a local context.

Version:
  $Id: VMProxyArg.java,v 1.13.4.1 2004/03/03 23:22:56 geirm Exp $
Author:
  Geir Magnusson Jr.

Field Summary
`private java.lang.String` | `callerReference` the reference we are proxying for
`private boolean` | `constant` by default, we are dynamic.
`private java.lang.String` | `contextReference` our identity in the current context
`private int` | `GENERALSTATIC` in the event our type is switched - we don't care really what it is
`private SimpleNode` | `nodeTree` the AST if the type is such that it's dynamic (ex.
`private int` | `numTreeChildren` number of children in our tree if a reference
`private RuntimeServices` | `rsvc`
`private java.lang.String` | `singleLevelRef` the 'de-dollared' reference if we are a ref but don't have a method attached
`private java.lang.Object` | `staticObject` reference for the object if we proxy for a static arg like an NumberLiteral
`private int` | `type` type of arg I will have
`private InternalContextAdapter` | `usercontext` not used in this impl : carries the appropriate user context

Constructor Summary
`VMProxyArg(RuntimeServices rs, java.lang.String contextRef, java.lang.String callerRef, int t)` ctor for current impl takes the reference literal we are proxying for, the literal the VM we are for is called with...
`VMProxyArg(VMProxyArg model, InternalContextAdapter c)` not used in current impl Constructor for alternate impl where VelProxy class would make new VMProxyArg objects, and use this contructor to avoid reparsing the reference args that impl also had the VMProxyArg carry it's context

Method Summary
`java.lang.String` | `getCallerReference()`
`java.lang.String` | `getContextReference()`
`SimpleNode` | `getNodeTree()`
`java.lang.Object` | `getObject(InternalContextAdapter context)` returns the value of the reference.
`java.lang.Object` | `getStaticObject()`
`int` | `getType()`
`boolean` | `isConstant()` tells if arg we are poxying for is dynamic or constant.
`java.lang.Object` | `setObject(InternalContextAdapter context, java.lang.Object o)` Invoked by VMContext when Context.put() is called for a proxied reference.
`private void` | `setup()` does the housekeeping upon creationg.

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

Field Detail

### type

    private int type

  type of arg I will have

### nodeTree

    private SimpleNode nodeTree

  the AST if the type is such that it's dynamic (ex. JJTREFERENCE )

### staticObject

    private java.lang.Object staticObject

  reference for the object if we proxy for a static arg like an NumberLiteral

### usercontext

    private InternalContextAdapter usercontext

  not used in this impl : carries the appropriate user context

### numTreeChildren

    private int numTreeChildren

  number of children in our tree if a reference

### contextReference

    private java.lang.String contextReference

  our identity in the current context

### callerReference

    private java.lang.String callerReference

  the reference we are proxying for

### singleLevelRef

    private java.lang.String singleLevelRef

  the 'de-dollared' reference if we are a ref but don't have a method attached

### constant

    private boolean constant

  by default, we are dynamic. safest

### GENERALSTATIC

    private final int GENERALSTATIC

  in the event our type is switched - we don't care really what it is

  See Also:
    Constant Field Values

### rsvc

    private RuntimeServices rsvc

Constructor Detail

### VMProxyArg

    public VMProxyArg(RuntimeServices rs,
                      java.lang.String contextRef,
                      java.lang.String callerRef,
                      int t)

  ctor for current impl takes the reference literal we are proxying for, the literal the VM we are for is called with...

Parameters:
  `contextRef` - reference arg in the definition of the VM, used in the VM
  `callerRef` - reference used by the caller as an arg to the VM
  `t` - type of arg : JJTREFERENCE, JJTTRUE, etc

### VMProxyArg

    public VMProxyArg(VMProxyArg model,
                      InternalContextAdapter c)

  not used in current impl Constructor for alternate impl where VelProxy class would make new VMProxyArg objects, and use this contructor to avoid reparsing the reference args that impl also had the VMProxyArg carry it's context

Method Detail

### isConstant

    public boolean isConstant()

  tells if arg we are poxying for is dynamic or constant.

  Returns:
    true of constant, false otherwise

### setObject

    public java.lang.Object setObject(InternalContextAdapter context,
                                      java.lang.Object o)

  Invoked by VMContext when Context.put() is called for a proxied reference.

  Parameters:
    `context` - context to modify via direct placement, or AST.setValue()
    `o` - new value of reference
  Returns:
    Object currently null

### getObject

    public java.lang.Object getObject(InternalContextAdapter context)

  returns the value of the reference. Generally, this is only called for dynamic proxies, as the static ones should have been stored in the VMContext's localcontext store

  Parameters:
    `context` - Context to use for getting current value
  Returns:
    Object value

### setup

    private void setup()

  does the housekeeping upon creationg. If a dynamic type it needs to make an AST for further get()/set() operations Anything else is constant.

### getCallerReference

    public java.lang.String getCallerReference()

### getContextReference

    public java.lang.String getContextReference()

### getNodeTree

    public SimpleNode getNodeTree()

### getStaticObject

    public java.lang.Object getStaticObject()

### getType

    public int getType()

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 © 2002 Apache Software Foundation. All Rights Reserved.