Source Code Cross Referenced for Util.java in  » Workflow-Engines » Dalma » 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 » Workflow Engines » Dalma » com.sun.jbi.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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