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

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

public class LeafParser<B>
extends AbstractParser<B>

A parser based on a Format.


Constructor Summary
protected LeafParser(Format format, Property<B,?> property, String errorMessage, String name)
          Creates a new leaf parser from the specified parameters.
 
Method Summary
static Parser<Object> newConstantParser(String value)
          Creates a parser that always returns a predefined value.
static
<B> Parser<B>
newMessageParser(List<Property<? super B,?>> properties, String pattern, String name)
          Creates a parser based on a MessageFormat.
static
<B> Parser<B>
newParser(Format format, Property<B,?> property, String errorMessage, String name)
          Creates a new leaf parser from the specified parameters.
static
<B> Parser<B>
newStringParser(Property<B,String> property, String delimiter, String name)
          Creates a new delimiter based parser.
protected  void parseIt(ParseReader in, B target)
          Parses text starting at the specified position.
 String treeView()
          Returns a tree view of this parser.
protected  void writeIt(ParseWriter out, B source)
          Formats the source object and writes it into the output stream
 
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

LeafParser

protected LeafParser(Format format,
                     Property<B,?> property,
                     String errorMessage,
                     String name)
Creates a new leaf parser from the specified parameters.

Parameters:
format - base format
property - the rule how to retrieve and store the value for parsing and formatting, respectively.
errorMessage - message set in the exception if parsing fails
name - name of this parser for logging purposes
Throws:
NullPointerException - if any parameter is null
Method Detail

newParser

public static <B> Parser<B> newParser(Format format,
                                      Property<B,?> property,
                                      String errorMessage,
                                      String name)
Creates a new leaf parser from the specified parameters.

Parameters:
format - base format
property - the rule how to retrieve and store the value for parsing and formatting, respectively.
errorMessage - message set in the exception if parsing fails
name - name of this parser for logging purposes
Returns:
the created parser
Throws:
NullPointerException - if any parameter is null

newConstantParser

public static Parser<Object> newConstantParser(String value)
Creates a parser that always returns a predefined value.

Parameters:
value - constant to be used
Returns:
the created parser
Throws:
NullPointerException - if value is null

newStringParser

public static <B> Parser<B> newStringParser(Property<B,String> property,
                                            String delimiter,
                                            String name)
Creates a new delimiter based parser.

Parameters:
property - the rule how to retrieve and store the value for parsing and formatting, respectively.
delimiter - the string where parsing stops
name - name of this parser for logging purposes
Returns:
the created parser
Throws:
NullPointerException - if any parameter is null

newMessageParser

public static <B> Parser<B> newMessageParser(List<Property<? super B,?>> properties,
                                             String pattern,
                                             String name)
Creates a parser based on a MessageFormat.

Parameters:
properties - the rules how to retrieve and store the values for parsing and formatting, respectively.
pattern - the pattern of the message format
name - name of this parser for logging purposes
Returns:
the created parser
Throws:
IllegalArgumentException - if the pattern is invalid
NullPointerException - if properties or name is null

parseIt

protected void parseIt(ParseReader in,
                       B target)
                throws IOException,
                       ParseException
Description copied from class: AbstractParser
Parses text starting at the specified position.

Specified by:
parseIt in class AbstractParser<B>
Parameters:
in - the position where to start parsing
target - place where the parsed object is stored.
Throws:
NullPointerException - if in or target is 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
Description copied from class: AbstractParser
Formats the source object and writes it into the output stream

Specified by:
writeIt in class AbstractParser<B>
Parameters:
out - the stream and position where to put the formatted text.
source - source object
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