au.gov.tas.dpiwe.mr.tool
Class ClosedSourceFileWriter

java.lang.Object
  extended by java.io.Writer
      extended by java.io.PrintWriter
          extended by au.gov.tas.dpiwe.mr.tool.ClosedSourceFileWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class ClosedSourceFileWriter
extends PrintWriter

ClosedSourceFileWriter takes a close source file, a set of global parameters, and a list of per key local parameters and produces a source file.

This class is used in the bean deployment process and for a number of other tools, and is a general approach to producing source files from templates.

Since:
Mr Architecture 1.0
Version:
1.0.1.2
Author:
Kade Hansson

Field Summary
protected  ListIterator abstractKeyParameterMapPairsIterator
          An iterator over the per key local parameters
protected  ResourceBundle closeSource
          The close source is a properties file decoded as a ResourceBundle.
protected  Object[] concreteKeyParameters
          The set of global parameters.
protected  int indentLevel
          The current indent level in the output source file.
protected  MutableBoolean inSlashStar
          Indicates whether a slash-star comment is open.
protected  boolean statementIndentationOnThisBlock
          Indicates whether this block is further indented because of an unclosed statement.
 
Fields inherited from class java.io.PrintWriter
out
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
ClosedSourceFileWriter(InputStream closeSourceStream, Writer writer, Object[] concreteKeyParameters, List abstractKeyParameterMapPairs)
          Construct a new closed source file writer.
 
Method Summary
protected  void writeAbstractSequence(StringTokenizer sequence)
          Writes the evaluation of an abstract key sequence.
 void writeClosedSourceFile()
          Output the evaluation of the SourceFile abstract key to the output source file.
protected  void writeCompoundConcreteKey(String key)
          Writes a compound concrete key, which is indicated in an abstract key with a key name followed by an asterisk.
protected  void writeCompoundConcreteKeyWithRepeatedKeys(String key)
          Writes a compound concrete key with repeated keys, which is indicated in an abstract key with a key name enclosed in curly braces followed by an asterisk.
protected  void writeConcreteSequence(String line)
          Writes the evaluation of a concrete key sequence.
protected  void writeKey(String key)
          Writes the evaluation of a concrete or abstract key with the given name.
protected  void writeOptionalSection(StringTokenizer section, String initialToken)
          Writes a section bounded by box brackets either once, if there is an abstract key name matching that of the optional section in the abstract key parameter pairs, or not at all.
protected  void writeRepeatedSection(StringTokenizer section, String initialToken)
          Writes a section bounded by curly braces as many times as there are abstract key names matching those of the repeated section in the abstract key parameter pairs.
protected  void writeSelectionSection(StringTokenizer section, String initialToken)
          Writes a selected part of a section bounded by parentheses delimited by vertical bars based on the next abstract key name in the abstract key parameter pairs.
 
Methods inherited from class java.io.PrintWriter
append, append, append, append, append, append, append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

closeSource

protected ResourceBundle closeSource
The close source is a properties file decoded as a ResourceBundle.


abstractKeyParameterMapPairsIterator

protected ListIterator abstractKeyParameterMapPairsIterator
An iterator over the per key local parameters


concreteKeyParameters

protected Object[] concreteKeyParameters
The set of global parameters.


indentLevel

protected int indentLevel
The current indent level in the output source file.


statementIndentationOnThisBlock

protected boolean statementIndentationOnThisBlock
Indicates whether this block is further indented because of an unclosed statement.


inSlashStar

protected MutableBoolean inSlashStar
Indicates whether a slash-star comment is open.

Constructor Detail

ClosedSourceFileWriter

public ClosedSourceFileWriter(InputStream closeSourceStream,
                              Writer writer,
                              Object[] concreteKeyParameters,
                              List abstractKeyParameterMapPairs)
                       throws IOException
Construct a new closed source file writer.

Parameters:
closeSourceStream - the close source file stream.
writer - the concrete source file writer.
concreteKeyParameters - the set of global parameters, which should be an array big enough to accomodate local parameter indicies.
abstractKeyParameterPairs - a list of (<key-name>, (<local-parameter-number>, <value-or-collection>)) pairs. entries for the global parameters per key.
Throws:
IOException
Method Detail

writeClosedSourceFile

public void writeClosedSourceFile()
Output the evaluation of the SourceFile abstract key to the output source file.


writeKey

protected void writeKey(String key)
Writes the evaluation of a concrete or abstract key with the given name.

Parameters:
key - the key name.

writeAbstractSequence

protected void writeAbstractSequence(StringTokenizer sequence)
Writes the evaluation of an abstract key sequence.

Parameters:
sequence - the sequence of key names and EBNF delimiters.

writeRepeatedSection

protected void writeRepeatedSection(StringTokenizer section,
                                    String initialToken)
Writes a section bounded by curly braces as many times as there are abstract key names matching those of the repeated section in the abstract key parameter pairs.

Parameters:
section - the section of a sequence to be repeated.
initialToken - the key name of the first item in the section.

writeOptionalSection

protected void writeOptionalSection(StringTokenizer section,
                                    String initialToken)
Writes a section bounded by box brackets either once, if there is an abstract key name matching that of the optional section in the abstract key parameter pairs, or not at all.

Parameters:
section - the optional section of a sequence.
initialToken - the key name of the first item in the section.

writeSelectionSection

protected void writeSelectionSection(StringTokenizer section,
                                     String initialToken)
Writes a selected part of a section bounded by parentheses delimited by vertical bars based on the next abstract key name in the abstract key parameter pairs.

Parameters:
section - a selection section in a sequence.
initialToken - the key name of the first item in the section.

writeCompoundConcreteKey

protected void writeCompoundConcreteKey(String key)
Writes a compound concrete key, which is indicated in an abstract key with a key name followed by an asterisk. This is evaluated as a sequence of key expansions resulting from multiple concrete keys, each ending with a different consecutive letter of the alphabet starting at 'A'. When the alphabet is exhausted, a prefix is recursively applied as necessary. e.g. the sequence is 'A'-'Z', "AA"-"AZ", "BA"-"ZZ", "AAA"-"ZZZ", etc.

Each concrete key expansion appears only once.

Parameters:
key - the key name (no trailing asterisk).

writeCompoundConcreteKeyWithRepeatedKeys

protected void writeCompoundConcreteKeyWithRepeatedKeys(String key)
Writes a compound concrete key with repeated keys, which is indicated in an abstract key with a key name enclosed in curly braces followed by an asterisk. This is evaluated as a sequence of key expansions resulting from multiple concrete keys, each ending with a different consecutive letter of the alphabet starting at 'A'. When the alphabet is exhausted, a prefix is recursively applied as necessary. e.g. the sequence is 'A'-'Z', "AA"-"AZ", "BA"-"ZZ", "AAA"-"ZZZ", etc.

Each concrete key expansion whose referenced parameters are collection-valued in the current combination of local and global parameter value pairs may appear more than once or not at all depending on the number of entries in the collection. All other concrete key expansions appear just once.

Parameters:
key - the key name (no trailing asterisk, not bounded by curly braces).

writeConcreteSequence

protected void writeConcreteSequence(String line)
Writes the evaluation of a concrete key sequence.

Parameters:
line - a source file line containing parameter indicies in curly braces which will be expanded.