All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----org.webmacro.engine.Variable
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").
protected final String vname
public final String toString()
public final Object evaluate(Object context)
public final void write(Writer out, Object context) throws InvalidContextException, IOException
public static final Object parse(ParseTool in) throws ParseException, IOException
public static void main(String args[])
public final Object getValue(Object context) throws InvalidContextException
public final void setValue(Object context, Object newValue) throws InvalidContextException
All Packages Class Hierarchy This Package Previous Next Index