OpMath

com.opmath.util.dmldoc
Class DMLDocText

java.lang.Object
  |
  +--com.opmath.util.dmldoc.DMLDocText

class DMLDocText
extends Object

An object representing one component of a Document Object Model (DOM).

DMLDocText represents the objects which make up a DMLDocBlock. Details of this class are only of relevance to developers wishing to extend the dmldoc classes.

A DMLDocBlock holds the root of a linked list of DMLDocTexts. One DMLDocText contains some text, at the end of which is a SUB target or a child DMLDocBlock (the child represents a LOOP or IF / IFNOT / IFDATAFOR / IFNODATAFOR block.

Copyright: (c) 2002 The Open Math Company Limited

The Terms of Distribution of this software are stipulated in the javadoc Overview for this project.

Since:
J2SE 1.3
Version:
utilities-v011
Author:
Bruno Beloff bruno.beloff@opmath.com
See Also:
DMLDoc, DMLDocBlock

Field Summary
protected static int MODE_EMPTY
          Returned by subBlockMode().
protected static int MODE_IF
          Returned by subBlockMode().
protected static int MODE_IFDATA
          Returned by subBlockMode().
protected static int MODE_IFNODATA
          Returned by subBlockMode().
protected static int MODE_IFNOT
          Returned by subBlockMode().
protected static int MODE_LOOP
          Returned by subBlockMode().
 
Constructor Summary
DMLDocText()
          Constructs a new DMLDocText node.
 
Method Summary
protected  DMLDocText addDMLDocText()
          Adds a new DMLDocText following this DMLDocText.
protected  void addText(String newText)
          Appends some text to the text held by this DMLDocText.
protected  int maxColumnSize(ComparableTable display)
          Returns the size of the longest column in the ComparableTable, for all of the SUB and IF / IFNOT / IFDATAFOR / IFNODATAFOR sources known to this DMLDocText.
protected  void newIf(BufferedReader inputText, DMLDocBlock parent, String ifToken, boolean positive, ParseCounter countLOOP, ParseCounter countIF)
          Creates an IF / IFNOT / IFDATAFOR / IFNODATAFOR element for this DMLDocText.
protected  void newIfData(BufferedReader inputText, DMLDocBlock parent, String ifToken, boolean positive, ParseCounter countLOOP, ParseCounter countIF)
           
protected  void newLoop(BufferedReader inputText, DMLDocBlock parent, ParseCounter countLOOP, ParseCounter countIF)
          Creates a DMLDocBlock LOOP element for this DMLDocText.
protected  void newSource(String subString)
          Adds the SUB source to this DMLDocText.
protected  DMLDocText next()
          Returns the DMLDocText node chained to the end of this one.
protected  DMLDocBlock subBlock()
          Returns the DMLDocBlock introduced by this DMLDocText.
protected  int subBlockMode()
          Returns an int code indicating whether this DMLDocText introduces a DMLDocBlock.
protected  String subValue(ComparableTable display, Comparable columnKey, int loopIndex)
          Returns a substitution value for the given Vector of data values and index i.
protected  String text()
          Returns the text component of this DMLDocText.
 String toString()
          Returns a string representaion of the DMLDocText instance.
protected  String view(ComparableTable display, int i)
          Returns a string representaion of this DMLDocText instance, with the various SUBs, LOOPs and IF / IFNOT / IFDATAFOR / IFNODATAFOR elements processed, as determined by the ComparableTable and the loop index i.
protected  ComparableList viewNames(ComparableList sourceList)
          Fills a com.opmath.util.datastruct.ComparableList with the substitution source names known to this DMLDocText.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MODE_EMPTY

protected static final int MODE_EMPTY

Returned by subBlockMode().

See Also:
subBlockMode()
Since:
J2SE 1.3

MODE_LOOP

protected static final int MODE_LOOP

Returned by subBlockMode().

See Also:
subBlockMode()
Since:
J2SE 1.3

MODE_IF

protected static final int MODE_IF

Returned by subBlockMode().

See Also:
subBlockMode()
Since:
J2SE 1.3

MODE_IFNOT

protected static final int MODE_IFNOT

Returned by subBlockMode().

See Also:
subBlockMode()
Since:
J2SE 1.3

MODE_IFDATA

protected static final int MODE_IFDATA

Returned by subBlockMode().

See Also:
subBlockMode()
Since:
J2SE 1.3

MODE_IFNODATA

protected static final int MODE_IFNODATA

Returned by subBlockMode().

See Also:
subBlockMode()
Since:
J2SE 1.3
Constructor Detail

DMLDocText

public DMLDocText()

Constructs a new DMLDocText node. The contents of the node will be instantiated later.

Since:
J2SE 1.3
Method Detail

next

protected DMLDocText next()

Returns the DMLDocText node chained to the end of this one. If there are no more DMLDocTexts, then next() returns null.

Returns:
a com.opmath.util.dmldoc.DMLDocText or null.
Since:
J2SE 1.3

subBlock

protected DMLDocBlock subBlock()

Returns the DMLDocBlock introduced by this DMLDocText. If no DMLDocBlock exists, then subBlock() returns null.

Returns:
a com.opmath.util.dmldoc.DMLDocText or null.
Since:
J2SE 1.3

subBlockMode

protected int subBlockMode()

Returns an int code indicating whether this DMLDocText introduces a DMLDocBlock. The code can be one of:

Returns:
an int.
Since:
J2SE 1.3

text

protected String text()

Returns the text component of this DMLDocText.

Returns:
a String
Since:
J2SE 1.3

viewNames

protected ComparableList viewNames(ComparableList sourceList)

Fills a com.opmath.util.datastruct.ComparableList with the substitution source names known to this DMLDocText. If no sources are known, viewNames(com.opmath.util.datastruct.ComparableList) does not alter the com.opmath.util.datastruct.ComparableList.

Parameters:
sourceList - the com.opmath.util.datastruct.ComparableList holding the source names.
Returns:
the same (updated) com.opmath.util.datastruct.ComparableList.
Since:
J2SE 1.3
See Also:
DMLDocBlock.viewNames(), DMLDocBlock.viewNames(com.opmath.util.datastruct.ComparableList)

addDMLDocText

protected DMLDocText addDMLDocText()

Adds a new DMLDocText following this DMLDocText. Always returns the new DMLDocText.

Returns:
a new com.opmath.util.dmldoc.DMLDocText
Since:
J2SE 1.3

newSource

protected void newSource(String subString)

Adds the SUB source to this DMLDocText.

NOTE: Given that a DMLDocText has at most only one SUB target, it also has only one SUB source. Performing newSource(String) more than once on the same instance is therefore of doubtful value, but is legal.

Parameters:
subString - the String naming this SUB source.
Since:
J2SE 1.3

addText

protected void addText(String newText)

Appends some text to the text held by this DMLDocText.

Parameters:
newText - the String carrying the text.
Since:
J2SE 1.3

newLoop

protected void newLoop(BufferedReader inputText,
                       DMLDocBlock parent,
                       ParseCounter countLOOP,
                       ParseCounter countIF)
                throws DMLDocBuildException

Creates a DMLDocBlock LOOP element for this DMLDocText. The LOOP element begins with text inputText and has the parent DMLDocBlock parent.

The arguments countLOOP and countIF can be used to validate the number of LOOP versus ENDLOOP, and IF / IFNOT / IFDATAFOR / IFNODATAFOR versus ENDIF instructions encountered in the template source - these counters should both be zero on exit from the DMLDocBlock building operation.

Parameters:
inputText - the BufferedReader carrying the template source.
parent - the DMLDocBlock parent of this node.
countLOOP - the ParseCounter for LOOP commands.
countIF - the ParseCounter for IF / IFNOT / IFDATAFOR / IFNODATAFOR commands.
Throws:
DMLDocBuildException - An exception thrown if inputText contained malformed commands.
Since:
J2SE 1.3

newIf

protected void newIf(BufferedReader inputText,
                     DMLDocBlock parent,
                     String ifToken,
                     boolean positive,
                     ParseCounter countLOOP,
                     ParseCounter countIF)
              throws DMLDocBuildException

Creates an IF / IFNOT / IFDATAFOR / IFNODATAFOR element for this DMLDocText. Its DMLDocBlock begins with text inputText and has the parent DMLDocBlock parent.

The argument ifToken is the source agument of the IF / IFNOT / IFDATAFOR / IFNODATAFOR instruction. Theargument positive is true for IF and IFDATAFOR, false for IFNOT and IFNODATAFOR. The ParseCounter arguments are equivalent to those for newLoop(BufferedReader, DMLDocBlock, ParseCounter, ParseCounter).

Parameters:
inputText - the BufferedReader carrying the template source.
parent - the DMLDocBlock parent of this node.
ifToken - the String naming the IF / IFNOT / IFDATAFOR / IFNODATAFOR determiner.
positive - the boolean for determiner sense.
countLOOP - the ParseCounter for LOOP commands.
countIF - the ParseCounter for IF/ IFNOT commands.
Throws:
DMLDocBuildException - An exception thrown if inputText contained malformed commands.
Since:
J2SE 1.3
See Also:
newLoop(BufferedReader, DMLDocBlock, ParseCounter, ParseCounter)

newIfData

protected void newIfData(BufferedReader inputText,
                         DMLDocBlock parent,
                         String ifToken,
                         boolean positive,
                         ParseCounter countLOOP,
                         ParseCounter countIF)
                  throws DMLDocBuildException

maxColumnSize

protected int maxColumnSize(ComparableTable display)
                     throws DMLDocWriteException

Returns the size of the longest column in the ComparableTable, for all of the SUB and IF / IFNOT / IFDATAFOR / IFNODATAFOR sources known to this DMLDocText.

Note the plural substitution sources! Each DMLDocText has at most one substitution source, and at most one IF / IFNOT / IFDATAFOR / IFNODATAFOR source. But maxColumnSize(ComparableTable) returns the size of the longest column known to this DMLDocText and those chained to it using addDMLDocText().

maxColumnSize(ComparableTable)checks the IF source, if present, but does not need to descend into the IF's DMLDocBlock node.

Parameters:
display - the ComparableTable carrying the data set.
Returns:
an int
Throws:
DMLDocWriteException - An exception thrown if a SUB or IF / IFNOT / IFDATAFOR / IFNODATAFOR source was not found in the ComparableTable.
Since:
J2SE 1.3
See Also:
addDMLDocText()

subValue

protected String subValue(ComparableTable display,
                          Comparable columnKey,
                          int loopIndex)
                   throws DMLDocWriteException

Returns a substitution value for the given Vector of data values and index i.

subValue(com.opmath.util.datastruct.ComparableList, int) embodies a number of important rules which define the instatiation bahaviour of DMLDocBlock:

NOTE: Although subValue(com.opmath.util.datastruct.ComparableList, int) is formally able to throw a com.opmath.util.dmldoc.DMLDocWriteException, this will not happen under normal operations.

Parameters:
column - the ComparableTable carrying the data column.
i - the int index into the column.
Returns:
a new String
Throws:
DMLDocWriteException - Reserved.
Since:
J2SE 1.3

view

protected String view(ComparableTable display,
                      int i)
               throws DMLDocWriteException

Returns a string representaion of this DMLDocText instance, with the various SUBs, LOOPs and IF / IFNOT / IFDATAFOR / IFNODATAFOR elements processed, as determined by the ComparableTable and the loop index i.

Parameters:
display - the ComparableTable carrying the data set.
i - the int index into the column.
Returns:
a new String
Throws:
DMLDocWriteException - An exception thrown if the ComparableTable does not match the DMLDocText.
Since:
JDK 1.0
See Also:
toString()

toString

public String toString()

Returns a string representaion of the DMLDocText instance. No instantiation is performed, but the structure of the DMLDocText instance is revealed.

NOTE: Intended to be used for debugging tasks only. The format of the output may change from one release of dmldoc to the next.

Overrides:
toString in class Object
Returns:
a new String
Since:
JDK 1.0
See Also:
view(com.opmath.util.datastruct.ComparableTable, int)

OpMath

Submit a bug or feature to Open Math
Copyright © 2002 Open Math Company Limited, Brighton, UK