Internationalization context API: Programming reference
Application components programmatically manage internationalization context through the UserInternationalization, Internationalization, and InvocationInternationalization interfaces in the com.ibm.websphere.i18n.context package. The following code example introduces the internationalization context 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.TimeZone getTimeZone(); } 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); }
UserInternationalization interface
The UserInternationalization interface provides factory methods for obtaining references to the CallerInternationalization and InvocationInternationalization context objects. Use these references to access elements of the caller and invocation contexts correlated to the current thread.
Methods of the UserInternationalization interface:
- Internationalization getCallerInternationalization()
- Returns a reference implementing the Internationalization interface that supports access to elements of the caller internationalization context correlated to the current thread. If the service is disabled, this method issues an IllegalStateException exception.
- InvocationInternationalization getInvocationInternationalization()
- Returns a reference implementing the InvocationInternationalization interface. If the service is disabled, this method issues an IllegalStateException exception.
Internationalization interface
The Internationalization interface declares methods that provide read-only access to internationalization context. Given a caller or invocation internationalization context object created with the UserInternationalization interface, bind the object to the Internationalization interface to get elements of that context type. Observe that caller internationalization context can be accessed only through this interface.
Methods of the Internationalization interface:
- Locale[] getLocales()
- Returns the chain of locales within the internationalization context (object) that is bound to the interface, provided the chain is not null; otherwise this method returns a chain of length(1) containing the default locale of the Java virtual machine (JVM).
- Locale getLocale()
- Returns the first in the chain of locales within the internationalization context (object) that is bound to the interface, provided the chain is not null; otherwise this method returns the default locale of the JVM.
- TimeZone getTimeZone()
- Returns the caller time zone (that is, the SimpleTimeZone instance) that is associated with the current thread, provided the time zone is non-null; otherwise this method returns the process time zone.
InvocationInternationalization interface
The InvocationInternationalization interface declares methods that provide read and write access to InvocationInternationalization context. Given an invocation internationalization context object created with the UserInternationalization interface, bind the object to the InvocationInternationalization interface to get and set elements of the invocation context.
According to the container-managed internationalization (CMI) policy, all set methods, setXxx(), issue an IllegalStateException exception when called within a CMI servlet or enterprise bean.
Methods of the InvocationInternationalization interface:
- void setLocales(java.util.Locale[] locales)
- Sets the chain of locales to the supplied chain, locales, within the invocation internationalization context. The supplied chain can be null or have length(>= 0). When the supplied chain is null or has length(0), the service sets the chain of invocation locales to an array of length(1) containing the default locale of the JVM. Null entries can exist within the supplied locale list, for which the service substitutes the default locale of the JVM on remote invocations.
- void setLocale(java.util.Locale locale)
- Sets the chain of locales within the invocation internationalization context to an array of length(1) containing the supplied locale, locale. The supplied locale can be null, in which case the service instead sets the chain to an array of length(1) containing the default locale of the JVM.
- void setTimeZone(java.util.TimeZone timeZone)
- Sets the time zone within the invocation internationalization context to the supplied time zone, time zone. If the supplied time zone is not an exact instance of java.util.SimpleTimeZone or is null, the service sets the invocation time zone to the default time zone of the JVM instead.
- void setTimeZone(String timeZoneId)
- Sets the time zone within the invocation internationalization context to the java.util.SimpleTimeZone having the supplied ID, timeZoneId. If the supplied time zone ID is null or invalid (that is, the ID is not displayed in the list of IDs returned by the java.util.TimeZone.getAvailableIds method) the service sets the invocation time zone to the simple time zone having an ID of GMT, an offset of 00:00, and otherwise invalid fields.
See also
Internationalization context
Internationalization context: Propagation and scope
Internationalization context: Management policies
Related Tasks
Using the internationalization context API
See Also
Example: Internationalization context in an EJB client program
Example: Internationalization context in a servlet
Example: Internationalization context in a session bean