1 55 56 package org.jboss.axis.i18n; 57 58 import java.text.MessageFormat ; 59 import java.util.Locale ; 60 import java.util.MissingResourceException ; 61 import java.util.ResourceBundle ; 62 63 72 public class MessageBundle 73 { 74 private boolean loaded = false; 75 76 private ProjectResourceBundle _resourceBundle = null; 77 78 private final String projectName; 79 private final String packageName; 80 private final String resourceName; 81 private final Locale locale; 82 private final ClassLoader classLoader; 83 private final ResourceBundle parent; 84 85 86 public final ProjectResourceBundle getResourceBundle() 87 { 88 if (!loaded) 89 { 90 _resourceBundle = ProjectResourceBundle.getBundle(projectName, 91 packageName, 92 resourceName, 93 locale, 94 classLoader, 95 parent); 96 loaded = true; 97 } 98 return _resourceBundle; 99 } 100 101 104 public MessageBundle(String projectName, 105 String packageName, 106 String resourceName, 107 Locale locale, 108 ClassLoader classLoader, 109 ResourceBundle parent) 110 throws MissingResourceException 111 { 112 this.projectName = projectName; 113 this.packageName = packageName; 114 this.resourceName = resourceName; 115 this.locale = locale; 116 this.classLoader = classLoader; 117 this.parent = parent; 118 } 119 120 126 public String getMessage(String key) throws MissingResourceException 127 { 128 return getMessage(key, (String [])null); 129 } 130 131 143 public String getMessage(String key, String arg0) throws MissingResourceException 144 { 145 return getMessage(key, new String []{arg0}); 146 } 147 148 161 public String getMessage(String key, String arg0, String arg1) throws MissingResourceException 162 { 163 return getMessage(key, new String []{arg0, arg1}); 164 } 165 166 180 public String getMessage(String key, String arg0, String arg1, String arg2) throws MissingResourceException 181 { 182 return getMessage(key, new String []{arg0, arg1, arg2}); 183 } 184 185 200 public String getMessage(String key, String arg0, String arg1, String arg2, String arg3) throws MissingResourceException 201 { 202 return getMessage(key, new String []{arg0, arg1, arg2, arg3}); 203 } 204 205 221 public String getMessage(String key, String arg0, String arg1, String arg2, String arg3, String arg4) throws MissingResourceException 222 { 223 return getMessage(key, new String []{arg0, arg1, arg2, arg3, arg4}); 224 } 225 226 238 public String getMessage(String key, String [] array) throws MissingResourceException 239 { 240 String msg = null; 241 if (getResourceBundle() != null) 242 { 243 msg = getResourceBundle().getString(key); 244 } 245 246 if (msg == null) 247 { 248 throw new MissingResourceException ("Cannot find resource key \"" + key + 249 "\" in base name " + 250 getResourceBundle().getResourceName(), 251 getResourceBundle().getResourceName(), key); 252 } 253 254 return MessageFormat.format(msg, array); 255 } 256 } 257 | Popular Tags |