net.sf.japaki.text
Class BeanParser<B>

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

public class BeanParser<B>
extends AbstractParser<B>

A parser for a bean. For every relevant property a parser must be specified, the sequence of properties is defined by the sequence of parsers.
It can also be used for any sequence of parsers of the same type.


Constructor Summary
protected BeanParser(List<Parser<? super B>> parsers, String name)
          Creates a new bean parser based on the specified parsers.
 
Method Summary
static
<B> Parser<B>
newParser(List<Parser<? super B>> parsers, String name)
          Creates a new bean parser based on the specified parsers.
static
<B> Parser<B>
newParser(List<Parser<? super B>> parsers, String name, Parser<? super B> delimiterParser)
          Creates a new bean parser based on the specified parsers.
protected  void parseIt(ParseReader in, B target)
          Uses the underlying parsers to parse the input stream and stores the values in the target bean.
 String treeView()
          Returns a tree view of this parser.
protected  void writeIt(ParseWriter out, B source)
          Formats the bean using the underlying 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

BeanParser

protected BeanParser(List<Parser<? super B>> parsers,
                     String name)
Creates a new bean parser based on the specified parsers.

Parameters:
parsers - property parsers
name - name of this parser for logging purposes
Throws:
NullPointerException - if parsers or name is null
Method Detail

newParser

public static <B> Parser<B> newParser(List<Parser<? super B>> parsers,
                                      String name)
Creates a new bean parser based on the specified parsers.

Parameters:
parsers - property parsers
name - name of this parser for logging purposes
Throws:
NullPointerException - if parsers or name is null

newParser

public static <B> Parser<B> newParser(List<Parser<? super B>> parsers,
                                      String name,
                                      Parser<? super B> delimiterParser)
Creates a new bean parser based on the specified parsers.

Parameters:
parsers - property parsers
name - name of this parser for logging purposes
delimiterParser - parser for tokens between elements
Throws:
NullPointerException - if parsers or name is null

parseIt

protected void parseIt(ParseReader in,
                       B target)
                throws IOException,
                       ParseException
Uses the underlying parsers to parse the input stream and stores the values in the target bean.

Specified by:
parseIt in class AbstractParser<B>
Parameters:
target - target bean
in - the position where to start parsing
Throws:
NullPointerException - if in or target or one of its (sub-) properties is null and the parser cannot handle it
BeanStoreException - if the parsed value could not be stored
IOException - if an I/O error occurs
ParseException - if the beginning of the string in in cannot be parsed

writeIt

protected void writeIt(ParseWriter out,
                       B source)
                throws IOException,
                       FormatException
Formats the bean using the underlying parsers.

Specified by:
writeIt in class AbstractParser<B>
Parameters:
source - source bean
out - the stream and position where to put the formatted text.
Throws:
NullPointerException - if out is null
IOException - if an I/O error occurs
FormatException - if the source object can not be formatted with this parser.

treeView

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

Returns:
a tree view of this parser