Class LocaleStringConverter
java.lang.Object
org.datanucleus.store.types.converters.LocaleStringConverter
- All Implemented Interfaces:
Serializable
,ColumnLengthDefiningTypeConverter
,TypeConverter<Locale,
String>
public class LocaleStringConverter
extends Object
implements TypeConverter<Locale,String>, ColumnLengthDefiningTypeConverter
Class to handle the conversion between java.util.Locale and a String form.
Locale should be stored in columns from 2 to 20 characters.
Normally, we will have a string no longer than 5 characters, but variants, in general, are vendor specific and can be longer than expected.
The Variant codes are vendor and browser-specific. For example, use WIN for Windows, MAC for Macintosh, and POSIX for POSIX.
Where there are two variants, separate them with an underscore, and put the most important one first.
For example, a Traditional Spanish collation might construct a locale with parameters for language, country and variant as: "es", "ES", "Traditional_WIN".
language_country_variant
Examples: "en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr_MAC"
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
getDefaultColumnLength
(int columnPosition) Accessor for the default column length to use for the datastore column at the specified position.static Locale
getLocaleFromString
(String localeString) Convert a string based locale into a Locale Object.toDatastoreType
(Locale loc) Method to convert the passed member value to the datastore type.toMemberType
(String str) Method to convert the passed datastore value to the member type.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
-
Constructor Details
-
LocaleStringConverter
public LocaleStringConverter()
-
-
Method Details
-
toMemberType
Description copied from interface:TypeConverter
Method to convert the passed datastore value to the member type.- Specified by:
toMemberType
in interfaceTypeConverter<Locale,
String> - Parameters:
str
- Value from the datastore- Returns:
- Value for the member
-
toDatastoreType
Description copied from interface:TypeConverter
Method to convert the passed member value to the datastore type.- Specified by:
toDatastoreType
in interfaceTypeConverter<Locale,
String> - Parameters:
loc
- Value from the member- Returns:
- Value for the datastore
-
getDefaultColumnLength
public int getDefaultColumnLength(int columnPosition) Description copied from interface:ColumnLengthDefiningTypeConverter
Accessor for the default column length to use for the datastore column at the specified position.- Specified by:
getDefaultColumnLength
in interfaceColumnLengthDefiningTypeConverter
- Parameters:
columnPosition
- Position of the column being enquired about (0 = first)- Returns:
- The column length (-1 if no preference)
-
getLocaleFromString
Convert a string based locale into a Locale Object. Assumes the string has form "{language}_{country}_{variant}" (same as the output from Locale.toString()). Examples: "en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr_MAC"- Parameters:
localeString
- The String- Returns:
- the Locale
-