KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > utils > Messages


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55
56 package org.jboss.axis.utils;
57
58 import org.jboss.axis.i18n.MessageBundle;
59 import org.jboss.axis.i18n.MessagesConstants;
60
61 import java.util.Locale JavaDoc;
62 import java.util.MissingResourceException JavaDoc;
63 import java.util.ResourceBundle JavaDoc;
64
65 /**
66  * @author Richard A. Sitze (rsitze@us.ibm.com)
67  * @author Karl Moss (kmoss@macromedia.com)
68  * @author Glen Daniels (gdaniels@macromedia.com)
69  * @see org.jboss.axis.i18n.Messages
70  */

71 public class Messages
72 {
73    private static final Class JavaDoc thisClass = Messages.class;
74
75    private static final String JavaDoc projectName = MessagesConstants.projectName;
76
77    private static final String JavaDoc resourceName = MessagesConstants.resourceName;
78    private static final Locale JavaDoc locale = MessagesConstants.locale;
79
80    private static final String JavaDoc packageName = getPackage(thisClass.getName());
81    private static final ClassLoader JavaDoc classLoader = thisClass.getClassLoader();
82
83    private static final ResourceBundle JavaDoc parent =
84            (MessagesConstants.rootPackageName == packageName)
85            ? null
86            : MessagesConstants.rootBundle;
87
88
89    /**
90     * ** NO NEED TO CHANGE ANYTHING BELOW ****
91     */

92
93    private static final MessageBundle messageBundle =
94            new MessageBundle(projectName, packageName, resourceName,
95                    locale, classLoader, parent);
96
97    /**
98     * Get a message from resource.properties from the package of the given object.
99     *
100     * @param caller The calling object, used to get the package name and class loader
101     * @param locale The locale
102     * @param key The resource key
103     * @return The formatted message
104     */

105    public static String JavaDoc getMessage(String JavaDoc key)
106            throws MissingResourceException JavaDoc
107    {
108       return messageBundle.getMessage(key);
109    }
110
111    /**
112     * Get a message from resource.properties from the package of the given object.
113     *
114     * @param caller The calling object, used to get the package name and class loader
115     * @param locale The locale
116     * @param key The resource key
117     * @param arg0 The argument to place in variable {0}
118     * @return The formatted message
119     */

120    public static String JavaDoc getMessage(String JavaDoc key, String JavaDoc arg0)
121            throws MissingResourceException JavaDoc
122    {
123       return messageBundle.getMessage(key, arg0);
124    }
125
126    /**
127     * Get a message from resource.properties from the package of the given object.
128     *
129     * @param caller The calling object, used to get the package name and class loader
130     * @param locale The locale
131     * @param key The resource key
132     * @param arg0 The argument to place in variable {0}
133     * @param arg1 The argument to place in variable {1}
134     * @return The formatted message
135     */

136    public static String JavaDoc getMessage(String JavaDoc key, String JavaDoc arg0, String JavaDoc arg1)
137            throws MissingResourceException JavaDoc
138    {
139       return messageBundle.getMessage(key, arg0, arg1);
140    }
141
142    /**
143     * Get a message from resource.properties from the package of the given object.
144     *
145     * @param caller The calling object, used to get the package name and class loader
146     * @param locale The locale
147     * @param key The resource key
148     * @param arg0 The argument to place in variable {0}
149     * @param arg1 The argument to place in variable {1}
150     * @param arg2 The argument to place in variable {2}
151     * @return The formatted message
152     */

153    public static String JavaDoc getMessage(String JavaDoc key, String JavaDoc arg0, String JavaDoc arg1, String JavaDoc arg2)
154            throws MissingResourceException JavaDoc
155    {
156       return messageBundle.getMessage(key, arg0, arg1, arg2);
157    }
158
159    /**
160     * Get a message from resource.properties from the package of the given object.
161     *
162     * @param caller The calling object, used to get the package name and class loader
163     * @param locale The locale
164     * @param key The resource key
165     * @param arg0 The argument to place in variable {0}
166     * @param arg1 The argument to place in variable {1}
167     * @param arg2 The argument to place in variable {2}
168     * @param arg3 The argument to place in variable {3}
169     * @return The formatted message
170     */

171    public static String JavaDoc getMessage(String JavaDoc key, String JavaDoc arg0, String JavaDoc arg1, String JavaDoc arg2, String JavaDoc arg3)
172            throws MissingResourceException JavaDoc
173    {
174       return messageBundle.getMessage(key, arg0, arg1, arg2, arg3);
175    }
176
177    /**
178     * Get a message from resource.properties from the package of the given object.
179     *
180     * @param caller The calling object, used to get the package name and class loader
181     * @param locale The locale
182     * @param key The resource key
183     * @param arg0 The argument to place in variable {0}
184     * @param arg1 The argument to place in variable {1}
185     * @param arg2 The argument to place in variable {2}
186     * @param arg3 The argument to place in variable {3}
187     * @param arg4 The argument to place in variable {4}
188     * @return The formatted message
189     */

190    public static String JavaDoc getMessage(String JavaDoc key, String JavaDoc arg0, String JavaDoc arg1, String JavaDoc arg2, String JavaDoc arg3, String JavaDoc arg4)
191            throws MissingResourceException JavaDoc
192    {
193       return messageBundle.getMessage(key, arg0, arg1, arg2, arg3, arg4);
194    }
195
196    /**
197     * Get a message from resource.properties from the package of the given object.
198     *
199     * @param caller The calling object, used to get the package name and class loader
200     * @param locale The locale
201     * @param key The resource key
202     * @param array An array of objects to place in corresponding variables
203     * @return The formatted message
204     */

205    public static String JavaDoc getMessage(String JavaDoc key, String JavaDoc[] args)
206            throws MissingResourceException JavaDoc
207    {
208       return messageBundle.getMessage(key, args);
209    }
210
211    public static ResourceBundle JavaDoc getResourceBundle()
212    {
213       return messageBundle.getResourceBundle();
214    }
215
216    public static MessageBundle getMessageBundle()
217    {
218       return messageBundle;
219    }
220
221    private static final String JavaDoc getPackage(String JavaDoc name)
222    {
223       return name.substring(0, name.lastIndexOf('.')).intern();
224    }
225 }
226
Popular Tags