org.webmacro.directive
Class DirectiveBuilder

java.lang.Object
  extended byorg.webmacro.directive.DirectiveBuilder
All Implemented Interfaces:
Builder, DirectiveArgs

public final class DirectiveBuilder
extends java.lang.Object
implements Builder, DirectiveArgs

DirectiveBuilder manages the building of directives. It is created by the parser, which populates it with the directive arguments, and the DirectiveBuilder.build() method calls the build() method for the appropriate directive.

Author:
Brian Goetz

Constructor Summary
DirectiveBuilder(DirectiveDescriptor desc)
           
 
Method Summary
 java.lang.Object build(BuildContext bc)
          Build the directive.
 java.lang.Object getArg(int argId)
          Retrieve the argument whose id is the specified id.
 java.lang.Object getArg(int argId, BuildContext bc)
          Retrieve the argument whose id is the specified id, and if it is a Builder, build it with the specified build context.
 int getArgCount()
          How many arguments does this builder have?
 java.lang.Object getExactArg(int idx)
           
 java.lang.String getName()
          Get the name this directive was registered as
 ArgsHolder[] getRepeatingSubdirective(int subdId)
          Retrieves an array of ArgsHolders for the associated subdirective so that the subdirective arguments can be retrieved.
 ArgsHolder getSubdirective(int subdId)
          Retrieves the ArgsHolder for the associated subdirective so that the subdirective arguments can be retrieved.
 int getSubdirectiveCount(int subdId)
          Find out how many subdirectives of the specified id were present.
 DirectiveArgs newSubdirective(int subdId)
          Create a new subdirective of the specified id and create an ArgsHolder for its arguments.
 void setArg(int argId, java.lang.Object arg)
          Set the argument whose id is the specified id.
 boolean subdirectiveOk(int subdId)
          Check to see if the specified subdirective is OK at this point.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DirectiveBuilder

public DirectiveBuilder(DirectiveDescriptor desc)
Method Detail

getExactArg

public java.lang.Object getExactArg(int idx)
                             throws BuildException
Specified by:
getExactArg in interface DirectiveArgs
Throws:
BuildException

getArgCount

public int getArgCount()
How many arguments does this builder have?

Specified by:
getArgCount in interface DirectiveArgs

getArg

public java.lang.Object getArg(int argId)
                        throws BuildException
Retrieve the argument whose id is the specified id.

Specified by:
getArg in interface DirectiveArgs
Throws:
BuildException

getArg

public java.lang.Object getArg(int argId,
                               BuildContext bc)
                        throws BuildException
Retrieve the argument whose id is the specified id, and if it is a Builder, build it with the specified build context.

Specified by:
getArg in interface DirectiveArgs
Throws:
BuildException

getSubdirectiveCount

public int getSubdirectiveCount(int subdId)
                         throws BuildException
Find out how many subdirectives of the specified id were present.

Throws:
BuildException

setArg

public void setArg(int argId,
                   java.lang.Object arg)
            throws BuildException
Set the argument whose id is the specified id. If the argument has already been set, it is overwritten. Generally not used by directives, only used by the parser.

Specified by:
setArg in interface DirectiveArgs
Throws:
BuildException

newSubdirective

public DirectiveArgs newSubdirective(int subdId)
                              throws BuildException
Create a new subdirective of the specified id and create an ArgsHolder for its arguments. Not used by directives.

Throws:
BuildException

subdirectiveOk

public boolean subdirectiveOk(int subdId)
                       throws BuildException
Check to see if the specified subdirective is OK at this point. The only reason it wouldn't be is because we've already got one and its not a repeating subdirective

Throws:
BuildException

getSubdirective

public ArgsHolder getSubdirective(int subdId)
                           throws BuildException
Retrieves the ArgsHolder for the associated subdirective so that the subdirective arguments can be retrieved. Only valid if the specified subdirective is not repeating.

Throws:
BuildException

getRepeatingSubdirective

public ArgsHolder[] getRepeatingSubdirective(int subdId)
                                      throws BuildException
Retrieves an array of ArgsHolders for the associated subdirective so that the subdirective arguments can be retrieved. Only valid if the specified subdirective is repeating.

Throws:
BuildException

build

public java.lang.Object build(BuildContext bc)
                       throws BuildException
Build the directive. Calls the build() method of the directive.

Specified by:
build in interface Builder
Throws:
BuildException

getName

public java.lang.String getName()
Get the name this directive was registered as