All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.webmacro.engine.Variable

java.lang.Object
   |
   +----org.webmacro.engine.Variable

public class Variable
extends Object
implements Macro
A Variable is a reference into a Propertymap.

A variable name contains a list of names separated by dots, for example "$User.Identity.email.address" is the list: User, Identity, email, and address.

PLEASE NOTE: Case-sensitivity is enforced. "User" is the the same name as "user".

What that means: When a template is interpreted, it is interpreted in terms of data in a hashtable/map called the "context". This is actually a Map of type Map. The context contains all the local variables that have been set, as well as other information that Macros may use to evaluate the request.

Variable depends heavily on Property introspection: It is defined as a list of one or more names (separated by dots when written).

Those names are references to sub-objects within the context. The Variable instance, when interpreted, will decend through the context following fields, method references, or hash table look-ups based on its names.

For example, the variable "$User.Identity.email.address" implies that there is a "User" object under the Map--either it is a field within the map, or the map has a getUser() method, or the User can be obtained by calling Map.get("User").

The full expansion of $User.Identity.email.address might be:

    Map.get("User").getIdentity().get("email").address
 
. Variable (actually the Property class it uses) will figure out how to decend through the object like this until it finds the final reference--which is the "value" of the variable.

When searchin for subfields Variable prefers fields over getFoo() methods, and getFoo() over get("Foo").


Variable Index

 o vname
The name of this variable.

Method Index

 o evaluate(Object)
Looks in the hashTable (context) for a value keyed to this variables name and returns the value string.
 o getValue(Object)
Look up my value in the corresponding Map, possibly using introspection, and return it
 o main(String[])
Test harness
 o parse(ParseTool)
Attempt to parse a variable name.
 o setValue(Object, Object)
Look up my the value of this variable in the specified Map, possibly using introspection, and set it to the supplied value.
 o toString()
Return a string name of this variable
 o write(Writer, Object)
Look in the hashtable (context) for a value keyed to this variables name and write its value to the stream.

Variables

 o vname
 protected final String vname
The name of this variable.

Methods

 o toString
 public final String toString()
Return a string name of this variable

Overrides:
toString in class Object
 o evaluate
 public final Object evaluate(Object context)
Looks in the hashTable (context) for a value keyed to this variables name and returns the value string. If the resulting value is a Macro, recursively call its evaluate method.

Returns:
String
 o write
 public final void write(Writer out,
                         Object context) throws InvalidContextException, IOException
Look in the hashtable (context) for a value keyed to this variables name and write its value to the stream.

Throws: InvalidContextException
is required data is missing
Throws: IOException
if could not write to output stream
 o parse
 public static final Object parse(ParseTool in) throws ParseException, IOException
Attempt to parse a variable name. The '$' has already been eaten, expect that the next thing on the parseTool is the variables name, followed by an optional ';'. If the name begins with $$ it will be considered a static parameter and must only contain a single name; the value of the parameter will be returned as a string.

Returns:
a Variable object
Throws: ParseException
on unrecoverable parse error
Throws: IOException
on failure to read from parseTool
 o main
 public static void main(String args[])
Test harness

 o getValue
 public final Object getValue(Object context) throws InvalidContextException
Look up my value in the corresponding Map, possibly using introspection, and return it

Throws: InvalidContextException
If the property does not exist
 o setValue
 public final void setValue(Object context,
                            Object newValue) throws InvalidContextException
Look up my the value of this variable in the specified Map, possibly using introspection, and set it to the supplied value.

Throws: InvalidContextException
If the property does not exist

All Packages  Class Hierarchy  This Package  Previous  Next  Index