org.webmacro.directive
Class Directive

java.lang.Object
  extended byorg.webmacro.directive.Directive
All Implemented Interfaces:
Macro, Visitable
Direct Known Subclasses:
AlternateDirective, AttributeDirective, BeanDirective, CommentDirective, CountDirective, DefaultDirective, DummyDirective, EvalDirective, ForeachDirective, GlobalDirective, IncludeDirective, MacroDirective, ParamDirective, SetblockDirective, SetDirective, SetpropsDirective, TempletDirective, TextDirective, TypeDirective

public abstract class Directive
extends java.lang.Object
implements Macro, Visitable

Directive is an abstract class which directives can extend. Nested within Directive (as static classes) are a host of classes used for building directive argument lists. Directives are Macros, so they must implement the Macro interface. For convenience, an implementation of evaluate() (written in terms of write()) is provided in the base class.) Directives must implement the following static method: public DirectiveDescriptor getDescriptor(); It is expected that all directives will build a copy of their descriptor statically, using the various XxxArg() constructors, and return a reference to that from getDescriptor().

Author:
Brian Goetz

Nested Class Summary
static class Directive.ArgDescriptor
          ArgDescriptor is the base class for all the different types of argument descriptors, like ConditionalArg, KeywordArg, RValueArg, etc.
static class Directive.AssignmentArg
          Assignment.
static class Directive.BlockArg
          Block argument type.
static class Directive.ConditionArg
          Condition argument type.
static class Directive.ExactlyOneChoice
          The ExactlyOneChoice indicates that exactly one of several optional groups can be accepted, only once.
static class Directive.FormalArgListArg
          Argument list.
static class Directive.KeywordArg
          Keyword argument type.
static class Directive.LiteralBlockArg
          Literal block argument type.
static class Directive.LValueArg
          LValue argument type.
static class Directive.NameArg
          Implements an argument as a simple name.
static class Directive.NotSimpleVariableBuildException
          Utility exception used by directives to signal that an argument that was supposed to be a simple Variable (only one term) is not.
static class Directive.NotVariableBuildException
          Utility exception used by directives to signal that an argument that was supposed to be a Variable is not a variable.
static class Directive.OptionalGroup
          Optional group.
static class Directive.OptionalRepeatingSubdirective
          Optional repeating subdirective.
static class Directive.OptionalSubdirective
          Optional subdirective.
static class Directive.OptionChoice
          The OptionChoice indicates that several optional groups can be accepted in any order.
static class Directive.QuotedStringArg
          Quoted string argument type.
static class Directive.RValueArg
          RValue argument type.
static class Directive.SingleOptionChoice
          The SingleOptionChoice indicates that zero or one of several optional groups can be accepted, but only once.
static class Directive.StringArg
          String argument type.
static class Directive.Subdirective
          Subdirectives are like directives, except that they do not have their own class.
 
Field Summary
static int ArgType_ARGLIST
           
static int ArgType_ASSIGN
           
static int ArgType_BLOCK
           
static int ArgType_CHOICE
           
static int ArgType_CONDITION
           
static int ArgType_GROUP
           
static int ArgType_KEYWORD
           
static int ArgType_LITBLOCK
           
static int ArgType_LVALUE
           
static int ArgType_NAME
           
static int ArgType_QUOTEDSTRING
           
static int ArgType_RVALUE
           
static int ArgType_STRING
           
static int ArgType_SUBDIRECTIVE
           
 
Constructor Summary
Directive()
           
 
Method Summary
 void accept(TemplateVisitor v)
           
abstract  java.lang.Object build(DirectiveBuilder b, BuildContext bc)
          Directives must implement a build() method.
 java.lang.Object evaluate(Context context)
          same as out but returns a String
protected static java.lang.String getWarningText(java.lang.String warning, Context context)
          Convenience method for directives to write HTML warnings into the output stream.
protected static void writeWarning(java.lang.String warning, Context context, FastWriter writer)
          Convenience method for directives to write HTML warnings into the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.webmacro.Macro
write
 

Field Detail

ArgType_CONDITION

public static final int ArgType_CONDITION
See Also:
Constant Field Values

ArgType_LVALUE

public static final int ArgType_LVALUE
See Also:
Constant Field Values

ArgType_RVALUE

public static final int ArgType_RVALUE
See Also:
Constant Field Values

ArgType_KEYWORD

public static final int ArgType_KEYWORD
See Also:
Constant Field Values

ArgType_ASSIGN

public static final int ArgType_ASSIGN
See Also:
Constant Field Values

ArgType_BLOCK

public static final int ArgType_BLOCK
See Also:
Constant Field Values

ArgType_LITBLOCK

public static final int ArgType_LITBLOCK
See Also:
Constant Field Values

ArgType_SUBDIRECTIVE

public static final int ArgType_SUBDIRECTIVE
See Also:
Constant Field Values

ArgType_QUOTEDSTRING

public static final int ArgType_QUOTEDSTRING
See Also:
Constant Field Values

ArgType_STRING

public static final int ArgType_STRING
See Also:
Constant Field Values

ArgType_NAME

public static final int ArgType_NAME
See Also:
Constant Field Values

ArgType_ARGLIST

public static final int ArgType_ARGLIST
See Also:
Constant Field Values

ArgType_GROUP

public static final int ArgType_GROUP
See Also:
Constant Field Values

ArgType_CHOICE

public static final int ArgType_CHOICE
See Also:
Constant Field Values
Constructor Detail

Directive

public Directive()
Method Detail

build

public abstract java.lang.Object build(DirectiveBuilder b,
                                       BuildContext bc)
                                throws BuildException
Directives must implement a build() method. The build method should examine the directive arguments (available through the DirectiveBuilder) and return a macro describing the built directive. In most cases, build() will just set up the directive's private fields and return 'this', but in some cases, no macro needs be returned (such as directives with only side effects on the build context) or some other macro may be returned (such as in the case of "#if (true) { }" -- no IfDirective object need be returned, just return the block.)

Throws:
BuildException

evaluate

public java.lang.Object evaluate(Context context)
                          throws PropertyException
Description copied from interface: Macro
same as out but returns a String

Specified by:
evaluate in interface Macro
Throws:
PropertyException - if required data was missing from context

getWarningText

protected static java.lang.String getWarningText(java.lang.String warning,
                                                 Context context)
                                          throws java.io.IOException,
                                                 PropertyException
Convenience method for directives to write HTML warnings into the output stream. Eventually this will be parameterizable so that HTML is not assumed to be the only underlying language.

Throws:
java.io.IOException
PropertyException

writeWarning

protected static void writeWarning(java.lang.String warning,
                                   Context context,
                                   FastWriter writer)
                            throws java.io.IOException,
                                   PropertyException
Convenience method for directives to write HTML warnings into the output stream. Eventually this will be parameterizable so that HTML is not assumed to be the only underlying language.

This method also outputs the same warning message to a log named "directive"

Throws:
java.io.IOException
PropertyException

accept

public void accept(TemplateVisitor v)
Specified by:
accept in interface Visitable


Copyright © 1999-2006 WebMacro. All Rights Reserved.