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 Details

  • Constructor Details

    • LocaleStringConverter

      public LocaleStringConverter()
  • Method Details

    • toMemberType

      public Locale toMemberType(String str)
      Description copied from interface: TypeConverter
      Method to convert the passed datastore value to the member type.
      Specified by:
      toMemberType in interface TypeConverter<Locale,String>
      Parameters:
      str - Value from the datastore
      Returns:
      Value for the member
    • toDatastoreType

      public String toDatastoreType(Locale loc)
      Description copied from interface: TypeConverter
      Method to convert the passed member value to the datastore type.
      Specified by:
      toDatastoreType in interface TypeConverter<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 interface ColumnLengthDefiningTypeConverter
      Parameters:
      columnPosition - Position of the column being enquired about (0 = first)
      Returns:
      The column length (-1 if no preference)
    • getLocaleFromString

      public static Locale getLocaleFromString(String localeString)
      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