org.writersforge.catalan.transform.xml
Class DirectiveStack

java.lang.Object
  extended byorg.writersforge.catalan.transform.xml.DirectiveStack

public class DirectiveStack
extends java.lang.Object

Format specification for placing Java Objects into a Datum tree.

Author:
jsheets

Nested Class Summary
static class DirectiveStack.Attribute
          A Directive to create a new attribute (Datum property) inside the current element.
static class DirectiveStack.Directive
          A single operation to perform on a node while creating a Bellows Datum tree from a list of nodes.
static class DirectiveStack.EndElement
          A Directive to close the current element.
static class DirectiveStack.Pcdata
          A Directive to insert PCDATA content into the current element.
static class DirectiveStack.Repeat
          A Directive to repeat an embedded stack of directives until a certain condition is met.
static class DirectiveStack.StartElement
          A Directive to start a new Datum element.
 
Constructor Summary
DirectiveStack()
          Creates a new instance of DirectiveStack.
DirectiveStack(int maxCycles, java.lang.Object untilNode)
          Creates a new instance of DirectiveStack with optional maximum iterations and an input node to trigger a premature bailout.
 
Method Summary
 void addDirective(DirectiveStack.Directive directive)
          Adds a formatting Directive to the end of the stack.
 DirectiveStack.Directive getNextDirective(java.lang.Object node)
          Retrieves the next Directive in the stack.
 boolean isFinished()
          Determines if the stack has reached the end of its run.
static DirectiveStack loadXmlStack(org.writersforge.bellows.Datum[] directives)
           Factory method for creating a stack from an XML document.
 void reset()
          Initializes the stack to its initial state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DirectiveStack

public DirectiveStack()
Creates a new instance of DirectiveStack.


DirectiveStack

public DirectiveStack(int maxCycles,
                      java.lang.Object untilNode)
Creates a new instance of DirectiveStack with optional maximum iterations and an input node to trigger a premature bailout. The DirectiveStack doesn't use these parameters, but does make them available to external code.

Parameters:
maxCycles - the maximum number of times the stack should be processed from start to finish
untilNode - the "bail out" node
Method Detail

addDirective

public void addDirective(DirectiveStack.Directive directive)
Adds a formatting Directive to the end of the stack.

Parameters:
directive - the next Directive to run in the stack

getNextDirective

public DirectiveStack.Directive getNextDirective(java.lang.Object node)
Retrieves the next Directive in the stack. When there are no more Directives, returns a null. If the stack contains any Repeat directives, this method will iterate through them as well.

Parameters:
node - the current node being processed; used to check for 'until-node' matches
Returns:
the next Directive in the stack, or null if stack is empty

isFinished

public boolean isFinished()
Determines if the stack has reached the end of its run. This happens when the stack reaches its maximum number of iterations, or if it hits the untilNode. When the stack is "finished", the method getNextDirective() will always return null. The reset() method returns the stack to a non-finished state.

Returns:
true if the stack is done processing nodes

reset

public void reset()
Initializes the stack to its initial state. Removes any saved state information acquired since creation or the last call to reset().


loadXmlStack

public static DirectiveStack loadXmlStack(org.writersforge.bellows.Datum[] directives)

Factory method for creating a stack from an XML document. Converts XML elements into Directive instances. The <repeat> element can contain other XML directives, which it will iterate through depending on its own parameters (if count is set, or the input data stream (if until-node is set). The XML directives map to Directive constructors like this:

<start-element/>
new DirectiveStack.StartElement()
<start-element name="static-name"/>
new DirectiveStack.StartElement("static-name")
<end-element/>
new DirectiveStack.EndElement()

<attribute/>
new DirectiveStack.Attribute(null, null)
<attribute name="static-name"/>
new DirectiveStack.Attribute("static-name", null)
<attribute value="static-value"/>
new DirectiveStack.Attribute(null, "static-value")
<attribute name="static-name" value="static-value"/>
new DirectiveStack.Attribute("static-name", "static-value")
<pcdata></pcdata>
new DirectiveStack.Pcdata(null)
<pcdata>PCDATA CONTENT</pcdata>
new DirectiveStack.Pcdata("PCDATA CONTENT")
<repeat>...</repeat>
new DirectiveStack.Repeat(new DirectiveStack(1, null))
<repeat count="5">...</repeat>
new DirectiveStack.Repeat(new DirectiveStack(5, null))
<repeat until-node="END">...</repeat>
new DirectiveStack.Repeat(new DirectiveStack(Integer.MAX_VALUE, "END"))

Parameters:
directives - an array of XML directives as described above
Returns:
an instance DirectiveStack corresponding to the XML directives