Source Code Cross Referenced for I18NBundle.java in  » ESB » open-esb » com » sun » jbi » ui » common » 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 » ESB » open esb » com.sun.jbi.ui.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)I18NBundle.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.ui.common;
030:
031:        import java.text.MessageFormat;
032:        import java.util.Locale;
033:        import java.util.MissingResourceException;
034:        import java.util.ResourceBundle;
035:
036:        /** This class reads the i18n strings from locale specific bundle from the
037:         * Bundle[locale].properties or bundle[locale].properties file in a specified
038:         * package. This class has methods for formating the messages.
039:         *
040:         * @author Sun Microsystems, Inc.
041:         */
042:        public class I18NBundle {
043:            /** package name */
044:            private String mBundlePackageName = null;
045:            /** resource bundle */
046:            private ResourceBundle mBundle = null;
047:
048:            /**
049:             * constructor
050:             * @param packageName packe name ( e.g. com.sun.mypackage ) in which
051:             * to look for Bundle.properties file
052:             */
053:            public I18NBundle(String packageName) {
054:                this .mBundlePackageName = packageName;
055:                this .mBundle = null;
056:
057:            }
058:
059:            /**
060:             * loads the bundle
061:             * @param bundleName bundle name
062:             * @param packageName packe name ( e.g. com.sun.mypackage ) in which
063:             * to look for Bundle.properties file
064:             */
065:            private void loadBundle(String packageName, String bundleName) {
066:
067:                String bundleBaseName = packageName + "." + bundleName;
068:                ResourceBundle resBundle = null;
069:                try {
070:                    resBundle = ResourceBundle.getBundle(bundleBaseName);
071:                } catch (MissingResourceException ex) {
072:                    // Try with locale independent defaultBundle
073:                    try {
074:                        resBundle = ResourceBundle.getBundle(bundleBaseName,
075:                                new Locale(""));
076:                    } catch (Exception anyEx) {
077:                        Util.logDebug(anyEx);
078:                    }
079:                }
080:
081:                if (resBundle != null) {
082:                    this .mBundle = resBundle;
083:                }
084:            }
085:
086:            /**
087:             * gets the loaded resource bundle
088:             * @return resource bundle
089:             */
090:            public ResourceBundle getBundle() {
091:                // lazzy init
092:                if (this .mBundle == null) {
093:                    loadBundle(this .mBundlePackageName, "Bundle");
094:                    // try to load the bundle with lower case first letter
095:                    if (this .mBundle == null) {
096:                        loadBundle(this .mBundlePackageName, "bundle");
097:                    }
098:                }
099:                return this .mBundle;
100:            }
101:
102:            /** gets the i18n message
103:             * @param aI18NMsg String.
104:             * @param aArgs Object[]
105:             * @return formated i18n string.
106:             */
107:            public static String getFormattedMessage(String aI18NMsg,
108:                    Object[] aArgs) {
109:                String formattedI18NMsg = aI18NMsg;
110:                try {
111:                    MessageFormat mf = new MessageFormat(aI18NMsg);
112:                    formattedI18NMsg = mf.format(aArgs);
113:                } catch (Exception ex) {
114:                }
115:                return formattedI18NMsg;
116:            }
117:
118:            /** gets the i18n message
119:             * @param aI18NKey i18n key
120:             * @param anArgsArray array of arguments for the formatted string
121:             * @return formatted i18n string
122:             */
123:            public String getMessage(String aI18NKey, Object[] anArgsArray) {
124:                String i18nMessage = getBundle().getString(aI18NKey);
125:                if (anArgsArray != null) {
126:                    return getFormattedMessage(i18nMessage, anArgsArray);
127:                } else {
128:                    return i18nMessage;
129:                }
130:            }
131:
132:            /** gets the i18n message
133:             * @param aI18NKey i18n key
134:             * @return i18n string
135:             */
136:            public String getMessage(String aI18NKey) {
137:                return getMessage(aI18NKey, null);
138:            }
139:
140:            /** gets the i18n message
141:             * @param aI18NKey i18n key
142:             * @param arg1 argrument object to message
143:             * @return i18n string
144:             */
145:            public String getMessage(String aI18NKey, Object arg1) {
146:                Object[] args = { arg1 };
147:                return getMessage(aI18NKey, args);
148:            }
149:
150:            /** gets the i18n message
151:             * @param aI18NKey i18n key
152:             * @param arg1 argrument object to message
153:             * @param arg2 argrument object to message
154:             * @return i18n string
155:             */
156:            public String getMessage(String aI18NKey, Object arg1, Object arg2) {
157:                Object[] args = { arg1, arg2 };
158:                return getMessage(aI18NKey, args);
159:            }
160:
161:            /** gets the i18n message
162:             * @param aI18NKey i18n key
163:             * @param arg1 argrument object to message
164:             * @param arg2 argrument object to message
165:             * @param arg3 argrument object to message
166:             * @return i18n string
167:             */
168:            public String getMessage(String aI18NKey, Object arg1, Object arg2,
169:                    Object arg3) {
170:                Object[] args = { arg1, arg2, arg3 };
171:                return getMessage(aI18NKey, args);
172:            }
173:
174:            /**
175:             * main
176:             * @param args string array.
177:             */
178:            public static void main(String[] args) {
179:                Locale l = new Locale("");
180:                System.out.println("Locale : " + l);
181:                System.out.println("Default Locale : " + Locale.getDefault());
182:                I18NBundle bundle = new I18NBundle("com.sun.jbi.ui.ant");
183:                System.out.println(bundle.getMessage(
184:                        "jbi.ui.ant.jmx.msg.jmxmp.connected",
185:                        new String[] { "xyz" }));
186:            }
187:
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.