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).
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
//-------------------------------------------------------------------- // 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.
... //-------------------------------------------------------------------- // 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. }