KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > orbutil > CorbaResourceUtil


1 /*
2  * @(#)CorbaResourceUtil.java 1.6 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.orbutil;
9
10 import java.util.ResourceBundle JavaDoc;
11 import java.util.MissingResourceException JavaDoc;
12
13 public class CorbaResourceUtil {
14     public static String JavaDoc getString(String JavaDoc key) {
15         if (!resourcesInitialized) {
16             initResources();
17         }
18
19         try {
20             return resources.getString(key);
21         } catch (MissingResourceException JavaDoc ignore) {
22         }
23         return null;
24     }
25
26     public static String JavaDoc getText(String JavaDoc key) {
27         String JavaDoc message = getString(key);
28         if (message == null) {
29             message = "no text found: \"" + key + "\"";
30         }
31         return message;
32     }
33
34     public static String JavaDoc getText(String JavaDoc key, int num) {
35     return getText(key, Integer.toString(num), null, null);
36     }
37
38     public static String JavaDoc getText(String JavaDoc key, String JavaDoc arg0) {
39     return getText(key, arg0, null, null);
40     }
41
42     public static String JavaDoc getText(String JavaDoc key, String JavaDoc arg0, String JavaDoc arg1) {
43     return getText(key, arg0, arg1, null);
44     }
45
46     public static String JavaDoc getText(String JavaDoc key,
47                  String JavaDoc arg0, String JavaDoc arg1, String JavaDoc arg2)
48     {
49     String JavaDoc format = getString(key);
50     if (format == null) {
51         format = "no text found: key = \"" + key + "\", " +
52         "arguments = \"{0}\", \"{1}\", \"{2}\"";
53     }
54
55     String JavaDoc[] args = new String JavaDoc[3];
56     args[0] = (arg0 != null ? arg0.toString() : "null");
57     args[1] = (arg1 != null ? arg1.toString() : "null");
58     args[2] = (arg2 != null ? arg2.toString() : "null");
59
60     return java.text.MessageFormat.format(format, args);
61     }
62
63     private static boolean resourcesInitialized = false;
64     private static ResourceBundle JavaDoc resources;
65
66     private static void initResources() {
67         try {
68             resources =
69                 ResourceBundle.getBundle("com.sun.corba.se.impl.orbutil.resources.sunorb");
70             resourcesInitialized = true;
71         } catch (MissingResourceException JavaDoc e) {
72             throw new Error JavaDoc("fatal: missing resource bundle: " +
73                             e.getClassName());
74         }
75     }
76
77 }
78
Popular Tags