C# Class NVelocity.Runtime.Directive.VMProxyArg

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.
Afficher le fichier Open project: rasmus-toftdahl-olesen/NVelocity Class Usage Examples

Méthodes publiques

Méthode Description
VMProxyArg ( IRuntimeServices rs, String contextRef, String callerRef, int t ) : System

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, IInternalContextAdapter c ) : System

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

getObject ( IInternalContextAdapter context ) : Object

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 *

isConstant ( ) : bool

tells if arg we are proxying for is dynamic or constant. *

setObject ( IInternalContextAdapter context, Object o ) : Object

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

Private Methods

Méthode Description
setup ( ) : void

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

Method Details

VMProxyArg() public méthode

ctor for current impl * takes the reference literal we are proxying for, the literal the VM we are for is called with... *
public VMProxyArg ( IRuntimeServices rs, String contextRef, String callerRef, int t ) : System
rs IRuntimeServices ///
contextRef String reference arg in the definition of the VM, used in the VM ///
callerRef String reference used by the caller as an arg to the VM ///
t int type of arg : JJTREFERENCE, JJTTRUE, etc /// ///
Résultat System

VMProxyArg() public méthode

not used in current impl * Constructor for alternate impl where VelProxy class would make new VMProxyArg objects, and use this constructor to avoid re-parsing the reference args * that impl also had the VMProxyArg carry it's context
public VMProxyArg ( VMProxyArg model, IInternalContextAdapter c ) : System
model VMProxyArg
c IInternalContextAdapter
Résultat System

getObject() public méthode

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 *
public getObject ( IInternalContextAdapter context ) : Object
context IInternalContextAdapter Context to use for getting current value ///
Résultat Object

isConstant() public méthode

tells if arg we are proxying for is dynamic or constant. *
public isConstant ( ) : bool
Résultat bool

setObject() public méthode

Invoked by VMContext when Context.put() is called for a proxied reference. *
public setObject ( IInternalContextAdapter context, Object o ) : Object
context IInternalContextAdapter context to modify via direct placement, or AST.setValue() ///
o Object new value of reference ///
Résultat Object