net.sf.japaki.kit
Class LeafParserMold<V>

java.lang.Object
  extended by net.sf.japaki.kit.LeafParserMold<V>
All Implemented Interfaces:
ParserMold<V>
Direct Known Subclasses:
DateParserMold, DecimalParserMold, DurationParserMold, FixedFormatMold, MessageParserMold, RegexParserMold

public abstract class LeafParserMold<V>
extends Object
implements ParserMold<V>

Skeleton class for molds that create leaf parsers.


Nested Class Summary
 
Nested classes/interfaces inherited from interface net.sf.japaki.kit.ParserMold
ParserMold.Parameter
 
Constructor Summary
protected LeafParserMold(Class<V> targetType, Format defaultFormat)
          Creates a new LeafParser mold.
 
Method Summary
protected  String getErrorMessage(Property property, String pattern)
          Returns the error message of the parser to be created.
protected  Format getFormat()
          Returns the format used, if no pattern is specified.
protected abstract  Format getFormat(String pattern)
          Returns the format of the parser to be created.
protected  String getName(Property property)
          Returns the name of the parser to be created.
<B> Parser<B>
getParser(Property<B,V> property, ParserMold.Parameter parameter)
          Creates a parser for the specified property and pattern.
 Class<V> getTargetType()
          Returns the target type of the parsers created by this mold.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LeafParserMold

protected LeafParserMold(Class<V> targetType,
                         Format defaultFormat)
Creates a new LeafParser mold.

Parameters:
targetType - the target type of the parsers created by this mold
defaultFormat - the format used when no pattern is specified. The default format may be null, then a pattern is required.
Throws:
NullPointerException - if targetType is null.
Method Detail

getErrorMessage

protected String getErrorMessage(Property property,
                                 String pattern)
Returns the error message of the parser to be created.

Parameters:
property - property of the new parser
pattern - pattern of the new parsers
Returns:
error message of the parser to be created
Throws:
NullPointerException - if property is null

getName

protected String getName(Property property)
Returns the name of the parser to be created.

Parameters:
property - property of the new parser
Returns:
name of the parser to be created
Throws:
NullPointerException - if property is null

getFormat

protected Format getFormat()
Returns the format used, if no pattern is specified.

Returns:
the default format
Throws:
NullPointerException - if the default format is not specified

getFormat

protected abstract Format getFormat(String pattern)
Returns the format of the parser to be created.

Parameters:
pattern - the pattern describing the format
Returns:
format of the parser to be created
Throws:
NullPointerException - if the given pattern is null
IllegalArgumentException - if the given pattern is invalid

getParser

public <B> Parser<B> getParser(Property<B,V> property,
                               ParserMold.Parameter parameter)
Description copied from interface: ParserMold
Creates a parser for the specified property and pattern.

Specified by:
getParser in interface ParserMold<V>
Parameters:
parameter - pattern - the pattern string for the format
property - property of the created parser
Returns:
new parser
Throws:
NullPointerException - if parameter is null or if property or pattern is null and this mold does not allow it.
IllegalArgumentException - if the pattern cannot be interpreted by this mold.

getTargetType

public Class<V> getTargetType()
Description copied from interface: ParserMold
Returns the target type of the parsers created by this mold.

Specified by:
getTargetType in interface ParserMold<V>
Returns:
the target type of the parsers created by this mold