286N/A * reserved comment block 286N/A * DO NOT REMOVE OR ALTER! 286N/A * Copyright 2004 The Apache Software Foundation. 286N/A * Licensed under the Apache License, Version 2.0 (the "License"); 286N/A * you may not use this file except in compliance with the License. 286N/A * You may obtain a copy of the License at 286N/A * Unless required by applicable law or agreed to in writing, software 286N/A * distributed under the License is distributed on an "AS IS" BASIS, 286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 286N/A * See the License for the specific language governing permissions and 286N/A * limitations under the License. 286N/A * A utility class for issuing error messages. 286N/A * A user of this class normally would create a singleton 286N/A * instance of this class, passing the name 286N/A * of the message class on the constructor. For example: 286N/A * static Messages x = new Messages("org.package.MyMessages"); 286N/A * Later the message is typically generated this way if there are no 286N/A * substitution arguments: 286N/A * String msg = x.createMessage(org.package.MyMessages.KEY_ONE, null); 286N/A * If there are arguments substitutions then something like this: 286N/A * String filename = ...; 286N/A * String directory = ...; 286N/A * String msg = x.createMessage(org.package.MyMessages.KEY_TWO, 286N/A * new Object[] {filename, directory) ); 286N/A * The constructor of an instance of this class must be given 286N/A * the class name of a class that extends java.util.ListResourceBundle 286N/A * ("org.package.MyMessages" in the example above). 286N/A * The name should not have any language suffix 286N/A * which will be added automatically by this utility class. 286N/A * The message class ("org.package.MyMessages") 286N/A * must define the abstract method getContents() that is 286N/A * declared in its base class, for example: 286N/A * public Object[][] getContents() {return contents;} 286N/A * It is suggested that the message class expose its 286N/A * message keys like this: 286N/A * public static final String KEY_ONE = "KEY1"; 286N/A * public static final String KEY_TWO = "KEY2"; 286N/A * and used through their names (KEY_ONE ...) rather than 286N/A * their values ("KEY1" ...). 286N/A * The field contents (returned by getContents() 286N/A * should be initialized something like this: 286N/A * public static final Object[][] contents = { 286N/A * { KEY_ONE, "Something has gone wrong!" }, 286N/A * { KEY_TWO, "The file ''{0}'' does not exist in directory ''{1}''." }, 286N/A * { KEY_N, "Message N" } } 286N/A * Where that section of code with the KEY to Message mappings 286N/A * (where the message classes 'contents' field is initialized) 286N/A * can have the Message strings translated in an alternate language 286N/A * in a errorResourceClass with a language suffix. 286N/A * This class is not a public API, it is only public because it is 286N/A /** The local object to use. */ 286N/A /** The language specific resource object for messages. */ 286N/A /** The class name of the error message string table with no language suffix. */ 286N/A * @param resourceBundle the class name of the ListResourceBundle 286N/A * that the instance of this class is associated with and will use when 286N/A * The class name is without a language suffix. If the value passed 286N/A * is null then loadResourceBundle(errorResourceClass) needs to be called 286N/A * explicitly before any messages are created. 286N/A * Get the Locale object that is being used. 286N/A * @return non-null reference to Locale object. 286N/A * Creates a message from the specified key and replacement 286N/A * arguments, localized to the given locale. 286N/A * @param msgKey The key for the message text. 286N/A * @param args The arguments to be used as replacement text 286N/A * in the message created. 286N/A * @return The formatted message string. 286N/A * Creates a message from the specified key and replacement 286N/A * arguments, localized to the given locale. 286N/A * @param errorCode The key for the message text. 286N/A * @param fResourceBundle The resource bundle to use. 286N/A * @param msgKey The message key to use. 286N/A * @param args The arguments to be used as replacement text 286N/A * in the message created. 286N/A * @return The formatted message string. 286N/A /* The message is not in the bundle . . . this is bad, 286N/A * so try to get the message that the message is not in the bundle 286N/A /* even the message that the message is not in the bundle is 286N/A * not there ... this is really bad 286N/A +
"' is not in the message class '" 286N/A // Do this to keep format from crying. 286N/A // This is better than making a bunch of conditional 286N/A // code all over the place. 286N/A for (
int i =
0; i < n; i++)
286N/A // if we get past the line above we have create the message ... hurray! 286N/A // Get the message that the format failed. 286N/A // We couldn't even get the message that the format of 286N/A // the message failed ... so fall back to English. 286N/A "The format of message '" 286N/A +
"' in message class '"