~ubuntu-branches/debian/squeeze/axis/squeeze

« back to all changes in this revision

Viewing changes to src/org/apache/axis/i18n/MessageBundle.java

  • Committer: Bazaar Package Importer
  • Author(s): Vladimír Lapáček
  • Date: 2006-09-06 22:31:39 UTC
  • Revision ID: james.westby@ubuntu.com-20060906223139-l7m5edxeositeppl
Tags: upstream-1.4
Import upstream version 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2001-2004 The Apache Software Foundation.
 
3
 * 
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
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
 
 
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
/**
 
25
 * Accept parameters for ProjectResourceBundle,
 
26
 * but defer object instantiation (and therefore
 
27
 * resource bundle loading) until required.
 
28
 * 
 
29
 * @author Richard A. Sitze (rsitze@us.ibm.com)
 
30
 * @author Karl Moss (kmoss@macromedia.com)
 
31
 * @author Glen Daniels (gdaniels@apache.org)
 
32
 */
 
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
    /**
 
60
     * Construct a new ExtendMessages
 
61
     */
 
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
    /**
 
79
      * Gets a string message from the resource bundle for the given key
 
80
      * @param key The resource key
 
81
      * @return The message
 
82
      */
 
83
    public String getMessage(String key) throws MissingResourceException
 
84
    {
 
85
        return getMessage(key, (String[]) null);
 
86
    }
 
87
 
 
88
    /**
 
89
      * <p>Gets a string message from the resource bundle for the given key. The
 
90
      * message may contain variables that will be substituted with the given
 
91
      * arguments. Variables have the format:</p>
 
92
      * <dir>
 
93
      * This message has two variables: {0} and {1}
 
94
      * </dir>
 
95
      * @param key The resource key
 
96
      * @param arg0 The argument to place in variable {0}
 
97
      * @return The message
 
98
      */
 
99
    public String getMessage(String key, String arg0) throws MissingResourceException
 
100
    {
 
101
        return getMessage(key, new String[] { arg0 });
 
102
    }
 
103
 
 
104
    /**
 
105
      * <p>Gets a string message from the resource bundle for the given key. The
 
106
      * message may contain variables that will be substituted with the given
 
107
      * arguments. Variables have the format:</p>
 
108
      * <dir>
 
109
      * This message has two variables: {0} and {1}
 
110
      * </dir>
 
111
      * @param key The resource key
 
112
      * @param arg0 The argument to place in variable {0}
 
113
      * @param arg1 The argument to place in variable {1}
 
114
      * @return The message
 
115
      */
 
116
    public String getMessage(String key, String arg0, String arg1) throws MissingResourceException
 
117
    {
 
118
        return getMessage(key, new String[] { arg0, arg1 });
 
119
    }
 
120
 
 
121
    /**
 
122
      * <p>Gets a string message from the resource bundle for the given key. The
 
123
      * message may contain variables that will be substituted with the given
 
124
      * arguments. Variables have the format:</p>
 
125
      * <dir>
 
126
      * This message has two variables: {0} and {1}
 
127
      * </dir>
 
128
      * @param key The resource key
 
129
      * @param arg0 The argument to place in variable {0}
 
130
      * @param arg1 The argument to place in variable {1}
 
131
      * @param arg2 The argument to place in variable {2}
 
132
      * @return The message
 
133
      */
 
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
    /**
 
140
      * <p>Gets a string message from the resource bundle for the given key. The
 
141
      * message may contain variables that will be substituted with the given
 
142
      * arguments. Variables have the format:</p>
 
143
      * <dir>
 
144
      * This message has two variables: {0} and {1}
 
145
      * </dir>
 
146
      * @param key The resource key
 
147
      * @param arg0 The argument to place in variable {0}
 
148
      * @param arg1 The argument to place in variable {1}
 
149
      * @param arg2 The argument to place in variable {2}
 
150
      * @param arg3 The argument to place in variable {3}
 
151
      * @return The message
 
152
      */
 
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
    /**
 
159
      * <p>Gets a string message from the resource bundle for the given key. The
 
160
      * message may contain variables that will be substituted with the given
 
161
      * arguments. Variables have the format:</p>
 
162
      * <dir>
 
163
      * This message has two variables: {0} and {1}
 
164
      * </dir>
 
165
      * @param key The resource key
 
166
      * @param arg0 The argument to place in variable {0}
 
167
      * @param arg1 The argument to place in variable {1}
 
168
      * @param arg2 The argument to place in variable {2}
 
169
      * @param arg3 The argument to place in variable {3}
 
170
      * @param arg4 The argument to place in variable {4}
 
171
      * @return The message
 
172
      */
 
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
    /**
 
179
      * <p>Gets a string message from the resource bundle for the given key. The
 
180
      * message may contain variables that will be substituted with the given
 
181
      * arguments. Variables have the format:</p>
 
182
      * <dir>
 
183
      * This message has two variables: {0} and {1}
 
184
      * </dir>
 
185
      * @param key The resource key
 
186
      * @param array An array of objects to place in corresponding variables
 
187
      * @return The message
 
188
      */
 
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
}