olg.csv.bean.parser
Class AbstractParser<T>

Package class diagram package AbstractParser
java.lang.Object
  extended by olg.csv.bean.parser.AbstractParser<T>
Type Parameters:
T - object this parser returns.
Direct Known Subclasses:
CharacterParser, ConstructorParser, DateParser, DecorateParser, EnumParser, ODSWriter.ODSParser

public abstract class AbstractParser<T>
extends Object

Class used to convert a string into object.


Constructor Summary
AbstractParser()
           
 
Method Summary
static AbstractParser<Character> getCharacterParser()
          Returns parser specialized in string conversion to Character or char.
static
<T> AbstractParser<T>
getConstructorParser(Class<T> clazz)
          Returns the parser that operates from the constructor of the given class.
static AbstractParser<Date> getDateParser(String format, Class<? extends Date> clazz, Locale locale)
          Returns parser specialized in string conversion to date.
static
<E extends Enum<E>>
AbstractParser<E>
getEnumParser(Class<E> clazz)
          Returns parser specialized in string conversion to Enum.
static AbstractParser identifyDefaultParser(Class clazz)
          Returns default parser corresponding to the given class.
abstract  T parse(String str)
          Converts a string into a new instance of .
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractParser

public AbstractParser()
Method Detail

parse

public abstract T parse(String str)
                 throws ParseException
Converts a string into a new instance of .

Parameters:
str - the string.
Returns:
the new instance of .
Throws:
ParseException - if parsing error occurs.

getDateParser

public static AbstractParser<Date> getDateParser(String format,
                                                 Class<? extends Date> clazz,
                                                 Locale locale)
Returns parser specialized in string conversion to date.

Parameters:
format - the date format.
clazz - The class that the returned parser have to return. this class must to have java.util.Date as superclass.
locale - a Locale to apply. May be null
Returns:
a new date parser

getConstructorParser

public static <T> AbstractParser<T> getConstructorParser(Class<T> clazz)
Returns the parser that operates from the constructor of the given class. Throws an UsageInvalideException if no such constructor exists or is visible.

Type Parameters:
T - the type the parser returns
Parameters:
clazz - The class that the returned parser have to return. This class must have a constructor with string argument. This constructor will be used to transform a String into a new Instance of this class.
Returns:
a new parser based on the string constructor of the given class

getCharacterParser

public static AbstractParser<Character> getCharacterParser()
Returns parser specialized in string conversion to Character or char.

Returns:
a new character parser.

getEnumParser

public static <E extends Enum<E>> AbstractParser<E> getEnumParser(Class<E> clazz)
Returns parser specialized in string conversion to Enum.

this parser identifies the enum constant to return from a string seen as the enum constant name.

Type Parameters:
E - the type the parser returns
Parameters:
clazz - Enum concret class
Returns:
a new parser

identifyDefaultParser

public static AbstractParser identifyDefaultParser(Class clazz)
Returns default parser corresponding to the given class. This parser would be responsible to convert a string into an object with the given class.

if the given class is not a primitive class, enum, or Character class, try to return a parser based on a constructor of this class accepting a string as argument.

throws an UsageInvalideException In case the parser we are trying to return is based on class constructor and no such constructor exists or is visible.

Parameters:
clazz - the class.
Returns:
the parser or null if none matches the class.
See Also:
ConstructorParser


Copyright © 2014. All Rights Reserved.