To make an exception localizable into different national languages, use the NLS framework. First, create a resource bundle for your error messages. The following code example defines a bundle named MyMsgBundle that stores three error messages.
import oracle.jbo.common.util.CheckedListResourceBundle;
public class MyMsgBundle extends CheckedListResourceBundle
// String Constants
public static final String BAD_EMPNO = "101";
public static final String DEPT_NOT_FOUND = "102";
public static final String NOT_IN_DEPT = "103";
...
/**
* Private 2-D array of key-value pairs
*/
private static final Object[][] sMessageStrings = {
...
{ BAD_EMPNO, "Invalid employee number." },
{ DEPT_NOT_FOUND, "Department {0} does not exist." }
{ NOT_IN_DEPT, "Employee {0} not found in Department {1}." }
...
}
}
Then you can use the resource bundle class to define a value to pass to the constructor for your exception class or JboException.
throw new JboException(MyMsgBundle.class /* Class of Bundle */,
MyMsgBundle.DEPT_NOT_FOUND /* String Constant */,
new Object[1] { localVar1 } /* Arguments to message */
);
JboException provides a getLocalizedMessage method which returns the message formatted for the specified locale.
The NLS framework translates the message text when the client calls getLocalizedMessage rather than at creation time because the client may need to present the message in a number of different languages. This mechanism provides a single point for localizing and formatting messages.