This topic describes how to access the internationalization service by resolving a reference to the internationalization context API.
Resolve internationalization context API references once over the life cycle 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, 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.
//-------------------------------------------------------------------- // 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 because of an anomaly or a restriction, the JNDI lookup invocation issues a javax.naming.NameNotFoundException exception that contains the java.lang.IllegalStateException instance.
... //-------------------------------------------------------------------- // 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 zones
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