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

java.lang.Object
  extended by net.sf.japaki.text.AbstractParser<T>
All Implemented Interfaces:
Parser<T>
Direct Known Subclasses:
BeanParser, ChoiceParser, CollectionParser, LeafParser, LineFeed, MapParser, OptionalParser, PeekParser, PropertyParser

public abstract class AbstractParser<T>
extends Object
implements Parser<T>

Parser skeleton that creates a path of the traversed parsers for logging purposes.
Instead of parse and write, parseIt and writeIt must be implemented.


Constructor Summary
protected AbstractParser(String name)
          Creates a new abstract parser.
 
Method Summary
protected  Logger getLogger()
           
protected static
<B,V> void
handleException(RuntimeException e, Property<B,V> property, B bean, V value)
          Handles exceptions that are thrown during a setValue operation.
 void parse(ParseReader in, T target)
          Parses text starting at the specified position.
protected abstract  void parseIt(ParseReader in, T target)
          Parses text starting at the specified position.
 String toString()
           
 void write(ParseWriter out, T source)
          Formats the source object and writes it into the output stream
protected abstract  void writeIt(ParseWriter out, T source)
          Formats the source object and writes it into the output stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.japaki.text.Parser
treeView
 

Constructor Detail

AbstractParser

protected AbstractParser(String name)
Creates a new abstract parser.

Parameters:
name - the name is returned in the toString() method.
Throws:
NullPointerException - if name is null
Method Detail

getLogger

protected Logger getLogger()
Returns:
the logger for this class

handleException

protected static <B,V> void handleException(RuntimeException e,
                                            Property<B,V> property,
                                            B bean,
                                            V value)
Handles exceptions that are thrown during a setValue operation.

Parameters:
e - exception that has occurred
property - See Property.setValue()
bean - See Property.setValue()
value - See Property.setValue()
Throws:
BeanStoreException - if a defined exception has occurred
RuntimeException - if an undefined exception has occurred

parseIt

protected abstract void parseIt(ParseReader in,
                                T target)
                         throws IOException,
                                ParseException
Parses text starting at the specified position.

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
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 abstract void writeIt(ParseWriter out,
                                T source)
                         throws IOException,
                                FormatException
Formats the source object and writes it into the output stream

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.

parse

public void parse(ParseReader in,
                  T target)
           throws IOException,
                  ParseException
Description copied from interface: Parser
Parses text starting at the specified position.

Specified by:
parse in interface Parser<T>
Parameters:
in - the position where to start parsing
target - place where the parsed object is stored.
Throws:
ClassCastException - if generics rules are violated
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

write

public void write(ParseWriter out,
                  T source)
           throws IOException,
                  FormatException
Description copied from interface: Parser
Formats the source object and writes it into the output stream

Specified by:
write in interface Parser<T>
Parameters:
out - the stream and position where to put the formatted text.
source - source object
Throws:
ClassCastException - if generics rules are violated
NullPointerException - if out is null
IOException - if an I/O error occurs
FormatException - if the source object can not be formatted with this parser.

toString

public String toString()
Overrides:
toString in class Object