Source Code Cross Referenced for CommonsLoggingComponentMonitor.java in  » Inversion-of-Control » PicoContainer » org » picocontainer » gems » monitors » 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 » Inversion of Control » PicoContainer » org.picocontainer.gems.monitors 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*****************************************************************************
002:         * Copyright (C) PicoContainer Organization. All rights reserved.            *
003:         * ------------------------------------------------------------------------- *
004:         * The software in this package is published under the terms of the BSD      *
005:         * style license a copy of which has been included with this distribution in *
006:         * the LICENSE.txt file.                                                     *
007:         *                                                                           *
008:         * Original code by Mauro Talevi                                             *
009:         *****************************************************************************/package org.picocontainer.gems.monitors;
010:
011:        import static org.picocontainer.monitors.ComponentMonitorHelper.methodToString;
012:        import static org.picocontainer.monitors.ComponentMonitorHelper.memberToString;
013:        import static org.picocontainer.monitors.ComponentMonitorHelper.ctorToString;
014:        import static org.picocontainer.monitors.ComponentMonitorHelper.parmsToString;
015:
016:        import java.io.Serializable;
017:        import java.lang.reflect.Constructor;
018:        import java.lang.reflect.Method;
019:        import java.lang.reflect.Member;
020:
021:        import org.apache.commons.logging.Log;
022:        import org.apache.commons.logging.LogFactory;
023:        import org.picocontainer.ComponentMonitor;
024:        import org.picocontainer.ComponentAdapter;
025:        import org.picocontainer.MutablePicoContainer;
026:        import org.picocontainer.PicoContainer;
027:        import org.picocontainer.monitors.ComponentMonitorHelper;
028:        import org.picocontainer.monitors.NullComponentMonitor;
029:
030:        /**
031:         * A {@link ComponentMonitor} which writes to a Commons Logging {@link Log Log} instance.
032:         * The Log instance can either be injected or, if not set, the {@link LogFactory LogFactory}
033:         * will be used to retrieve it at every invocation of the monitor.
034:         * 
035:         * @author Paul Hammant
036:         * @author Mauro Talevi
037:         */
038:        public class CommonsLoggingComponentMonitor implements 
039:                ComponentMonitor, Serializable {
040:
041:            /**
042:             * Serialization UUID.
043:             */
044:            private static final long serialVersionUID = 5863003718112457388L;
045:
046:            /**
047:             * Commons Logger.
048:             */
049:            private Log log;
050:
051:            /**
052:             * Delegate for component monitor chains.
053:             */
054:            private final ComponentMonitor delegate;
055:
056:            /**
057:             * Creates a CommonsLoggingComponentMonitor with no Log instance set.
058:             * The {@link LogFactory LogFactory} will be used to retrieve the Log instance
059:             * at every invocation of the monitor.
060:             */
061:            public CommonsLoggingComponentMonitor() {
062:                delegate = new NullComponentMonitor();
063:            }
064:
065:            /**
066:             * Creates a CommonsLoggingComponentMonitor with a given Log instance class.
067:             * The class name is used to retrieve the Log instance.
068:             * 
069:             * @param logClass the class of the Log
070:             */
071:            public CommonsLoggingComponentMonitor(Class<?> logClass) {
072:                this (logClass.getName());
073:            }
074:
075:            /**
076:             * Creates a CommonsLoggingComponentMonitor with a given Log instance name. It uses the
077:             * {@link LogFactory LogFactory} to create the Log instance.
078:             * 
079:             * @param logName the name of the Log
080:             */
081:            public CommonsLoggingComponentMonitor(String logName) {
082:                this (LogFactory.getLog(logName));
083:            }
084:
085:            /**
086:             * Creates a CommonsLoggingComponentMonitor with a given Log instance
087:             * 
088:             * @param log the Log to write to
089:             */
090:            public CommonsLoggingComponentMonitor(Log log) {
091:                this ();
092:                this .log = log;
093:            }
094:
095:            /**
096:             * Creates a CommonsLoggingComponentMonitor with a given Log instance class.
097:             * The class name is used to retrieve the Log instance.
098:             *
099:             * @param logClass the class of the Log
100:             * @param delegate the delegate
101:             */
102:            public CommonsLoggingComponentMonitor(Class<?> logClass,
103:                    ComponentMonitor delegate) {
104:                this (logClass.getName(), delegate);
105:            }
106:
107:            /**
108:             * Creates a CommonsLoggingComponentMonitor with a given Log instance name. It uses the
109:             * {@link LogFactory LogFactory} to create the Log instance.
110:             *
111:             * @param logName the name of the Log
112:             * @param delegate the delegate
113:             */
114:            public CommonsLoggingComponentMonitor(String logName,
115:                    ComponentMonitor delegate) {
116:                this (LogFactory.getLog(logName), delegate);
117:            }
118:
119:            /**
120:             * Creates a CommonsLoggingComponentMonitor with a given Log instance
121:             *
122:             * @param log the Log to write to
123:             * @param delegate the delegate
124:             */
125:            public CommonsLoggingComponentMonitor(Log log,
126:                    ComponentMonitor delegate) {
127:                this .log = log;
128:                this .delegate = delegate;
129:            }
130:
131:            public <T> Constructor<T> instantiating(PicoContainer container,
132:                    ComponentAdapter<T> componentAdapter,
133:                    Constructor<T> constructor) {
134:                Log log = getLog(constructor);
135:                if (log.isDebugEnabled()) {
136:                    log.debug(ComponentMonitorHelper.format(
137:                            ComponentMonitorHelper.INSTANTIATING,
138:                            ctorToString(constructor)));
139:                }
140:                return delegate.instantiating(container, componentAdapter,
141:                        constructor);
142:            }
143:
144:            public <T> void instantiated(PicoContainer container,
145:                    ComponentAdapter<T> componentAdapter,
146:                    Constructor<T> constructor, Object instantiated,
147:                    Object[] parameters, long duration) {
148:                Log log = getLog(constructor);
149:                if (log.isDebugEnabled()) {
150:                    log.debug(ComponentMonitorHelper.format(
151:                            ComponentMonitorHelper.INSTANTIATED,
152:                            ctorToString(constructor), duration, instantiated
153:                                    .getClass().getName(),
154:                            parmsToString(parameters)));
155:                }
156:                delegate.instantiated(container, componentAdapter, constructor,
157:                        instantiated, parameters, duration);
158:            }
159:
160:            public <T> void instantiationFailed(PicoContainer container,
161:                    ComponentAdapter<T> componentAdapter,
162:                    Constructor<T> constructor, Exception cause) {
163:                Log log = getLog(constructor);
164:                if (log.isWarnEnabled()) {
165:                    log.warn(ComponentMonitorHelper.format(
166:                            ComponentMonitorHelper.INSTANTIATION_FAILED,
167:                            ctorToString(constructor), cause.getMessage()),
168:                            cause);
169:                }
170:                delegate.instantiationFailed(container, componentAdapter,
171:                        constructor, cause);
172:            }
173:
174:            public void invoking(PicoContainer container,
175:                    ComponentAdapter<?> componentAdapter, Member member,
176:                    Object instance) {
177:                Log log = getLog(member);
178:                if (log.isDebugEnabled()) {
179:                    log.debug(ComponentMonitorHelper.format(
180:                            ComponentMonitorHelper.INVOKING,
181:                            memberToString(member), instance));
182:                }
183:                delegate
184:                        .invoking(container, componentAdapter, member, instance);
185:            }
186:
187:            public void invoked(PicoContainer container,
188:                    ComponentAdapter<?> componentAdapter, Method method,
189:                    Object instance, long duration) {
190:                Log log = getLog(method);
191:                if (log.isDebugEnabled()) {
192:                    log.debug(ComponentMonitorHelper.format(
193:                            ComponentMonitorHelper.INVOKED,
194:                            methodToString(method), instance, duration));
195:                }
196:                delegate.invoked(container, componentAdapter, method, instance,
197:                        duration);
198:            }
199:
200:            public void invocationFailed(Member member, Object instance,
201:                    Exception cause) {
202:                Log log = getLog(member);
203:                if (log.isWarnEnabled()) {
204:                    log.warn(ComponentMonitorHelper.format(
205:                            ComponentMonitorHelper.INVOCATION_FAILED,
206:                            memberToString(member), instance, cause
207:                                    .getMessage()), cause);
208:                }
209:                delegate.invocationFailed(member, instance, cause);
210:            }
211:
212:            public void lifecycleInvocationFailed(
213:                    MutablePicoContainer container,
214:                    ComponentAdapter<?> componentAdapter, Method method,
215:                    Object instance, RuntimeException cause) {
216:                Log log = getLog(method);
217:                if (log.isWarnEnabled()) {
218:                    log.warn(ComponentMonitorHelper.format(
219:                            ComponentMonitorHelper.LIFECYCLE_INVOCATION_FAILED,
220:                            methodToString(method), instance, cause
221:                                    .getMessage()), cause);
222:                }
223:                delegate.lifecycleInvocationFailed(container, componentAdapter,
224:                        method, instance, cause);
225:            }
226:
227:            public Object noComponentFound(MutablePicoContainer container,
228:                    Object componentKey) {
229:                Log log = this .log != null ? this .log : LogFactory
230:                        .getLog(ComponentMonitor.class);
231:                if (log.isWarnEnabled()) {
232:                    log.warn(ComponentMonitorHelper.format(
233:                            ComponentMonitorHelper.NO_COMPONENT, componentKey));
234:                }
235:                return delegate.noComponentFound(container, componentKey);
236:            }
237:
238:            protected Log getLog(Member member) {
239:                if (log != null) {
240:                    return log;
241:                }
242:                return LogFactory.getLog(member.getDeclaringClass());
243:            }
244:
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.