KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > utils > Messages


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 test.utils;
18
19 import org.apache.axis.i18n.MessageBundle;
20 import org.apache.axis.i18n.MessagesConstants;
21
22 import java.util.Locale JavaDoc;
23 import java.util.MissingResourceException JavaDoc;
24 import java.util.ResourceBundle JavaDoc;
25
26
27 /**
28  * @see org.apache.axis.i18n.Messages
29  *
30  * Changed projectName to local package (test.utils).
31  *
32  * @author Richard A. Sitze (rsitze@us.ibm.com)
33  * @author Karl Moss (kmoss@macromedia.com)
34  * @author Glen Daniels (gdaniels@apache.org)
35  */

36 public class Messages {
37     private static final Class JavaDoc thisClass = Messages.class;
38
39     private static final String JavaDoc projectName = "test.utils";
40
41     private static final String JavaDoc resourceName = MessagesConstants.resourceName;
42     private static final Locale JavaDoc locale = MessagesConstants.locale;
43
44     private static final String JavaDoc packageName = getPackage(thisClass.getName());
45     private static final ClassLoader JavaDoc classLoader = thisClass.getClassLoader();
46
47     private static final ResourceBundle JavaDoc parent =
48         (MessagesConstants.rootPackageName == packageName)
49         ? null
50         : MessagesConstants.rootBundle;
51
52
53     /***** NO NEED TO CHANGE ANYTHING BELOW *****/
54
55     private static final MessageBundle messageBundle =
56         new MessageBundle(projectName, packageName, resourceName,
57                                      locale, classLoader, parent);
58
59     /**
60       * Get a message from resource.properties from the package of the given object.
61       * @param caller The calling object, used to get the package name and class loader
62       * @param locale The locale
63       * @param key The resource key
64       * @return The formatted message
65       */

66     public static String JavaDoc getMessage(String JavaDoc key)
67         throws MissingResourceException JavaDoc
68     {
69         return messageBundle.getMessage(key);
70     }
71
72     /**
73       * Get a message from resource.properties from the package of the given object.
74       * @param caller The calling object, used to get the package name and class loader
75       * @param locale The locale
76       * @param key The resource key
77       * @param arg0 The argument to place in variable {0}
78       * @return The formatted message
79       */

80     public static String JavaDoc getMessage(String JavaDoc key, String JavaDoc arg0)
81         throws MissingResourceException JavaDoc
82     {
83         return messageBundle.getMessage(key, arg0);
84     }
85
86     /**
87       * Get a message from resource.properties from the package of the given object.
88       * @param caller The calling object, used to get the package name and class loader
89       * @param locale The locale
90       * @param key The resource key
91       * @param arg0 The argument to place in variable {0}
92       * @param arg1 The argument to place in variable {1}
93       * @return The formatted message
94       */

95     public static String JavaDoc getMessage(String JavaDoc key, String JavaDoc arg0, String JavaDoc arg1)
96         throws MissingResourceException JavaDoc
97     {
98         return messageBundle.getMessage(key, arg0, arg1);
99     }
100
101     /**
102       * Get a message from resource.properties from the package of the given object.
103       * @param caller The calling object, used to get the package name and class loader
104       * @param locale The locale
105       * @param key The resource key
106       * @param arg0 The argument to place in variable {0}
107       * @param arg1 The argument to place in variable {1}
108       * @param arg2 The argument to place in variable {2}
109       * @return The formatted message
110       */

111     public static String JavaDoc getMessage(String JavaDoc key, String JavaDoc arg0, String JavaDoc arg1, String JavaDoc arg2)
112         throws MissingResourceException JavaDoc
113     {
114         return messageBundle.getMessage(key, arg0, arg1, arg2);
115     }
116
117     /**
118       * Get a message from resource.properties from the package of the given object.
119       * @param caller The calling object, used to get the package name and class loader
120       * @param locale The locale
121       * @param key The resource key
122       * @param arg0 The argument to place in variable {0}
123       * @param arg1 The argument to place in variable {1}
124       * @param arg2 The argument to place in variable {2}
125       * @param arg3 The argument to place in variable {3}
126       * @return The formatted message
127       */

128     public static String JavaDoc getMessage(String JavaDoc key, String JavaDoc arg0, String JavaDoc arg1, String JavaDoc arg2, String JavaDoc arg3)
129         throws MissingResourceException JavaDoc
130     {
131         return messageBundle.getMessage(key, arg0, arg1, arg2, arg3);
132     }
133
134     /**
135       * Get a message from resource.properties from the package of the given object.
136       * @param caller The calling object, used to get the package name and class loader
137       * @param locale The locale
138       * @param key The resource key
139       * @param arg0 The argument to place in variable {0}
140       * @param arg1 The argument to place in variable {1}
141       * @param arg2 The argument to place in variable {2}
142       * @param arg3 The argument to place in variable {3}
143       * @param arg4 The argument to place in variable {4}
144       * @return The formatted message
145       */

146     public static String JavaDoc getMessage(String JavaDoc key, String JavaDoc arg0, String JavaDoc arg1, String JavaDoc arg2, String JavaDoc arg3, String JavaDoc arg4)
147         throws MissingResourceException JavaDoc
148     {
149         return messageBundle.getMessage(key, arg0, arg1, arg2, arg3, arg4);
150     }
151
152     /**
153       * Get a message from resource.properties from the package of the given object.
154       * @param caller The calling object, used to get the package name and class loader
155       * @param locale The locale
156       * @param key The resource key
157       * @param array An array of objects to place in corresponding variables
158       * @return The formatted message
159       */

160     public static String JavaDoc getMessage(String JavaDoc key, String JavaDoc[] args)
161         throws MissingResourceException JavaDoc
162     {
163         return messageBundle.getMessage(key, args);
164     }
165     
166     public static ResourceBundle JavaDoc getResourceBundle() {
167         return messageBundle.getResourceBundle();
168     }
169     
170     public static MessageBundle getMessageBundle() {
171         return messageBundle;
172     }
173
174     private static final String JavaDoc getPackage(String JavaDoc name) {
175         return name.substring(0, name.lastIndexOf('.')).intern();
176     }
177 }
178
Popular Tags