public abstract class AbstractCsvConverter extends Object implements CsvConverter
CsvConverter
provides a reasonable default
for CsvConverter.convertToWrite(java.lang.Object)
as well as a couple
of common fields.Modifier and Type | Field and Description |
---|---|
protected Locale |
errorLocale
The locale to be used for error messages.
|
protected Locale |
locale
The locale to be used when converting for reading, if a locale is relevant.
|
protected Class<?> |
type
The type to which (on reading) or from which (on writing) conversion
is being performed.
|
protected Locale |
writeLocale
The locale to be used when converting for writing, if a locale is
relevant.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractCsvConverter()
Default nullary constructor, so derived classes aren't forced to create
a constructor identical to this one.
|
protected |
AbstractCsvConverter(Class<?> type,
String locale,
String writeLocale,
Locale errorLocale)
Currently the only constructor for this class.
|
Modifier and Type | Method and Description |
---|---|
String |
convertToWrite(Object value)
This implementation simply calls
toString() on value . |
void |
setErrorLocale(Locale errorLocale)
Sets the locale for all error messages.
|
void |
setLocale(String locale)
If not null or empty, specifies the locale used for converting
locale-specific data types for reading.
|
void |
setType(Class<?> type)
Sets the class of the type of the data being processed.
|
void |
setWriteLocale(String writeLocale)
If not null or empty, specifies the locale used for converting
locale-specific data types for writing.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
convertToRead
protected Class<?> type
protected Locale locale
protected Locale writeLocale
protected Locale errorLocale
protected AbstractCsvConverter()
protected AbstractCsvConverter(Class<?> type, String locale, String writeLocale, Locale errorLocale)
type
- The type to which (on reading) or from which (on writing) is
being convertedlocale
- The locale to be used when converting for reading, if a
locale is relevantwriteLocale
- The locale to be used when converting for writing, if
a locale is relevanterrorLocale
- The locale to be used for error messagespublic String convertToWrite(Object value) throws CsvDataTypeMismatchException
toString()
on value
.
For complex types, overriding the toString()
method in the type
of the field in question would be an alternative to writing a conversion
routine in a class derived from this one.convertToWrite
in interface CsvConverter
value
- The contents of the field currently being processed from the
bean to be written. Can be null
if the field is not marked as
required.value
is null
CsvDataTypeMismatchException
- This implementation doesn't, but
subclasses do, so it must be declaredpublic void setErrorLocale(Locale errorLocale)
CsvConverter
setErrorLocale
in interface CsvConverter
errorLocale
- Locale for error messages. If null
, the
default locale is used.public void setType(Class<?> type)
CsvConverter
setType
in interface CsvConverter
type
- The type of the data being processedpublic void setLocale(String locale)
CsvConverter
setLocale
in interface CsvConverter
locale
- The name of the locale for locale-sensitive datapublic void setWriteLocale(String writeLocale)
CsvConverter
setWriteLocale
in interface CsvConverter
writeLocale
- The name of the locale for locale-sensitive dataCopyright © 2005–2023. All rights reserved.