01: /*
02: * Copyright 2004-2006 Fouad HAMDI.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.csvbeans.utils;
17:
18: /**
19: * Container of the internationalized messages.
20: *
21: * @author Fouad Hamdi
22: * @since 0.7
23: */
24: public class MessagesBundle {
25: private static MessagesBundle instance;
26: private MessageContainer messageContainer;
27:
28: /**
29: * Constructor.
30: * @param messageContainer the container of messages.
31: */
32: public MessagesBundle(MessageContainer messageContainer) {
33: this .messageContainer = messageContainer;
34: }
35:
36: protected static MessagesBundle instance() {
37: if (instance == null) {
38: instance = new MessagesBundle(new MessageContainerImpl());
39: }
40: return instance;
41: }
42:
43: /**
44: * Return the message associated with the specified key.
45: *
46: * @param key
47: * the message key
48: */
49: public static String getMessage(String key) {
50: return instance().getMessageContainer().getMessage(key);
51: }
52:
53: /**
54: * Return the message associated with the specified key and parameter.
55: *
56: * @param key
57: * the message key
58: * @param param
59: * the parameter
60: */
61: public static String getMessage(String key, Object param) {
62: return instance().getMessageContainer().getMessage(key, param);
63: }
64:
65: /**
66: * Return the message associated with the specified key and parameters.
67: *
68: * @param key
69: * the message key
70: * @param params
71: * the parameters
72: */
73: public static String getMessage(String key, Object[] params) {
74: return instance().getMessageContainer().getMessage(key, params);
75: }
76:
77: public MessageContainer getMessageContainer() {
78: return messageContainer;
79: }
80:
81: public static void setInstance(MessagesBundle instance) {
82: MessagesBundle.instance = instance;
83: }
84: }
|