01: package org.objectweb.celtix.common.i18n;
02:
03: import java.text.MessageFormat;
04: import java.util.MissingResourceException;
05: import java.util.ResourceBundle;
06: import java.util.logging.Logger;
07:
08: public class Message {
09: String code;
10: Object[] parameters;
11: ResourceBundle bundle;
12:
13: /**
14: * Constructor.
15: *
16: * @param key the message catalog (resource bundle) key
17: * @param logger a logger with an associated resource bundle
18: * @param params the message substitution parameters
19: */
20: public Message(String key, Logger logger, Object... params) {
21: this (key, logger.getResourceBundle(), params);
22: }
23:
24: /**
25: * Constructor.
26: *
27: * @param key the message catalog (resource bundle) key
28: * @param catalog the resource bundle
29: * @param params the message substitution parameters
30: */
31: public Message(String key, ResourceBundle catalog, Object... params) {
32: code = key;
33: bundle = catalog;
34: parameters = params;
35: }
36:
37: public String toString() {
38: String fmt = null;
39: try {
40: if (null == bundle) {
41: return code;
42: }
43: fmt = bundle.getString(code);
44: } catch (MissingResourceException ex) {
45: return code;
46: }
47: return MessageFormat.format(fmt, parameters);
48: }
49:
50: public String getCode() {
51: return code;
52: }
53:
54: public Object[] getParameters() {
55: return parameters;
56: }
57: }
|