public abstract class BaseLocaleConverter extends java.lang.Object implements LocaleConverter
The base class for all standart type locale-sensitive converters.
It has LocaleConverter
and Converter
implementations,
that convert an incoming locale-sensitive Object into an object of correspond type,
optionally using a default value or throwing a ConversionException
if a conversion error occurs.
Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
defaultValue
The default value specified to our Constructor, if any.
|
protected java.util.Locale |
locale
The locale specified to our Constructor, by default - system locale.
|
protected boolean |
locPattern
The flag indicating whether the given pattern string is localized or not.
|
private org.apache.commons.logging.Log |
log
All logging goes through this logger
|
protected java.lang.String |
pattern
The default pattern specified to our Constructor, if any.
|
protected boolean |
useDefault
Should we return the default value on conversion errors?
|
Modifier | Constructor and Description |
---|---|
protected |
BaseLocaleConverter(java.util.Locale locale,
java.lang.String pattern)
Create a
LocaleConverter that will throw a ConversionException
if a conversion error occurs. |
protected |
BaseLocaleConverter(java.util.Locale locale,
java.lang.String pattern,
boolean locPattern)
Create a
LocaleConverter that will throw a ConversionException
if a conversion error occurs. |
protected |
BaseLocaleConverter(java.lang.Object defaultValue,
java.util.Locale locale,
java.lang.String pattern)
Create a
LocaleConverter that will return the specified default value
if a conversion error occurs. |
protected |
BaseLocaleConverter(java.lang.Object defaultValue,
java.util.Locale locale,
java.lang.String pattern,
boolean locPattern)
Create a
LocaleConverter that will return the specified default value
if a conversion error occurs. |
private |
BaseLocaleConverter(java.lang.Object defaultValue,
java.util.Locale locale,
java.lang.String pattern,
boolean useDefault,
boolean locPattern)
Create a
LocaleConverter that will return the specified default value
or throw a ConversionException if a conversion error occurs. |
Modifier and Type | Method and Description |
---|---|
private static <T> T |
checkConversionResult(java.lang.Class<T> type,
java.lang.Object result)
Checks whether the result of a conversion is conform to the specified
target type.
|
<T> T |
convert(java.lang.Class<T> type,
java.lang.Object value)
Convert the specified locale-sensitive input object into an output object of the
specified type.
|
<T> T |
convert(java.lang.Class<T> type,
java.lang.Object value,
java.lang.String pattern)
Convert the specified locale-sensitive input object into an output object of the
specified type.
|
java.lang.Object |
convert(java.lang.Object value)
Convert the specified locale-sensitive input object into an output object.
|
java.lang.Object |
convert(java.lang.Object value,
java.lang.String pattern)
Convert the specified locale-sensitive input object into an output object.
|
private <T> T |
getDefaultAs(java.lang.Class<T> type)
Returns the default object specified for this converter cast for the
given target type.
|
protected abstract java.lang.Object |
parse(java.lang.Object value,
java.lang.String pattern)
Convert the specified locale-sensitive input object into an output object of the
specified type.
|
private final org.apache.commons.logging.Log log
private java.lang.Object defaultValue
protected boolean useDefault
protected java.util.Locale locale
protected java.lang.String pattern
protected boolean locPattern
protected BaseLocaleConverter(java.util.Locale locale, java.lang.String pattern)
LocaleConverter
that will throw a ConversionException
if a conversion error occurs.
An unlocalized pattern is used for the convertion.locale
- The localepattern
- The convertion patternprotected BaseLocaleConverter(java.util.Locale locale, java.lang.String pattern, boolean locPattern)
LocaleConverter
that will throw a ConversionException
if a conversion error occurs.locale
- The localepattern
- The convertion patternlocPattern
- Indicate whether the pattern is localized or notprotected BaseLocaleConverter(java.lang.Object defaultValue, java.util.Locale locale, java.lang.String pattern)
LocaleConverter
that will return the specified default value
if a conversion error occurs.
An unlocalized pattern is used for the convertion.defaultValue
- The default value to be returnedlocale
- The localepattern
- The convertion patternprotected BaseLocaleConverter(java.lang.Object defaultValue, java.util.Locale locale, java.lang.String pattern, boolean locPattern)
LocaleConverter
that will return the specified default value
if a conversion error occurs.defaultValue
- The default value to be returnedlocale
- The localepattern
- The convertion patternlocPattern
- Indicate whether the pattern is localized or notprivate BaseLocaleConverter(java.lang.Object defaultValue, java.util.Locale locale, java.lang.String pattern, boolean useDefault, boolean locPattern)
LocaleConverter
that will return the specified default value
or throw a ConversionException
if a conversion error occurs.defaultValue
- The default value to be returnedlocale
- The localepattern
- The convertion patternuseDefault
- Indicate whether the default value is used or notlocPattern
- Indicate whether the pattern is localized or notprotected abstract java.lang.Object parse(java.lang.Object value, java.lang.String pattern) throws java.text.ParseException
value
- The input object to be convertedpattern
- The pattern is used for the convertionjava.text.ParseException
- if conversion cannot be performed
successfullypublic java.lang.Object convert(java.lang.Object value)
value
- The input object to be convertedConversionException
- if conversion cannot be performed
successfullypublic java.lang.Object convert(java.lang.Object value, java.lang.String pattern)
value
- The input object to be convertedpattern
- The pattern is used for the conversionConversionException
- if conversion cannot be performed
successfullypublic <T> T convert(java.lang.Class<T> type, java.lang.Object value)
convert
in interface Converter
T
- The desired target type of the conversiontype
- Data type to which this value should be convertedvalue
- The input object to be convertedConversionException
- if conversion cannot be performed
successfullypublic <T> T convert(java.lang.Class<T> type, java.lang.Object value, java.lang.String pattern)
convert
in interface LocaleConverter
T
- The desired target type of the conversiontype
- Data is type to which this value should be convertedvalue
- is the input object to be convertedpattern
- is the pattern is used for the conversion; if null is
passed then the default pattern associated with the converter object
will be used.ConversionException
- if conversion cannot be performed
successfullyprivate <T> T getDefaultAs(java.lang.Class<T> type)
T
- the desired target typetype
- the target class of the conversionConversionException
- if the default object is not compatible with
the target typeprivate static <T> T checkConversionResult(java.lang.Class<T> type, java.lang.Object result)
T
- the desired result typetype
- the target class of the conversionresult
- the conversion result objectConversionException
- if the result object is not compatible with
the target typeCopyright (c) 2000-2008 - Apache Software Foundation