Source Code Cross Referenced for ServiceLogger.java in  » Web-Framework » Tapestry » org » apache » tapestry » ioc » internal » services » 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 » Web Framework » Tapestry » org.apache.tapestry.ioc.internal.services 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright 2006 The Apache Software Foundation
002:        //
003:        // Licensed under the Apache License, Version 2.0 (the "License");
004:        // you may not use this file except in compliance with the License.
005:        // You may obtain a copy of the License at
006:        //
007:        //     http://www.apache.org/licenses/LICENSE-2.0
008:        //
009:        // Unless required by applicable law or agreed to in writing, software
010:        // distributed under the License is distributed on an "AS IS" BASIS,
011:        // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        // See the License for the specific language governing permissions and
013:        // limitations under the License.
014:
015:        package org.apache.tapestry.ioc.internal.services;
016:
017:        import static java.lang.String.format;
018:
019:        import java.util.Iterator;
020:
021:        import org.apache.commons.logging.Log;
022:        import org.apache.tapestry.ioc.internal.util.Defense;
023:        import org.apache.tapestry.ioc.services.ExceptionTracker;
024:
025:        /**
026:         * Used by {@link org.apache.tapestry.ioc.internal.services.LoggingDecoratorImpl} to delegate out
027:         * logging behavior to a seperate object (helps ensure no naming conflicts).
028:         */
029:        public final class ServiceLogger {
030:            private final Log _log;
031:
032:            private final ExceptionTracker _exceptionTracker;
033:
034:            private static final String ENTER = "ENTER";
035:
036:            private static final String EXIT = " EXIT";
037:
038:            private static final String FAIL = " FAIL";
039:
040:            public ServiceLogger(Log log, ExceptionTracker exceptionTracker) {
041:                _log = log;
042:                _exceptionTracker = exceptionTracker;
043:            }
044:
045:            /** Returns true if the debugging is enabled for the underlying Log. */
046:            public boolean isDebugEnabled() {
047:                return _log.isDebugEnabled();
048:            }
049:
050:            /**
051:             * Invoked when a method is first entered
052:             * 
053:             * @param name
054:             *            of the method
055:             * @param arguments
056:             */
057:            public void entry(String name, Object[] arguments) {
058:                StringBuilder buffer = new StringBuilder();
059:
060:                buffer.append(format("[%s] %s(", ENTER, name));
061:
062:                for (int i = 0; i < arguments.length; i++) {
063:                    if (i > 0)
064:                        buffer.append(", ");
065:
066:                    convert(buffer, arguments[i]);
067:                }
068:
069:                buffer.append(")");
070:
071:                _log.debug(buffer.toString());
072:            }
073:
074:            private void convert(StringBuilder buffer, Object object) {
075:                if (object == null) {
076:                    buffer.append("null");
077:                    return;
078:                }
079:
080:                // Minimal, alas: Doesn't handle embedded quotes and other
081:                // characters. Really want to convert the string back to what it
082:                // would look like as source code.
083:
084:                if (object instanceof  String) {
085:                    buffer.append("\"");
086:                    buffer.append(object.toString());
087:                    buffer.append("\"");
088:                    return;
089:                }
090:
091:                if (object instanceof  Object[]) {
092:                    Object[] values = (Object[]) object;
093:                    buffer.append('{');
094:
095:                    for (int i = 0; i < values.length; i++) {
096:                        if (i > 0)
097:                            buffer.append(", ");
098:
099:                        convert(buffer, values[i]);
100:                    }
101:
102:                    buffer.append('}');
103:                    return;
104:                }
105:
106:                if (object instanceof  Iterable) {
107:                    Iterable itr = (Iterable) object;
108:                    boolean first = true;
109:
110:                    buffer.append('[');
111:                    Iterator i = itr.iterator();
112:                    while (i.hasNext()) {
113:                        if (!first)
114:                            buffer.append(", ");
115:
116:                        convert(buffer, i.next());
117:                        first = false;
118:                    }
119:                    buffer.append(']');
120:                    return;
121:                }
122:
123:                // Might need to add a few more, for things like character values ...
124:
125:                buffer.append(object.toString());
126:            }
127:
128:            /**
129:             * Invoked when a method returns a value
130:             * 
131:             * @param name
132:             *            of the method
133:             * @param result
134:             *            the return value for the method invocation
135:             */
136:            public void exit(String name, Object result) {
137:                Defense.notNull(name, "name");
138:
139:                StringBuilder buffer = new StringBuilder();
140:
141:                buffer.append(format("[%s] %s [", EXIT, name));
142:
143:                convert(buffer, result);
144:
145:                buffer.append(']');
146:
147:                _log.debug(buffer.toString());
148:            }
149:
150:            /** Invoked when void method finishes succesfully. */
151:            public void voidExit(String name) {
152:                _log.debug(format("[%s] %s", EXIT, name));
153:            }
154:
155:            /** Invoked when method invocation instead throws an exception. */
156:            public void fail(String name, Throwable t) {
157:                if (_log.isDebugEnabled()) {
158:                    _log.debug(format("[%s] %s -- %s", FAIL, name, t.getClass()
159:                            .getName()),
160:                            _exceptionTracker.exceptionLogged(t) ? null : t);
161:                }
162:            }
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.