EDU.bmrb.starlibj
Class StarUnparser

java.lang.Object
  |
  +--EDU.bmrb.starlibj.StarUnparser

public class StarUnparser
extends java.lang.Object
implements java.lang.Cloneable

The inverse of class StarParse: This class will print out a star file (or subset thereof) into a previously opened output stream. Many of the output options can be manipulated with get... and set... functions.

This class is thread-safe if and only if each thread that uses it has its own separate instances of this class. (There are no static entities that step on each other in this class, so each instance of it is independant, but there are some dynamic entities that do get in each other's way if multiple threads try to run methods in the same object.)


Field Summary
protected  boolean formatting
           
protected  int indentSize
           
protected  java.io.PrintWriter oWrit
           
protected  int prevCheckLineNum
           
protected  SkipTextHandler skips
           
 
Constructor Summary
StarUnparser(java.io.OutputStream out)
          Constructor: Pass in an already-opened output stream and the output will end up there - buffered.
StarUnparser(java.io.OutputStream out, boolean autoFlush)
          Constructor: Pass in an already-opened output stream and the output will end up there - and choose the flushing flag.
StarUnparser(StarUnparser copyMe)
          copy constructor: copies an existing StarUnparser object:
 
Method Summary
 StarUnparser clone(StarUnparser copyMe)
          clone - needed so that this type can be stored inside the container classes in java.util.*.
protected  void finalize()
          Flush the output one last time before ending.
 boolean getFormatting()
          Gets the value of current formatting flag.
 int getIndentSize()
          Gets the number of characters to indent when printing.
protected  boolean isItNumeric(java.lang.String str)
           
 void setFormatting(boolean isOn)
          Turns off (or on) the formatting code for output.
 void setIndentSize(int s)
          Sets the number of characters to indent when printing.
protected  void writeBlockNode(BlockNode node, int indentLvl)
           
protected  void writeDataItemNode(DataItemNode node, int indentLvl, int longest)
           
protected  void writeDataLoopNameListNode(DataLoopNameListNode node, int indentLvl)
           
protected  void writeDataLoopNode(DataLoopNode node, int indentLvl)
           
protected  void writeDataNameNode(DataNameNode node, int indentLvl)
           
protected  void writeDataValueNode(DataValueNode node, int indentLvl, int preSize, int postSize)
           
protected  void writeIndent(int indentLvl)
           
protected  void writeLoopNameListNode(LoopNameListNode node, int indentLvl)
           
protected  void writeLoopRowNode(LoopRowNode node, int indentLvl, java.util.Vector preSizes, java.util.Vector postSizes)
           
protected  void writeLoopTableNode(LoopTableNode node, int indentLvl)
           
 void writeOut(StarNode node, int indentLvl)
          Writes out the StarNode-derived object given.
protected  void writeOut(StarNode node, int indentLvl, boolean internal)
           
protected  void writeOut(StarNode node, int indentLvl, int longest)
          Writes out the StarNode-derived object given.
protected  void writeOut(StarNode node, int indentLvl, int longest, boolean internal)
           
protected  void writePreComment(java.lang.String cmt, int indentLvl)
           
protected  void writeSaveFrameNode(SaveFrameNode node, int indentLvl)
           
 void writeSkipped(int thisLineNum)
          writeSkipped - writes out the skipped text that may exist between the last written thing and the current written thing:
protected  void writeStarFileNode(StarFileNode node, int indentLvl)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

indentSize

protected int indentSize

formatting

protected boolean formatting

oWrit

protected java.io.PrintWriter oWrit

skips

protected SkipTextHandler skips

prevCheckLineNum

protected int prevCheckLineNum
Constructor Detail

StarUnparser

public StarUnparser(java.io.OutputStream out)
Constructor: Pass in an already-opened output stream and the output will end up there - buffered. Output will appear without flushing each line.
Parameters:
out - The output stream to print on.

StarUnparser

public StarUnparser(java.io.OutputStream out,
                    boolean autoFlush)
Constructor: Pass in an already-opened output stream and the output will end up there - and choose the flushing flag.
Parameters:
out - The output stream to print on.
autoFlush - true = flush each line, false = don't flush output on each line. Setting it false is the default.

StarUnparser

public StarUnparser(StarUnparser copyMe)
copy constructor: copies an existing StarUnparser object:
Method Detail

finalize

protected void finalize()
Flush the output one last time before ending. DOES NOT CLOSE THE STREAM, since this class did not create the stream.
Overrides:
finalize in class java.lang.Object

clone

public StarUnparser clone(StarUnparser copyMe)
clone - needed so that this type can be stored inside the container classes in java.util.*. It mimics the functionality of a copy constructor, but with a different syntax.

writeSkipped

public void writeSkipped(int thisLineNum)
writeSkipped - writes out the skipped text that may exist between the last written thing and the current written thing:

writeOut

public void writeOut(StarNode node,
                     int indentLvl)
Writes out the StarNode-derived object given. pass a StarFileNode and it prints the whole file. Pass a single DataValueNode and it just prints that one value. The output can happen at any subset of the StarNode hierarchy.
Parameters:
node - The StarNode to print out.
indentLvl - The starting indent level to
longest - The longest string in the value. print at, typically zero. The number of characters indented will be = (indentLvl * getIndentSize()).
See Also:
setIndentSize()

writeOut

protected void writeOut(StarNode node,
                        int indentLvl,
                        int longest)
Writes out the StarNode-derived object given. pass a StarFileNode and it prints the whole file. Pass a single DataValueNode and it just prints that one value. The output can happen at any subset of the StarNode hierarchy.
Parameters:
node - The StarNode to print out.
indentLvl - The starting indent level to
longest - The longest string in the value. print at, typically zero. The number of characters indented will be = (indentLvl * getIndentSize()).
See Also:
setIndentSize()

writeOut

protected void writeOut(StarNode node,
                        int indentLvl,
                        boolean internal)

writeOut

protected void writeOut(StarNode node,
                        int indentLvl,
                        int longest,
                        boolean internal)

writeIndent

protected void writeIndent(int indentLvl)

writePreComment

protected void writePreComment(java.lang.String cmt,
                               int indentLvl)

writeDataValueNode

protected void writeDataValueNode(DataValueNode node,
                                  int indentLvl,
                                  int preSize,
                                  int postSize)

writeDataNameNode

protected void writeDataNameNode(DataNameNode node,
                                 int indentLvl)

writeDataItemNode

protected void writeDataItemNode(DataItemNode node,
                                 int indentLvl,
                                 int longest)

writeDataLoopNode

protected void writeDataLoopNode(DataLoopNode node,
                                 int indentLvl)

writeDataLoopNameListNode

protected void writeDataLoopNameListNode(DataLoopNameListNode node,
                                         int indentLvl)

writeLoopNameListNode

protected void writeLoopNameListNode(LoopNameListNode node,
                                     int indentLvl)

writeLoopTableNode

protected void writeLoopTableNode(LoopTableNode node,
                                  int indentLvl)

writeLoopRowNode

protected void writeLoopRowNode(LoopRowNode node,
                                int indentLvl,
                                java.util.Vector preSizes,
                                java.util.Vector postSizes)

writeSaveFrameNode

protected void writeSaveFrameNode(SaveFrameNode node,
                                  int indentLvl)

writeBlockNode

protected void writeBlockNode(BlockNode node,
                              int indentLvl)

writeStarFileNode

protected void writeStarFileNode(StarFileNode node,
                                 int indentLvl)

setIndentSize

public void setIndentSize(int s)
Sets the number of characters to indent when printing. Each time the output formatter needs to indent one more level, this is the number of spaces it will indent.

getIndentSize

public int getIndentSize()
Gets the number of characters to indent when printing. Each time the output formatter needs to indent one more level, this is the number of spaces it will indent.
Returns:
number of characters.

setFormatting

public void setFormatting(boolean isOn)
Turns off (or on) the formatting code for output. By default, the formatting is always on. The formatting can be turned off if the output does not need to be made 'pretty', and only needs to be syntactically correct. This is mostly useful when you are creating STAR syntax that you intend to be read by another computer program and you don't think a human's eyes will ever need to look at the output. Formatting slows down the output because multiple passes are required to count characters in values to make the values line up with each other. Turning the formatting off will speed up the output at the expense of human readability. Turning off formatting also condenses the whitespace down to the smallest it can be while still preserving syntax.

One example of a place where this could be useful is when two programs are communicating using STAR syntax over a pipe or socket.

Parameters:
isOn - true (default) == formatting is on, false == turn formatting off.

getFormatting

public boolean getFormatting()
Gets the value of current formatting flag.
Returns:
the formatting flag.
See Also:
setFormatting

isItNumeric

protected boolean isItNumeric(java.lang.String str)