net.sf.japaki.kit
Class ParserStore

java.lang.Object
  extended by net.sf.japaki.kit.ParserStore

public class ParserStore
extends Object

Tries to find parsers for given parameters.


Constructor Summary
ParserStore()
           
 
Method Summary
 void add(Class<?> supertype, Class<?> subtype)
          Inserts a new class pair in the implementation map.
<B,S,T> void
add(Class<S> valueType, Class<T> targetType, Property<B,T> property)
          Adds a new property to the transformer repository.
<B,T extends B>
void
add(String name, Parser<B> parser, Class<T> type)
          Adds the parser to the mold map.
 ParserMold<?> add(String name, ParserMold<?> mold)
          Adds a mold to the mold repository.
 SuperParserMold<?,?,?> add(String name, SuperParserMold<?,?,?> mold)
          Adds a mold to the mold repository.
 String addDefault(String name, ParserMold<?> mold)
          Adds a mold to the mold repository and makes it default for its target type.
 String addDefault(String name, SuperParserMold<?,?,?> mold)
          Adds a mold to the mold repository and makes it default for its target type.
<S,T> void
addTransformer(Class<S> sourceType, Class<T> targetType, TwoWayTransformer<S,T> transformer)
          Adds a new transformer to the transformer repository.
<T> Factory<T>
findFactory(Class<T> type)
          Creates a factory for the specified type.
protected
<B,V,T> Parser<B>
findParser(ParserMold<T> mold, Property<B,V> property, ParserMold.Parameter parameter)
          Creates a parser using the specified parameters.
<B,V> Parser<B>
findParser(Property<B,V> property)
          Creates a parser using the specified parameters.
<B,V> Parser<B>
findParser(String parserName, Property<B,V> property, ParserMold.Parameter parameter)
          Creates a parser using the specified parameters.
<B,V> Parser<B>
findParser(String parserName, Property<B,V> property, ParserMold.Parameter parameter, String subParserName, Parser<Object> delParser)
          Creates a parser using the specified parameters.
static ParserMold.Parameter fromPattern(String pattern)
          Creates parser mold parameters from the given pattern.
static ParserStore getInstance()
          Returns a default instance.
protected  Logger getLogger()
           
static ParserStore newDefaultInstance()
          Creates a new parser store and fills it with default settings.
protected  void useDefaults(Locale locale)
          Adds default entries for the specified locale.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParserStore

public ParserStore()
Method Detail

getLogger

protected Logger getLogger()

getInstance

public static ParserStore getInstance()
Returns a default instance.

Returns:
a default instance

newDefaultInstance

public static ParserStore newDefaultInstance()
Creates a new parser store and fills it with default settings.

Returns:
a new parser store.

add

public <B,S,T> void add(Class<S> valueType,
                        Class<T> targetType,
                        Property<B,T> property)
Adds a new property to the transformer repository. If a transformer for the class pair already exists, it is overwritten. The property is used if a parser is searched and the target type of the parser mold does not match the property's type. If the target type has a default mold, it is also used for the source type.

Parameters:
valueType - the type of the property that is used
targetType - the type of the parser mold that is used.
property - the transformer to be used for the specified pair of source and target class

addTransformer

public <S,T> void addTransformer(Class<S> sourceType,
                                 Class<T> targetType,
                                 TwoWayTransformer<S,T> transformer)
Adds a new transformer to the transformer repository. If a transformer for the class pair already exists, it is overwritten. The transformer is used if a parser is searched and the target type of the parser mold does not match the property's type. If the target type has a default mold, it is also used for the source type.

Parameters:
sourceType - the type of the property that is used
targetType - the type of the parser mold that is used.
transformer - the transformer to be used for the specified pair of source and target class

findParser

protected <B,V,T> Parser<B> findParser(ParserMold<T> mold,
                                       Property<B,V> property,
                                       ParserMold.Parameter parameter)
Creates a parser using the specified parameters. If necessary the property is transformed so that its value type and the target type of the mold match.

Parameters:
mold - to be used to create the parser
property - the property of the new parser
parameter - the parameters to be used for the new parser
Returns:
a new parser
Throws:
NullPointerException - if parameter is null or if property or some parameter is null and this mold does not allow it.
IllegalArgumentException - if the pattern cannot be interpreted by the mold.

add

