1 16 17 package org.apache.axis.i18n; 18 19 import java.text.MessageFormat ; 20 import java.util.Locale ; 21 import java.util.MissingResourceException ; 22 import java.util.ResourceBundle ; 23 24 33 public class MessageBundle { 34 private boolean loaded = false; 35 36 private ProjectResourceBundle _resourceBundle = null; 37 38 private final String projectName; 39 private final String packageName; 40 private final String resourceName; 41 private final Locale locale; 42 private final ClassLoader classLoader; 43 private final ResourceBundle parent; 44 45 46 public final ProjectResourceBundle getResourceBundle() { 47 if (!loaded) { 48 _resourceBundle = ProjectResourceBundle.getBundle(projectName, 49 packageName, 50 resourceName, 51 locale, 52 classLoader, 53 parent); 54 loaded = true; 55 } 56 return _resourceBundle; 57 } 58 59 62 public MessageBundle(String projectName, 63 String packageName, 64 String resourceName, 65 Locale locale, 66 ClassLoader classLoader, 67 ResourceBundle parent) 68 throws MissingResourceException 69 { 70 this.projectName = projectName; 71 this.packageName = packageName; 72 this.resourceName = resourceName; 73 this.locale = locale; 74 this.classLoader = classLoader; 75 this.parent = parent; 76 } 77 78 83 public String getMessage(String key) throws MissingResourceException 84 { 85 return getMessage(key, (String []) null); 86 } 87 88 99 public String getMessage(String key, String arg0) throws MissingResourceException 100 { 101 return getMessage(key, new String [] { arg0 }); 102 } 103 104 116 public String getMessage(String key, String arg0, String arg1) throws MissingResourceException 117 { 118 return getMessage(key, new String [] { arg0, arg1 }); 119 } 120 121 134 public String getMessage(String key, String arg0, String arg1, String arg2) throws MissingResourceException 135 { 136 return getMessage(key, new String [] { arg0, arg1, arg2 }); 137 } 138 139 153 public String getMessage(String key, String arg0, String arg1, String arg2, String arg3) throws MissingResourceException 154 { 155 return getMessage(key, new String [] { arg0, arg1, arg2, arg3 }); 156 } 157 158 173 public String getMessage(String key, String arg0, String arg1, String arg2, String arg3, String arg4) throws MissingResourceException 174 { 175 return getMessage(key, new String [] { arg0, arg1, arg2, arg3, arg4 }); 176 } 177 178 189 public String getMessage(String key, String [] array) throws MissingResourceException 190 { 191 String msg = null; 192 if (getResourceBundle() != null) { 193 msg = getResourceBundle().getString(key); 194 } 195 196 if (msg == null) { 197 throw new MissingResourceException ("Cannot find resource key \"" + key + 198 "\" in base name " + 199 getResourceBundle().getResourceName(), 200 getResourceBundle().getResourceName(), key); 201 } 202 203 return MessageFormat.format(msg, array); 204 } 205 } 206 | Popular Tags |