net.sf.japaki.text
Class ChoiceParser<T>

java.lang.Object
  extended by net.sf.japaki.text.AbstractParser<T>
      extended by net.sf.japaki.text.ChoiceParser<T>
All Implemented Interfaces:
Parser<T>

public class ChoiceParser<T>
extends AbstractParser<T>

A choice parser selects the right parser out of a list of underlying parser depending on the input text for parsing or based on the source object for formatting.


Constructor Summary
protected ChoiceParser(List<Parser<? super T>> parsers)
          Creates a new choice parser based on the specified parsers.
 
Method Summary
static
<T> Parser<T>
newParser(List<Parser<? super T>> parsers)
          Creates a new choice parser based on the specified parsers.
protected  void parseIt(ParseReader in, T target)
          Tries to parse the input text with one of the base parsers.
 String treeView()
          Returns a tree view of this parser.
protected  void writeIt(ParseWriter out, T source)
          Tries to parse the source object with one of the base parsers.
 
Methods inherited from class net.sf.japaki.text.AbstractParser
getLogger, handleException, parse, toString, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChoiceParser

protected ChoiceParser(List<Parser<? super T>> parsers)
Creates a new choice parser based on the specified parsers.

Parameters:
parsers - base parsers
Throws:
NullPointerException - if parsers or one of its elements is null
Method Detail

newParser

public static <T> Parser<T> newParser(List<Parser<? super T>> parsers)
Creates a new choice parser based on the specified parsers.

Parameters:
parsers - base parsers
Throws:
NullPointerException - if parsers is null

parseIt

protected void parseIt(ParseReader in,
                       T target)
                throws IOException,
                       ParseException
Tries to parse the input text with one of the base parsers. The first succesful parser is used.

Specified by:
parseIt in class AbstractParser<T>
Parameters:
in - the position where to start parsing
target - place where the parsed object is stored.
Throws:
NullPointerException - if in or target or one of its (sub-) properties is null and the parser cannot handle it
ParseException - if no parser matches.
IOException - if an I/O error occurs

writeIt

protected void writeIt(ParseWriter out,
                       T source)
                throws IOException,
                       FormatException
Tries to parse the source object with one of the base parsers. The first successful parser is used.

Specified by:
writeIt in class AbstractParser<T>
Parameters:
out - the stream and position where to put the formatted text.
source - source object
Throws:
FormatException - if no parser matches. The cause is a MultiCauseException containg the fail reason of each option parser.
NullPointerException - if out is null
IOException - if an I/O error occurs

treeView

public String treeView()
Description copied from interface: Parser
Returns a tree view of this parser.

Returns:
a tree view of this parser