1. /*
  2. * @(#)CorbaResourceUtil.java 1.4 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.internal.orbutil;
  8. import java.util.ResourceBundle;
  9. import java.util.MissingResourceException;
  10. public class CorbaResourceUtil {
  11. public static String getString(String key) {
  12. if (!resourcesInitialized) {
  13. initResources();
  14. }
  15. try {
  16. return resources.getString(key);
  17. } catch (MissingResourceException ignore) {
  18. }
  19. return null;
  20. }
  21. public static String getText(String key) {
  22. String message = getString(key);
  23. if (message == null) {
  24. message = "no text found: \"" + key + "\"";
  25. }
  26. return message;
  27. }
  28. public static String getText(String key, int num) {
  29. return getText(key, Integer.toString(num), null, null);
  30. }
  31. public static String getText(String key, String arg0) {
  32. return getText(key, arg0, null, null);
  33. }
  34. public static String getText(String key, String arg0, String arg1) {
  35. return getText(key, arg0, arg1, null);
  36. }
  37. public static String getText(String key,
  38. String arg0, String arg1, String arg2)
  39. {
  40. String format = getString(key);
  41. if (format == null) {
  42. format = "no text found: key = \"" + key + "\", " +
  43. "arguments = \"{0}\", \"{1}\", \"{2}\"";
  44. }
  45. String[] args = new String[3];
  46. args[0] = (arg0 != null ? arg0.toString() : "null");
  47. args[1] = (arg1 != null ? arg1.toString() : "null");
  48. args[2] = (arg2 != null ? arg2.toString() : "null");
  49. return java.text.MessageFormat.format(format, args);
  50. }
  51. private static boolean resourcesInitialized = false;
  52. private static ResourceBundle resources;
  53. private static void initResources() {
  54. try {
  55. resources =
  56. ResourceBundle.getBundle("com.sun.corba.se.internal.orbutil.resources.sunorb");
  57. resourcesInitialized = true;
  58. } catch (MissingResourceException e) {
  59. throw new Error("fatal: missing resource bundle: " +
  60. e.getClassName());
  61. }
  62. }
  63. }