Source Code Cross Referenced for I18n.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas_lib » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas_lib 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or 1any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * Initial developer: Florent BENOIT
022:         * --------------------------------------------------------------------------
023:         * $Id: I18n.java 4840 2004-05-28 14:02:57Z sauthieg $
024:         * --------------------------------------------------------------------------
025:         */package org.objectweb.jonas_lib;
026:
027:        import java.text.MessageFormat;
028:        import java.util.HashMap;
029:        import java.util.Locale;
030:        import java.util.Map;
031:        import java.util.MissingResourceException;
032:        import java.util.ResourceBundle;
033:
034:        /**
035:         * This class defines the way for getting message with
036:         * ResourceBundle for different language
037:         * Inspired from http://java.sun.com/docs/books/tutorial/i18n/
038:         * @author Florent Benoit
039:         */
040:        public class I18n {
041:
042:            /**
043:             * Name of the resource bundle to use
044:             */
045:            private static final String RESOURCE_BUNDLE_NAME = "I18n";
046:
047:            /**
048:             * List of our I18n objects
049:             */
050:            private static Map bundles = null;
051:
052:            /**
053:             * Internal Resource Bundle
054:             */
055:            private ResourceBundle resourceBundle = null;
056:
057:            /**
058:             * Constructor (private access, use getInstance instead)
059:             * @param packageName name of the package for the bundle
060:             * @param cl the classloader used to load bundle
061:             */
062:            private I18n(String packageName, ClassLoader cl) {
063:
064:                String bundleName = packageName + "." + RESOURCE_BUNDLE_NAME;
065:
066:                // Resource bundle is on the form packagename.I18n.properties
067:                try {
068:                    Locale locale = Locale.getDefault();
069:                    resourceBundle = ResourceBundle.getBundle(bundleName,
070:                            locale, cl);
071:                } catch (MissingResourceException mre) {
072:                    String err = "Error when trying to get a ResourceBundle for package '"
073:                            + packageName + "' : " + mre.getMessage();
074:                    throw new IllegalStateException(err);
075:                }
076:            }
077:
078:            /**
079:             * Gets the instance for a given class
080:             * @param c the class for which we want a bundle
081:             * @return I18n object
082:             */
083:            public static I18n getInstance(Class c) {
084:                return getInstance(c.getPackage().getName());
085:            }
086:
087:            /**
088:             * Gets the instance for a given class
089:             * @param c the class for which we want a bundle
090:             * @param cl the classloader used to load bundle
091:             * @return I18n object
092:             */
093:            public static I18n getInstance(Class c, ClassLoader cl) {
094:                return getInstance(c.getPackage().getName(), cl);
095:            }
096:
097:            /**
098:             * Gets the instance for a given package
099:             * @param packageName the package for which we want a bundle
100:             * @return I18n object
101:             */
102:            public static I18n getInstance(String packageName) {
103:                return getInstance(packageName, Thread.currentThread()
104:                        .getContextClassLoader());
105:            }
106:
107:            /**
108:             * Gets the instance for a given package
109:             * @param packageName the package for which we want a bundle
110:             * @param cl the classloader used to load bundle
111:             * @return I18n object
112:             */
113:            public static I18n getInstance(String packageName, ClassLoader cl) {
114:                if (bundles == null) {
115:                    bundles = new HashMap();
116:                }
117:
118:                I18n i18n = (I18n) bundles.get(packageName);
119:                if (i18n != null) {
120:                    return i18n;
121:                }
122:
123:                i18n = new I18n(packageName, cl);
124:                bundles.put(packageName, i18n);
125:                return i18n;
126:            }
127:
128:            /**
129:             * Gets the formatted string with the given arguments
130:             * @param key the keystring on which to apply arguments
131:             * @param args the object arguments for the formatter
132:             * @return the formatted string
133:             */
134:            public String getMessage(String key, Object[] args) {
135:                String value = getMessage(key);
136:                return MessageFormat.format(value, args);
137:            }
138:
139:            /**
140:             * Gets the value of the given key
141:             * @param key the keystring to retrieve
142:             * @return the value for the given key or the key if the value can not be found
143:             */
144:            public String getMessage(String key) {
145:                String ret = null;
146:
147:                // No bundle, return key
148:                if (resourceBundle == null) {
149:                    return key;
150:                }
151:
152:                try {
153:                    ret = resourceBundle.getString(key);
154:                } catch (MissingResourceException mre) {
155:                    // key not found, return the key
156:                    ret = key;
157:                }
158:
159:                return ret;
160:            }
161:
162:            /**
163:             * Gets the formatted string with the given arguments
164:             * @param key the keystring on which to apply arguments
165:             * @param obj the object argument for the formatter
166:             * @return the formatted string
167:             */
168:            public String getMessage(String key, Object obj) {
169:                return getMessage(key, new Object[] { obj });
170:            }
171:
172:            /**
173:             * Gets the formatted string with the given arguments
174:             * @param key the keystring on which to apply arguments
175:             * @param obj1 the first object argument for the formatter
176:             * @param obj2 the second object argument for the formatter
177:             * @return the formatted string
178:             */
179:            public String getMessage(String key, Object obj1, Object obj2) {
180:                return getMessage(key, new Object[] { obj1, obj2 });
181:            }
182:
183:            /**
184:             * Gets the formatted string with the given arguments
185:             * @param key the keystring on which to apply arguments
186:             * @param obj1 the first object argument for the formatter
187:             * @param obj2 the second object argument for the formatter
188:             * @param obj3 the third object argument for the formatter
189:             * @return the formatted string
190:             */
191:            public String getMessage(String key, Object obj1, Object obj2,
192:                    Object obj3) {
193:                return getMessage(key, new Object[] { obj1, obj2, obj3 });
194:            }
195:
196:            /**
197:             * Gets the formatted string with the given arguments
198:             * @param key the keystring on which to apply arguments
199:             * @param obj1 argument for the formatter
200:             * @param obj2 argument for the formatter
201:             * @param obj3 argument for the formatter
202:             * @param obj4 argument for the formatter
203:             * @return the formatted string
204:             */
205:            public String getMessage(String key, Object obj1, Object obj2,
206:                    Object obj3, Object obj4) {
207:                return getMessage(key, new Object[] { obj1, obj2, obj3, obj4 });
208:            }
209:
210:            /**
211:             * Gets the formatted string with the given arguments
212:             * @param key the keystring on which to apply arguments
213:             * @param obj1 argument for the formatter
214:             * @param obj2 argument for the formatter
215:             * @param obj3 argument for the formatter
216:             * @param obj4 argument for the formatter
217:             * @param obj5 argument for the formatter
218:             * @return the formatted string
219:             */
220:            public String getMessage(String key, Object obj1, Object obj2,
221:                    Object obj3, Object obj4, Object obj5) {
222:                return getMessage(key, new Object[] { obj1, obj2, obj3, obj4,
223:                        obj5 });
224:            }
225:
226:            /**
227:             * Gets the formatted string with the given arguments
228:             * @param key the keystring on which to apply arguments
229:             * @param obj1 argument for the formatter
230:             * @param obj2 argument for the formatter
231:             * @param obj3 argument for the formatter
232:             * @param obj4 argument for the formatter
233:             * @param obj5 argument for the formatter
234:             * @param obj6 argument for the formatter
235:             * @return the formatted string
236:             */
237:            public String getMessage(String key, Object obj1, Object obj2,
238:                    Object obj3, Object obj4, Object obj5, Object obj6) {
239:                return getMessage(key, new Object[] { obj1, obj2, obj3, obj4,
240:                        obj5, obj6 });
241:            }
242:
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.