public void add(Class<?> supertype,
                Class<?> subtype)
Inserts a new class pair in the implementation map.

Parameters:
supertype - interface or not instantiable class
subtype - implementing class of the super class
Throws:
NullPointerException - if any class is null
DuplicateKeyException - if one or both classes are already in the map

findFactory

public <T> Factory<T> findFactory(Class<T> type)
Creates a factory for the specified type. If the type is defined as a super class in the implementation map a factory for the implementing class is created.
If the type has a static class with the name "getFactory", it is used to create the factory.

Parameters:
type - a class
Returns:
the new factory for the given type or null if no factory could be constructed.

add

public ParserMold<?> add(String name,
                         ParserMold<?> mold)
Adds a mold to the mold repository.

Parameters:
name - name of the parser mold in the repository
mold - the new parser mold
Returns:
old mold for the name
Throws:
NullPointerException - if name or mold is null

addDefault

public String addDefault(String name,
                         ParserMold<?> mold)
Adds a mold to the mold repository and makes it default for its target type. If a mold for the target type already exists, it is overwritten.

Parameters:
name - name of the parser mold in the repository
mold - the new parser mold
Returns:
old default mold for the new mold's target type
Throws:
NullPointerException - if name or mold is null
DuplicateKeyException - if there is already an entry for the name

add

public SuperParserMold<?,?,?> add(String name,
                                  SuperParserMold<?,?,?> mold)
Adds a mold to the mold repository.

Parameters:
name - name of the super parser mold in the repository
mold - the new super parser mold
Returns:
old mold for the name
Throws:
NullPointerException - if name or mold is null

addDefault

public String addDefault(String name,
                         SuperParserMold<?,?,?> mold)
Adds a mold to the mold repository and makes it default for its target type. If a mold for the target type already exists, it is overwritten.
If the target type is defined in the implementation as implementing a super class, then the mold is also default for the super class.

Parameters:
name - name of the super parser mold in the repository
mold - the new super parser mold
Returns:
old default mold for the new mold's target type
Throws:
NullPointerException - if name,mold or mold's target type is null
DuplicateKeyException - if there is already an entry for the name

add

public <B,T extends B> void add(String name,
                                Parser<B> parser,
                                Class<T> type)
Adds the parser to the mold map.

Parameters:
name - name of the super parser mold in the repository
parser - a parser
type - target type for the name
Throws:
NullPointerException - if targetType or parser is null
DuplicateKeyException - if there is already an entry for the name

findParser

public <B,V> Parser<B> findParser(String parserName,
                                  Property<B,V> property,
                                  ParserMold.Parameter parameter,
                                  String subParserName,
                                  Parser<Object> delParser)
Creates a parser using the specified parameters.

Parameters:
parserName - name of the parser
property - the property of the new parser
parameter - the parameters to be used for the new parser
subParserName - name of the element parser
delParser - parser for delimiters
Returns:
a new parser
Throws:
NullPointerException - if both parserName and type are null or subParserName is null or if property or some parameter is null and this mold does not allow it.
IllegalArgumentException - if a parser of the given name is not found in the store or if the pattern cannot be interpreted by the used mold.

findParser

public <B,V> Parser<B> findParser(String parserName,
                                  Property<B,V> property,
                                  ParserMold.Parameter parameter)
Creates a parser using the specified parameters.

Parameters:
parserName - name of the parser
property - the property of the new parser
parameter - the parameters to be used for the new parser
Returns:
a new parser
Throws:
NullPointerException - if both parserName and the property's type are null or if property or some parameter is null and this mold does not allow it.
IllegalArgumentException - if a parser of the given name is not found in the store or if the pattern cannot be interpreted by the used mold.

findParser

public <B,V> Parser<B> findParser(Property<B,V> property)
Creates a parser using the specified parameters.

Parameters:
property - the property of the new parser
Throws:
NullPointerException - if the property or its target type is null

fromPattern

public static final ParserMold.Parameter fromPattern(String pattern)
Creates parser mold parameters from the given pattern.

Parameters:
pattern - a pattern string that specifies a parser
Returns:
new parser mold parameters

useDefaults

protected void useDefaults(Locale locale)
Adds default entries for the specified locale.

Parameters:
locale - a locale
Throws:
DuplicateKeyException - if one of the entries was already in the store