Source Code Cross Referenced for Util.java in  » ESB » open-esb » com » sun » jbi » 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.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:         * @(#)Util.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.common;
030:
031:        import com.sun.jbi.StringTranslator;
032:        import com.sun.jbi.common.management.ManagementMessageBuilder;
033:        import com.sun.jbi.common.management.ManagementMessageBuilderImpl;
034:
035:        import java.io.PrintWriter;
036:        import java.io.StringWriter;
037:
038:        import java.util.HashMap;
039:        import java.util.logging.Level;
040:        import java.util.logging.Logger;
041:
042:        /**
043:         * This is an utility class which provides an interface to access the string tran
044:         *
045:         * @author Sun Microsystems, Inc.
046:         */
047:        public class Util {
048:            /**
049:             * Table of handles to StringTranslators.
050:             */
051:            private static HashMap sStringTranslators;
052:
053:            /**
054:             * StringTranslator for the common utility.
055:             */
056:            private static StringTranslator sTranslator;
057:
058:            /**
059:             * Handle to the Logger instance.
060:             */
061:            private static Logger sLogger;
062:
063:            static {
064:                sStringTranslators = new HashMap();
065:                sLogger = Logger.getLogger("com.sun.jbi.common");
066:                sTranslator = new StringTranslatorImpl("com.sun.jbi.common",
067:                        null);
068:                sStringTranslators.put("com.sun.jbi.common", sTranslator);
069:            }
070:
071:            /**
072:             * A helper method to efficiently log an internationalized message. The method uses
073:             * the StringTranslator to get the internationalized only if the configured log
074:             * level is greater than or equal to the prescribed log level. It is recommended
075:             * that clients use
076:             * <pre><code>
077:             *      Util.log( stringTranslator, logger, Level.FINE, key);
078:             *  </code></pre>
079:             * instead of
080:             * <pre> <code>
081:             *      logger.fine(stringTranslator.getString(key));
082:             * </code></pre>
083:             *
084:             * @param stringTranslator the stringTranslator implementation to be used
085:             * @param logger the logger instance to be used
086:             * @param level the prescribed log level
087:             * @param key the key to the localized string in the resource bundle
088:             */
089:            public static void log(StringTranslator stringTranslator,
090:                    Logger logger, Level level, String key) {
091:                if (logger.isLoggable(level)) {
092:                    logger.log(level, stringTranslator.getString(key));
093:                }
094:            }
095:
096:            /**
097:             * A helper method to efficiently log an internationalized message. The method uses
098:             * the StringTranslator to get the internationalized only if the configured log
099:             * level is greater than or equal to the prescribed log level. This is a helper
100:             * method which can be used when the inserts length is 1.
101:             *
102:             * @param stringTranslator the stringTranslator implementation to be used
103:             * @param logger the logger instance to be used
104:             * @param level the prescribed log level
105:             * @param key the key to the localized string in the resource bundle
106:             * @param insert the object value to be inserted.
107:             */
108:            public static void log(StringTranslator stringTranslator,
109:                    Logger logger, Level level, String key, Object insert) {
110:                if (logger.isLoggable(level)) {
111:                    Object[] inserts = new Object[1];
112:                    inserts[0] = insert;
113:                    logger.log(level, stringTranslator.getString(key, inserts));
114:                }
115:            }
116:
117:            /**
118:             * A helper method to efficiently log an internationalized message. The method uses
119:             * the StringTranslator to get the internationalized only if the configured log
120:             * level is greater than or equal to the prescribed log level. This is a helper
121:             * method which can be used when the inserts length is 2.
122:             *
123:             * @param stringTranslator the stringTranslator implementation to be used
124:             * @param logger the logger instance to be used
125:             * @param level the prescribed log level
126:             * @param key the key to the localized string in the resource bundle
127:             * @param insert1 the first object value to be inserted.
128:             * @param insert2 the second object value to be inserted.
129:             */
130:            public static void log(StringTranslator stringTranslator,
131:                    Logger logger, Level level, String key, Object insert1,
132:                    Object insert2) {
133:                if (logger.isLoggable(level)) {
134:                    Object[] inserts = new Object[2];
135:                    inserts[0] = insert1;
136:                    inserts[1] = insert2;
137:                    logger.log(level, stringTranslator.getString(key, inserts));
138:                }
139:            }
140:
141:            /**
142:             * A helper method to efficiently log an internationalized message. The method uses
143:             * the StringTranslator to get the internationalized only if the configured log
144:             * level is greater than or equal to the prescribed log level. It is recommended
145:             * that clients use
146:             * <pre><code>
147:             *      Util.log( stringTranslator, logger, Level.FINE, key, inserts);
148:             *  </code></pre>
149:             * instead of
150:             * <pre> <code>
151:             *      logger.fine(stringTranslator.getString(key, inserts));
152:             * </code></pre>
153:             *
154:             * @param stringTranslator the stringTranslator implementation to be used
155:             * @param logger the logger instance to be used
156:             * @param level the prescribed log level
157:             * @param key the key to the localized string in the resource bundle
158:             * @param inserts the array of message inserts.
159:             */
160:            public static void log(StringTranslator stringTranslator,
161:                    Logger logger, Level level, String key, Object[] inserts) {
162:                if (logger.isLoggable(level)) {
163:                    logger.log(level, stringTranslator.getString(key, inserts));
164:                }
165:            }
166:
167:            /**
168:             * Get the StringTranslator for a specified package name.
169:             *
170:             * @param packageName - the name of the package containing the resource bundle to be
171:             *        used by this StringTranslator.    
172:             *
173:             * @return The StringTranslator instance.
174:             */
175:            public static synchronized StringTranslator getStringTranslator(
176:                    String packageName) {
177:                sLogger.fine(sTranslator.getString(
178:                        "EC_STRING_TRANSLATOR_REQUESTED", packageName));
179:
180:                StringTranslator translator = (StringTranslator) sStringTranslators
181:                        .get(packageName);
182:
183:                if (null == translator) {
184:                    translator = new StringTranslatorImpl(packageName, null);
185:                    sStringTranslators.put(packageName, translator);
186:                    sLogger.finer(sTranslator.getString(
187:                            "EC_STRING_TRANSLATOR_CREATED", packageName));
188:                }
189:
190:                return translator;
191:            }
192:
193:            /**
194:             * Get the StringTranslator for a specified object.
195:             *
196:             * @param object - an object in the package that contains the resource bundle to be
197:             *        used for this StringTranslator.
198:             *
199:             * @return The StringTranslator instance.
200:             */
201:            public static StringTranslator getStringTranslatorFor(Object object) {
202:                return getStringTranslator(object.getClass().getPackage()
203:                        .getName());
204:            }
205:
206:            /**
207:             * Logs the exception stack trace using the defined logger instance at the prescribed
208:             * level.
209:             *
210:             * @param exception exception instance thrown by the application.
211:             * @param logger logger instance to be used.
212:             * @param level prescribed level.
213:             */
214:            public static void logExceptionTrace(Exception exception,
215:                    Logger logger, Level level) {
216:                if (logger.isLoggable(level)) {
217:                    StringWriter stringWriter = new StringWriter();
218:                    PrintWriter printWriter = new PrintWriter(stringWriter);
219:                    exception.printStackTrace(printWriter);
220:                    logger.log(level, stringWriter.toString());
221:                    printWriter.close();
222:                }
223:            }
224:
225:            /**
226:             * Logs the exception stack trace using the defined logger. It logs the
227:             * exception trace using a default level of SEVERE.
228:             *
229:             * @param exception exception instance thrown by the application.
230:             * @param logger logger instance to be used
231:             */
232:            public static void logExceptionTrace(Exception exception,
233:                    Logger logger) {
234:                logExceptionTrace(exception, logger, Level.SEVERE);
235:            }
236:
237:            /**
238:             * Creates a new management message builder instance.
239:             *
240:             * @return a management message builder implementation instance.
241:             */
242:            public static ManagementMessageBuilder createManagementMessageBuilder() {
243:                return new ManagementMessageBuilderImpl();
244:            }
245:
246:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.