01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.common.i18n;
19:
20: import java.text.MessageFormat;
21: import java.util.MissingResourceException;
22: import java.util.ResourceBundle;
23: import java.util.logging.Logger;
24:
25: public class Message {
26: String code;
27: Object[] parameters;
28: ResourceBundle bundle;
29:
30: /**
31: * Constructor.
32: *
33: * @param key the message catalog (resource bundle) key
34: * @param logger a logger with an associated resource bundle
35: * @param params the message substitution parameters
36: */
37: public Message(String key, Logger logger, Object... params) {
38: this (key, logger.getResourceBundle(), params);
39: }
40:
41: /**
42: * Constructor.
43: *
44: * @param key the message catalog (resource bundle) key
45: * @param catalog the resource bundle
46: * @param params the message substitution parameters
47: */
48: public Message(String key, ResourceBundle catalog, Object... params) {
49: code = key;
50: bundle = catalog;
51: parameters = params;
52: }
53:
54: public String toString() {
55: String fmt = null;
56: try {
57: if (null == bundle) {
58: return code;
59: }
60: fmt = bundle.getString(code);
61: } catch (MissingResourceException ex) {
62: return code;
63: }
64: return MessageFormat.format(fmt, parameters);
65: }
66:
67: public String getCode() {
68: return code;
69: }
70:
71: public Object[] getParameters() {
72: return parameters;
73: }
74: }
|