net.sf.japaki.text
Class MapParser<K,V>

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

public class MapParser<K,V>
extends AbstractParser<Map<K,V>>

Parses a map, where the key of each field is given in the input stream.


Constructor Summary
protected MapParser(Parser<? super KeyValueBean<K,V>> keyParser, Parser<? super KeyValueBean<K,V>> valueParser, Parser<?> delimiterParser)
          Creates a new map parser from the specified parameters.
 
Method Summary
static
<K,V> Parser<Map<K,V>>
newParser(Parser<? super KeyValueBean<K,V>> parser, Parser<?> delimiterParser)
          Creates a new map parser from the specified parameters.
static
<K,V> Parser<Map<K,V>>
newParser(Parser<? super KeyValueBean<K,V>> keyParser, Parser<? super KeyValueBean<K,V>> valueParser, Parser<?> delimiterParser)
          Creates a new map parser from the specified parameters.
static
<K,V> Parser<Map<K,V>>
newParser(Parser<? super KeyValueBean<K,V>> parser, String delimiter)
          Creates a new map parser from the specified parameters.
protected  void parseIt(ParseReader in, Map<K,V> target)
          Parses text starting at the specified position.
 String treeView()
          Returns a tree view of this parser.
protected  void writeIt(ParseWriter out, Map<K,V> 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

MapParser

protected MapParser(Parser<? super KeyValueBean<K,V>> keyParser,
                    Parser<? super KeyValueBean<K,V>> valueParser,
                    Parser<?> delimiterParser)
Creates a new map parser from the specified parameters.

Parameters:
keyParser - parser for parsing the key
valueParser - element parser
delimiterParser - parser for tokens between map entries
Throws:
NullPointerException - if keyParser or valueParser is null
Method Detail

newParser

public static <K,V> Parser<Map<K,V>> newParser(Parser<? super KeyValueBean<K,V>> keyParser,
                                               Parser<? super KeyValueBean<K,V>> valueParser,
                                               Parser<?> delimiterParser)
Creates a new map parser from the specified parameters.

Parameters:
keyParser - parser for parsing the index
valueParser - element parser
delimiterParser - parser for tokens between map entries
Throws:
NullPointerException - if keyParser or valueParser is null

newParser

public static <K,V> Parser<Map<K,V>> newParser(Parser<? super KeyValueBean<K,V>> parser,
                                               Parser<?> delimiterParser)
Creates a new map parser from the specified parameters.

Parameters:
parser - entry parser
delimiterParser - parser for tokens between map entries
Throws:
NullPointerException - if parser is null

newParser

public static <K,V> Parser<Map<K,V>> newParser(Parser<? super KeyValueBean<K,V>> parser,
                                               String delimiter)
Creates a new map parser from the specified parameters.

Parameters:
parser - entry parser
delimiter - a constant expected and formatted between map entries

parseIt

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

Specified by:
parseIt in class AbstractParser<Map<K,V>>
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 void writeIt(ParseWriter out,
                       Map<K,V> 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<Map<K,V>>
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