[Enterprise Extensions only]

Internationalization context application programming interface

Application components programmatically manage Internationalization context through the UserInternationalization, Internationalization, and InvocationInternationalization interfaces within the com.ibm.websphere.i18n.context package. The following code snippet introduces the Internationalization context application programming interface (API):

public interface UserInternationalization {
  public Internationalization getCallerInternationalization();
  public InvocationInternationalization getInvocationInternationalization();
}

public interface Internationalization {
  public java.util.Locale[] getLocales();
  public java.util.Locale getLocale();
  public java.util.TimeZonegetTimeZone();
}

public interface InvocationInternationalization
    extends Internationalization {
  public void setLocales(java.util.Locale [] locales);
  public void setLocale(java.util.Locale jmLocale);
  public void setTimeZone(java.util.TimeZonetimeZone);
  public void setTimeZone(String timeZoneId);
}

The UserInternationalization interface provides factory methods for the Internationalization Service interfaces affording access to the caller and invocation contexts. The UserInternationalization interface declares the following methods:

Internationalization getCallerInternationalization()
Returns a reference implementing the Internationalization interface. If the service is disabled, the method throws an IllegalStateException.
InvocationInternationalization getInvocationInternationalization()
Returns a reference implementing the InvocationInternationalization interface. If the service is disabled, the method throws an IllegalStateException.

The Internationalization interface declares methods affording read-only access to caller Internationalization context:

Locale[] getLocales()
Returns the caller locale list associated with the current thread, provided the locale list is non-null; otherwise the method returns a locale list of length(1) containing the process locale.
Locale getLocale()
Returns the tail of the caller locale list associated with the current thread, provided the locale list is non-null; otherwise the method returns the process locale.
TimeZone getTimeZone()
Returns the caller time zone (that is, the SimpleTimeZone) associated with the current thread, provided the time zone is non-null; otherwise the method returns the process time zone.

The InvocationInternationalization interface declares methods affording read and write access to invocation Internationalization context.

Note: According to the server-side Internationaliztion context management policy, all set methods (setXxx()) throw an IllegalStateException when called within a server-side application component, such as a servlet or Enterprise JavaBean implementation.
void setLocales(java.util.Locale[] locales)
Sets the invocation locale list element to the supplied locale list (locales), within the Internationalization context associated with the current thread. The supplied locale list can be null or have length(>= 0). When the supplied locale list is null or has length(0), the service sets the invocation locale list to an array of length(1) containing the default locale. Null entries can exist within the supplied locale list, but the service substitutes the default locale for null on remote invocations.
Locale[] getLocales()
Returns the invocation locale list element of the Internationalization context associated with the current thread, provided the locale list is non-null; otherwise the method returns a locale list of length(1) containing the default locale.
void setLocale(java.util.Locale locale)
Sets the invocation locale list element to an array of length(1) containing the supplied locale (locale), within the Internationalization context associated with the current thread. The supplied locale can be null, in which case the service instead sets the invocation locale list to an array of length(1) containing the default locale.
Locale getLocale()
Returns the tail of the invocation locale list element of the Internationalization context associated with the current thread, provided the locale list is non-null; otherwise the method returns the default locale.
void setTimeZone(java.util.TimeZone timeZone)
Sets the invocation time zone element to the supplied time zone (timeZone), within the Internationalization context associated with the current thread. If the supplied time zone is not an exact instance of java.util.SimpleTimeZone or is null, the service instead sets the invocation time zone to the default time zone.
void setTimeZone(String timeZoneId)
Sets the invocation time zone element to a java.util.SimpleTimeZone having the supplied ID (timeZoneId) within the Internationalization context associated with the current thread. If the supplied time zone ID is null or unsupported (that is, it does not appear in the list of IDs returned by the java.util.TimeZone.getAvailableIds() method) the service sets the invocation time zone to a time zone to the simple time zone having an ID of GMT and otherwise invalid fields.
TimeZone getTimeZone()
Returns the invocation time zone element of the Internationalization context associated with the current thread, provided the time zone is non-null; otherwise the method returns the default time zone (java.util.SimpleTimeZone).