[Version 5.0.2 and later]Gaining access to the internationalization context API

Why and when to perform this task

This topic describes how to access the internationalization service by resolving a reference to the internationalization context API.

Tip:

Resolve internationalization context API references once over the lifecycle of an application component, within the initialization method of that component (for example, within the init() method of servlets, or within the SetXxxContext() method of enterprise beans).

[Version 5.0.2 and later]For Web service client programs, perform the following task to resolve a reference to the internationalization context API during initialization. For stateless session beans enabled for Web services, resolve the reference in the setSessionContext() method.

Steps for this task

  1. Resolve a reference to the UserInternationalization interface by performing a lookup on the JNDI name java:comp/websphere/UserInternationalization.
    For example:
    //--------------------------------------------------------------------
    // Internationalization context imports. 
    //--------------------------------------------------------------------
    import com.ibm.websphere.i18n.context.*;
    import javax.naming.*;
    ...
    
    public class MyApplication {
      ...
    
      //--------------------------------------------------------------------
      // Resolve a reference to the UserInternationalization interface.
      //--------------------------------------------------------------------
      InitialContext initCtx = null;
      UserInternationalization userI18n = null;
      final String UserI18nUrl = "java:comp/websphere/UserInternationalization"; 
      try {
        initCtx = new InitialContext();
        userI18n = (UserInternationalization)initCtx.lookup(UserI18nUrl);
      }
      catch (NamingException ne) {
        // UserInternationalization URL is unavailable.
      }
    

    If the UserInternationalization object is unavailable due to an anomaly or a restriction, the JNDI lookup invocation throws a javax.naming.NameNotFoundException that contains the java.lang.IllegalStateException.

  2. Use the UserInternationalization reference to create references to the CallerInternationalization or InvocationInternationalization objects, which provide access to elements of the Caller or Invocation internationalization contexts, respectively.
    The CallerInternationalization reference can be bound to the Internationalization interface, only; the InvocationInternationalization reference can be bound to either the Internationalization or the InvocationInternationalization interfaces, depending on whether the application requires read-only or read-write access to invocation context. For example:
      ...
      //--------------------------------------------------------------------
      // Resolve references to the Internationalization and
      // InvocationInternationalization interfaces.
      //--------------------------------------------------------------------
      Internationalization callerI18n = null;
      InvocationInternationalization invocationI18n = null;
      try {
        callerI18n = userI18n.getCallerInternationalization();
        invocationI18n = userI18n.getInvocationInternationalization();
      }
      catch (IllegalStateException ise) {
        // An Internationalization interface(s) is unavailable.
      }
    

Related concepts
Internationalization context
Related tasks
Accessing caller locales and time zone
Accessing invocation locales and time zone
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



Searchable topic ID:   tin_gainaccess
Last updated: Jun 21, 2007 8:07:48 PM CDT    WebSphere Business Integration Server Foundation, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/i18n/tasks/tin_gainaccess.html

Library | Support | Terms of Use | Feedback