FileDocCategorySizeDatePackage
ExceptionMessageGenerator.javaAPI DocGlassfish v2 API5544Tue May 22 16:54:20 BST 2007oracle.toplink.essentials.exceptions.i18n

ExceptionMessageGenerator

public class ExceptionMessageGenerator extends Object
INTERNAL: Utility class to generate exception messages using ResourceBundles. Creation date: (12/7/00 10:30:38 AM)
author:
Rick Barkhouse

Fields Summary
Constructors Summary
Methods Summary
public static java.lang.StringbuildMessage(java.lang.Class exceptionClass, int errorNumber, java.lang.Object[] arguments)
Return the message for the given exception class and error number.

        final String CR = System.getProperty("line.separator");

        String shortClassName = Helper.getShortClassName(exceptionClass);
        String message = "";
        ResourceBundle bundle = null;

        // JDK 1.1 MessageFormat can't handle null arguments
        for (int i = 0; i < arguments.length; i++) {
            if (arguments[i] == null) {
                arguments[i] = "null";
            }
        }

        bundle = ResourceBundle.getBundle("oracle.toplink.essentials.exceptions.i18n." + shortClassName + "Resource", Locale.getDefault());

        try {
            message = bundle.getString(String.valueOf(errorNumber));
        } catch (java.util.MissingResourceException mre) {
            // Found bundle, but couldn't find exception translation.
            // Get the current language's NoExceptionTranslationForThisLocale message.
            bundle = ResourceBundle.getBundle("oracle.toplink.essentials.exceptions.i18n.ExceptionResource", Locale.getDefault());
            String noTranslationMessage = bundle.getString("NoExceptionTranslationForThisLocale");
            Object[] args = { CR };
            return format(message, arguments) + format(noTranslationMessage, args);
        }
        return format(message, arguments);
    
protected static java.lang.Stringformat(java.lang.String message, java.lang.Object[] arguments)
Return the formatted message for the given exception class and error number.

        try {
            return MessageFormat.format(message, arguments);
        } catch (Exception ex) {
            ResourceBundle bundle = null;
            bundle = ResourceBundle.getBundle("oracle.toplink.essentials.exceptions.i18n.ExceptionResource", Locale.getDefault());
            String errorMessage = bundle.getString("ErrorFormattingMessage");
            Vector vec = new Vector();
            if (arguments != null) {
                for (int index = 0; index < arguments.length; index++) {
                    try {
                        vec.add(arguments[index].toString());
                    } catch (Exception ex2) {
                        vec.add(ex2);
                    }
                }
            }
            return MessageFormat.format(errorMessage, new Object[] {message, vec});
        }
    
public static java.lang.StringgetHeader(java.lang.String headerLabel)
Get one of the generic headers used for the exception's toString(). E.g., "EXCEPTION DESCRIPTION: ", "ERROR CODE: ", etc.

        ResourceBundle bundle = null;
        try {
            bundle = ResourceBundle.getBundle("oracle.toplink.essentials.exceptions.i18n.ExceptionResource", Locale.getDefault());
            return bundle.getString(headerLabel);
        } catch (java.util.MissingResourceException mre) {
            return "[" + headerLabel + "]";
        }