|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.webmacro.engine.Variable
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").
| Field Summary | |
protected java.lang.Object[] |
_names
The name as an array |
protected java.lang.String |
_vname
The name of this variable. |
static java.lang.Object |
LOCAL_TYPE
|
static java.lang.Object |
PROPERTY_TYPE
|
| Method Summary | |
void |
accept(TemplateVisitor v)
|
java.lang.Object |
evaluate(Context context)
Looks in the hashTable (context) for a value keyed to this variables name and returns the value string. |
java.lang.String |
getName()
Like getPropertyNames, but only works if isSimpleName is true |
java.lang.String[] |
getPropertyNames()
|
abstract java.lang.Object |
getValue(Context context)
The code to get the value represented by the variable from the supplied context. |
java.lang.String |
getVariableName()
Return the canonical name for this variable |
boolean |
isSimpleName()
Returns true if the Variable describes a simple name (one with only one element) |
abstract void |
setValue(Context c,
java.lang.Object v)
The code to set the value represented by the variable in the supplied context. |
abstract java.lang.String |
toString()
Return the String name of the variable prefixed with a string representing its type. |
void |
write(FastWriter out,
Context context)
Look in the hashtable (context) for a value keyed to this variables name and write its value to the stream. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final java.lang.Object PROPERTY_TYPE
public static final java.lang.Object LOCAL_TYPE
protected java.lang.String _vname
protected java.lang.Object[] _names
| Method Detail |
public final java.lang.String[] getPropertyNames()
public final java.lang.String getName()
public final boolean isSimpleName()
public final java.lang.Object evaluate(Context context)
throws PropertyException
evaluate in interface MacroPropertyException - if required data was missing from context
public final void write(FastWriter out,
Context context)
throws PropertyException,
java.io.IOException
write in interface MacroPropertyException - is required data is missing
java.io.IOException - if could not write to output stream
public abstract java.lang.Object getValue(Context context)
throws PropertyException
PropertyException
public abstract void setValue(Context c,
java.lang.Object v)
throws PropertyException
PropertyExceptionpublic abstract java.lang.String toString()
public java.lang.String getVariableName()
public void accept(TemplateVisitor v)
accept in interface Visitable
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||