|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.webmacro.directive.Directive
org.webmacro.directive.TypeDirective
TypeDirective allows the programmer (or template designer) to ensure
objects placed into the Context
are of the required class
type.
Syntax:
#type [ required ] var-reference quoted-stringExamples:
$MyName, if it exists in the context, must be a java.lang.String #type $MyName "java.lang.String" $Today must exist in the context and must be a java.util.Date #type required $Today "java.util.Date" $Addresses, if it exists in the context, must be an org.mycompany.til.Address array #type $Addresses "org.mycompany.util.Address[]"TypeDirective simply ensures the class type of the
$Variable
isAssignableFrom
the specified classname.If the variable is not flagged as being required, then its class type is only checked if it exists in the context. By default, variables are not required to be in the context.
Special support for checking that a variable is an object array exists. Simply append matching square brackets to the end of the classname.
If a Variable is not of the specified type, TypeDirective will
throw a org.webmacro.PropertyException.InvalidTypeException
,
which one can catch in their servlet code if necessary.
TypeDirective is enabled by default, however, it can be disabled
via your custom WebMacro.properties
file:
TypeDirective.Enabled = true | false
Nested Class Summary |
Field Summary | |
static Directive.ArgDescriptor[] |
_args
|
static DirectiveDescriptor |
_dd
|
static int |
TYPE_CLASSNAME
|
static int |
TYPE_OBJECT
|
static int |
TYPE_REQUIRED
|
Fields inherited from class org.webmacro.directive.Directive |
ArgType_ARGLIST, ArgType_ASSIGN, ArgType_BLOCK, ArgType_CHOICE, ArgType_CONDITION, ArgType_GROUP, ArgType_KEYWORD, ArgType_LITBLOCK, ArgType_LVALUE, ArgType_NAME, ArgType_QUOTEDSTRING, ArgType_RVALUE, ArgType_STRING, ArgType_SUBDIRECTIVE |
Constructor Summary | |
TypeDirective()
|
Method Summary | |
void |
accept(TemplateVisitor v)
|
java.lang.Object |
build(DirectiveBuilder builder,
BuildContext bc)
configure directive for this run and return 'this' |
java.lang.Object |
evaluate(Context context)
Ensure the class of the specified Variable reference isAssignableFrom from the classname arg. |
static DirectiveDescriptor |
getDescriptor()
static method required by the WebMacro parser to provide a descriptor about this directive |
void |
write(FastWriter fw,
Context context)
The #type directive does not produce output |
Methods inherited from class org.webmacro.directive.Directive |
getWarningText, writeWarning |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int TYPE_REQUIRED
public static final int TYPE_OBJECT
public static final int TYPE_CLASSNAME
public static final Directive.ArgDescriptor[] _args
public static final DirectiveDescriptor _dd
Constructor Detail |
public TypeDirective()
Method Detail |
public static DirectiveDescriptor getDescriptor()
public java.lang.Object build(DirectiveBuilder builder, BuildContext bc) throws BuildException
build
in class Directive
BuildException
public java.lang.Object evaluate(Context context) throws PropertyException
isAssignableFrom
from the classname arg.
evaluate
in interface Macro
evaluate
in class Directive
null
, always
PropertyException.NoSuchVariableException
- if the
specified variable arg evaluates to null
PropertyException
public void write(FastWriter fw, Context context) throws java.io.IOException, PropertyException
java.io.IOException
- if we could not successfully write to out
PropertyException
- if required data was missing from contextpublic void accept(TemplateVisitor v)
accept
in interface Visitable
accept
in class Directive
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |