KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > localization > ToplinkLocalization


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.localization;
23
24 import java.text.MessageFormat JavaDoc;
25 import java.util.Locale JavaDoc;
26 import java.util.ResourceBundle JavaDoc;
27
28 /**
29  * <p>
30  * <b>Purpose</b>: Any TopLink message in Foundation Library & J2EE Integration JARs
31  * should be a subclass of this class.
32  *
33  * Creation date: (7/12/00)
34  * @author Shannon Chen
35  * @since TOPLink/Java 5.0
36  */

37 public abstract class ToplinkLocalization {
38
39     /**
40      * Return the message for the given exception class and error number.
41      */

42     public static String JavaDoc buildMessage(String JavaDoc localizationClassName, String JavaDoc key, Object JavaDoc[] arguments) {
43         String JavaDoc message = key;
44         ResourceBundle JavaDoc bundle = null;
45
46         // JDK 1.1 MessageFormat can't handle null arguments
47
if (arguments != null) {
48             for (int i = 0; i < arguments.length; i++) {
49                 if (arguments[i] == null) {
50                     arguments[i] = "null";
51                 }
52             }
53         }
54
55         bundle = ResourceBundle.getBundle("oracle.toplink.essentials.internal.localization.i18n." + localizationClassName + "Resource", Locale.getDefault());
56
57         try {
58             message = bundle.getString(key);
59         } catch (java.util.MissingResourceException JavaDoc mre) {
60             // Found bundle, but couldn't find translation.
61
// Get the current language's NoTranslationForThisLocale message.
62
bundle = ResourceBundle.getBundle("oracle.toplink.essentials.internal.localization.i18n.ToplinkLocalizationResource", Locale.getDefault());
63             String JavaDoc noTranslationMessage = bundle.getString("NoTranslationForThisLocale");
64
65             return MessageFormat.format(message, arguments) + noTranslationMessage;
66         }
67         return MessageFormat.format(message, arguments);
68     }
69 }
70
Popular Tags