1 7 8 package com.sun.corba.se.impl.orbutil; 9 10 import java.util.ResourceBundle ; 11 import java.util.MissingResourceException ; 12 13 public class CorbaResourceUtil { 14 public static String getString(String key) { 15 if (!resourcesInitialized) { 16 initResources(); 17 } 18 19 try { 20 return resources.getString(key); 21 } catch (MissingResourceException ignore) { 22 } 23 return null; 24 } 25 26 public static String getText(String key) { 27 String message = getString(key); 28 if (message == null) { 29 message = "no text found: \"" + key + "\""; 30 } 31 return message; 32 } 33 34 public static String getText(String key, int num) { 35 return getText(key, Integer.toString(num), null, null); 36 } 37 38 public static String getText(String key, String arg0) { 39 return getText(key, arg0, null, null); 40 } 41 42 public static String getText(String key, String arg0, String arg1) { 43 return getText(key, arg0, arg1, null); 44 } 45 46 public static String getText(String key, 47 String arg0, String arg1, String arg2) 48 { 49 String format = getString(key); 50 if (format == null) { 51 format = "no text found: key = \"" + key + "\", " + 52 "arguments = \"{0}\", \"{1}\", \"{2}\""; 53 } 54 55 String [] args = new String [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 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 e) { 72 throw new Error ("fatal: missing resource bundle: " + 73 e.getClassName()); 74 } 75 } 76 77 } 78 | Popular Tags |