WebSphere Application Server Network Deployment, Version 6.0.x     Operating Systems: AIX, HP-UX, Linux, Solaris, Windows

Accessing caller locales and time zones

Before you begin

An application component must first resolve a reference to the CallerInternationalization object and then bind it to the Internationalization interface.

Why and when to perform this task

Every remote invocation of an application component has an associated caller internationalization context associated with the thread that is running that invocation. A caller context is propagated by the internationalization service and middleware to the target of a request, such as an Enterprise JavaBeans (EJB) business method or servlet service method. This task also applies to Web service client programs.

Perform the following task to access elements of the Caller internationalization context.

Steps for this task

  1. Obtain the desired caller context elements.
    java.util.Locale [] myLocales  = null;
    try {
      myLocales  = callerI18n.getLocales();
    }
    catch (IllegalStateException ise) {
      // The Caller context is unavailable; 
      // is the service started and enabled?  
    }
    ...
    
    The Internationalization interface contains the following methods to get caller internationalization context elements:
    • Locale [] getLocales() Returns the list of caller locales that are associated with the current thread.
    • Locale getLocale() Returns the first in the list of caller locales that are associated with the current thread.
    • TimeZone getTimeZone() Returns the SimpleTimeZone caller that is associated with the current thread.

    The Internationalization interface supports read-only access to internationalization context within application components. Methods of the Internationalization interface are available to all EJB application components and are used in the same manner for each, but the method semantics vary according to the component type. For instance, when obtaining the caller locale within an EJB client application, the interface returns the default locale of the host Java virtual machine (JVM); in contrast, when obtaining caller context within a servlet service method (for example, doPost or doGet methods), the interface returns the first locale (accept-language) propagated within the corresponding HTML request. See Internationalization context for a discussion of how the service propagates internationalization context throughout an application.

  2. Use the caller context elements to localize computations under a locale or time zone of the calling process.
    DateFormat df = DateFormat.getDateInstance(myLocale);
    String localizedDate = df.getDateInstance().format(aDateInstance);
    ...



Related concepts
Internationalization context

Related tasks
Gaining access to the internationalization context API
Accessing invocation locales and time zones

Related reference
Internationalization context API: Programming reference
Example: Internationalization context in an EJB client program
Example: Internationalization context in a servlet
Example: Internationalization context in a session bean

Task topic    

Terms of Use | Feedback

Last updated: Mar 17, 2005 4:28:29 AM CST
http://publib.boulder.ibm.com/infocenter/ws60help/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/i18n/tasks/tin_accesscallertz.html

© Copyright IBM Corporation 2002, 2005. All Rights Reserved.
This information center is powered by Eclipse technology. (http://www.eclipse.org)