net.sf.japaki.text
Class PropertyParser<B,V>

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

public class PropertyParser<B,V>
extends AbstractParser<B>

Parses a Property of a generic bean. A factory can be defined to cover the case if either the property or its value is null.
The behaviour is as follows:

property property.
getValue()
factory parse result write result
not null not null not null value is used value is used
not null not null null value is used value is used
not null null not null factory is used to create value FormatException (from base parser)
not null null null NullPointerException FormatException (from base parser)
null N/A not null factory is used to create value factory is used to create value
null N/A null prohibited by factory methods


Constructor Summary
protected PropertyParser(Parser<? super V> parser, Property<B,V> property, Factory<? extends V> factory)
          Creates a new property parser based on the specified parameters.
 
Method Summary
static
<B,V> Parser<B>
newParser(Parser<? super V> parser, Property<B,V> property, Factory<? extends V> factory)
          Creates a new factory parser based on the specified parameters.
protected  void parseIt(ParseReader in, B target)
          Parses the next item from the input stream and stores the value in the corresponding property of the target bean.
 String treeView()
          Returns a tree view of this parser.
protected  void writeIt(ParseWriter out, B source)
          Reads the property value from the specified bean and formats it with the underlying parser.
 
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

PropertyParser

protected PropertyParser(Parser<? super V> parser,
                         Property<B,V> property,
                         Factory<? extends V> factory)
Creates a new property parser based on the specified parameters. If property is null, the factory is used to create the output value for writing.

Parameters:
parser - base parser
property - specifies what element to read or write to in the source or target bean, respectively
factory - used to create a new bean if it does not exist yet
Throws:
NullPointerException - if parser or both property and factory are null
Method Detail

newParser

public static <B,V> Parser<B> newParser(Parser<? super V> parser,
                                        Property<B,V> property,
                                        Factory<? extends V> factory)
Creates a new factory parser based on the specified parameters. If property is null, the factory is used to create the output value for writing.

Parameters:
parser - base parser
property - specifies what element to read or write to in the source or target bean, respectively
factory - used to create a new bean if it does not exist yet
Throws:
NullPointerException - if parser or both property and factory are null

parseIt

protected void parseIt(ParseReader in,
                       B target)
                throws IOException,
                       ParseException
Parses the next item from the input stream and stores the value in the corresponding property of the target bean.

Specified by:
parseIt in class AbstractParser<B>
Parameters:
target - target bean
in - the position where to start parsing
Throws:
NullPointerException - if the underlying factory and the property's value are both null
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
Reads the property value from the specified bean and formats it with the underlying parser. If either the property or its value is null, the factory is used to create a value.

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