unit
Class UniT

unit.UniT

public final class UniT

This class provides some methods to easily interprete (parse and execute) UniT templates.

If a UniT template should be interpreted only once (in the default encoding), exceptions should not be caught and the result should be directed to standard out/the console, call the method interprete(String fileName).

If all occuring exceptions should be caught additionally and appropriate error messages should be directed to standard error/the console, call the method interpreteAndHandleExceptions(String fileName).

If a UniT template should be interpreted multiple times, hold the Interpreter object, that will be returned and call its run method multiple times, even in multiple threads.

An alternative to immediately executing a template is: calling parseUniT(String fileName). The template will be parsed but not executed! An object of the class Interpreter will be returned, that represents the parse tree and that can be executed at any time multiple times (with the method run), even in multiple threads.

If parameters should be passed to a UniT template, a Hashtable must be passed to the run method of the Interpreter object. That Hashtable must contain the name and value of the parameters. The name of each parameter or key of each Hashtable element respectively, must be a valid Java identifier, that can be accessed in UniT source code. The identifier named "out" may only be a Writer object.

If a UniT template should be directly executed from the command line ("java unit.UniT fileName"), the main method will be used. The output will be directed to standard output/the console, exceptions will be caught and error messages will be directed to standard error/the console. Additionally the arguments array will be passed to the template as identifier "arguments".

See Also:
Interpreter

Constructor Summary
UniT()
           
 
Method Summary
static Interpreter interprete(java.lang.String fileName)
          Parses and executes a UniT template, the resulting output will be send to System.out.
static Interpreter interprete(java.lang.String fileName, java.util.Hashtable identifiers, java.io.Writer out)
          Parses and executes a UniT template, the resulting output will be send to the out Writer object.
static Interpreter interpreteAndHandleExceptions(java.lang.String fileName)
          Parses and executes a UniT template.
static Interpreter interpreteAndHandleExceptions(java.lang.String fileName, java.util.Hashtable identifiers, java.io.Writer out, java.io.Writer error)
          Parses and executes a UniT template.
static void main(java.lang.String[] arguments)
          Interpretes (parses and executes) a UniT template given as first parameter at the command line, catches all exceptions and directs standard and error output to the console.
static Interpreter parseUniT(java.io.Reader in, java.lang.String nameOfInput)
          Parses a UniT template from a character stream.
static Interpreter parseUniTFile(java.lang.String fileName)
          Parses a UniT template with the specified file name and the default encoding.
 

Constructor Detail

UniT

public UniT()
Method Detail

main

public static void main(java.lang.String[] arguments)
Interpretes (parses and executes) a UniT template given as first parameter at the command line, catches all exceptions and directs standard and error output to the console. All command line arguments will be passed on to the template by the identifier "arguments".
Parameters:
arguments - all arguments of the command line

interpreteAndHandleExceptions

public static Interpreter interpreteAndHandleExceptions(java.lang.String fileName)
Parses and executes a UniT template. The resulting output will be send to System.out. All Exceptions will be catched and appropriate messages will be send to System.err.
Parameters:
fileName - the file name of the template, that should be executed.
See Also:
Interpreter.run(Hashtable)

interpreteAndHandleExceptions

public static Interpreter interpreteAndHandleExceptions(java.lang.String fileName,
                                                        java.util.Hashtable identifiers,
                                                        java.io.Writer out,
                                                        java.io.Writer error)
Parses and executes a UniT template. The resulting output will be send to the out Writer object. If it is null, System.out will be used. All Exceptions will be catched and appropriate messages will be send to the error Writer object. If it is null, System.err will be used.
Parameters:
fileName - the file name of the template, that should be executed.
identifiers - that should be passed to the template. That Hashtable must contain the name and value of the parameters. The name of each parameter or key of each Hashtable element respectively, must be a valid Java identifier, that can be accessed in UniT source code.
out - the target of the result output
error - the target of error messages
See Also:
Interpreter.run(Hashtable)

interprete

public static Interpreter interprete(java.lang.String fileName)
                              throws java.io.FileNotFoundException,
                                     unit.RecognitionException,
                                     unit.TokenStreamException
Parses and executes a UniT template, the resulting output will be send to System.out.
Parameters:
fileName - the file name of the template, that should be executed.
See Also:
Interpreter.run(Hashtable)

interprete

public static Interpreter interprete(java.lang.String fileName,
                                     java.util.Hashtable identifiers,
                                     java.io.Writer out)
                              throws java.io.FileNotFoundException,
                                     unit.RecognitionException,
                                     unit.TokenStreamException
Parses and executes a UniT template, the resulting output will be send to the out Writer object. If it is null, System.out will be used.
Parameters:
fileName - the file name of the template, that should be executed.
identifiers - that should be passed to the template. That Hashtable must contain the name and value of the parameters. The name of each parameter or key of each Hashtable element respectively, must be a valid Java identifier, that can be accessed in UniT source code.
out - the target of the result output
See Also:
Interpreter.run(Hashtable)

parseUniTFile

public static Interpreter parseUniTFile(java.lang.String fileName)
                                 throws java.io.FileNotFoundException,
                                        unit.RecognitionException,
                                        unit.TokenStreamException
Parses a UniT template with the specified file name and the default encoding. Calls the method parseUniT. If another encoding than default is required, the method parseUniT must be used directly and a Reader object must be passed as first argument.
Parameters:
fileName - the file name of the UniT template, that should be parsed.
See Also:
Interpreter.run(Hashtable)

parseUniT

public static Interpreter parseUniT(java.io.Reader in,
                                    java.lang.String nameOfInput)
                             throws unit.TokenStreamException,
                                    unit.RecognitionException
Parses a UniT template from a character stream. This method allows escaping from the default encoding.
Parameters:
in - the Reader object that contains the UniT template with the correct encoding.
nameOfInput - the name of the UniT template, that should be parsed. This name will be used when refering errors within the template.
See Also:
Interpreter.run(Hashtable)