Source Code Cross Referenced for GenericHandler.java in  » Development » Monolog » org » objectweb » util » monolog » wrapper » log4j » 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 » Development » Monolog » org.objectweb.util.monolog.wrapper.log4j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright (C) 2001-2003 France Telecom R&D
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2 of the License, or (at your option) any later version.
008:         *
009:         * This library is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */package org.objectweb.util.monolog.wrapper.log4j;
018:
019:        import org.apache.log4j.Appender;
020:        import org.apache.log4j.Layout;
021:        import org.apache.log4j.spi.ErrorHandler;
022:        import org.apache.log4j.spi.Filter;
023:        import org.apache.log4j.spi.LoggingEvent;
024:        import org.objectweb.util.monolog.api.Handler;
025:
026:        import java.util.ArrayList;
027:        import java.util.HashMap;
028:        import java.util.Iterator;
029:
030:        /**
031:         * This class is a generic implementation of the Handler interface. This class
032:         * delegates all calls on a log4j Appender. It is also an Appender interceptor.
033:         * This class can therefore be referenced into the log4j struture as an
034:         * Appender.
035:         * There are three ways to specify the inner Appender:
036:         * <ul>
037:         * <li>by the construstor with the appender instance</li>
038:         * <li>by the setAppender method with the appender instance</li>
039:         * <li>by the setAttribute method with the appender class name. This method
040:         * tries to instanciate the class, and initializes the new Appender with all
041:         * attribute which has been specified before. Even the filters and the layout
042:         * are memorized.</li>
043:         *
044:         * @author Sebastien Chassande-Barrioz
045:         */
046:        public class GenericHandler implements  Appender, Handler {
047:
048:            /**
049:             * This constant can be used to specify the class name of the inner appender
050:             */
051:            public static final String APPENDER_CLASS_NAME_ATTR = "appenderClassName";
052:
053:            /**
054:             * The inner appender
055:             */
056:            protected Appender appender = null;
057:
058:            /**
059:             * The appender name
060:             */
061:            protected String name = null;
062:
063:            /**
064:             * The properties of the appender
065:             */
066:            protected HashMap prop = null;
067:
068:            protected ArrayList filters = null;
069:            protected Layout layout = null;
070:
071:            public GenericHandler() {
072:            }
073:
074:            public GenericHandler(String name) {
075:                this .name = name;
076:            }
077:
078:            public GenericHandler(Appender a) {
079:                appender = a;
080:                prop = new HashMap();
081:            }
082:
083:            public Appender getAppender() {
084:                return appender;
085:            }
086:
087:            public void setAppender(Appender a) {
088:                appender = a;
089:                if (layout != null) {
090:                    appender.setLayout(layout);
091:                }
092:                if (filters != null) {
093:                    for (Iterator it = filters.iterator(); it.hasNext();) {
094:                        appender.addFilter((Filter) it.next());
095:                    }
096:                }
097:            }
098:
099:            // IMPLEMENTATION OF THE Appender INTERFACE //
100:            //------------------------------------------//
101:
102:            public String getName() {
103:                return name = appender.getName();
104:            }
105:
106:            public void setName(String n) {
107:                name = n;
108:                appender.setName(n);
109:            }
110:
111:            public String getType() {
112:                return "generic";
113:            }
114:
115:            public String[] getAttributeNames() {
116:                return (String[]) prop.keySet().toArray(new String[0]);
117:            }
118:
119:            public Object getAttribute(String key) {
120:                return prop.get(key);
121:            }
122:
123:            public Object setAttribute(String key, Object value) {
124:                if (APPENDER_CLASS_NAME_ATTR.equalsIgnoreCase(key)) {
125:                    try {
126:                        setAppender((Appender) Class.forName((String) value)
127:                                .newInstance());
128:                    } catch (Exception e) {
129:                    }
130:                }
131:                return null;
132:            }
133:
134:            // IMPLEMENTATION OF THE Appender INTERFACE //
135:            //------------------------------------------//
136:
137:            public void addFilter(Filter newFilter) {
138:                if (appender != null) {
139:                    appender.addFilter(newFilter);
140:                } else {
141:                    if (filters == null)
142:                        filters = new ArrayList();
143:                    filters.add(newFilter);
144:                }
145:            }
146:
147:            public void clearFilters() {
148:                if (appender != null) {
149:                    appender.clearFilters();
150:                } else {
151:                    if (filters != null)
152:                        filters.clear();
153:                }
154:            }
155:
156:            public void close() {
157:                if (appender != null) {
158:                    appender.close();
159:                }
160:            }
161:
162:            public void doAppend(LoggingEvent event) {
163:                if (appender != null) {
164:                    appender.doAppend(event);
165:                }
166:            }
167:
168:            public void setErrorHandler(ErrorHandler errorHandler) {
169:                if (appender != null) {
170:                    appender.setErrorHandler(errorHandler);
171:                }
172:            }
173:
174:            public void setLayout(Layout layout) {
175:                if (appender != null) {
176:                    appender.setLayout(layout);
177:                } else {
178:                    this .layout = layout;
179:                }
180:            }
181:
182:            public Filter getFilter() {
183:                if (appender != null) {
184:                    return appender.getFilter();
185:                } else if (filters != null && filters.size() > 0) {
186:                    return (Filter) filters.get(0);
187:                }
188:                return null;
189:            }
190:
191:            public ErrorHandler getErrorHandler() {
192:                return (appender != null ? appender.getErrorHandler() : null);
193:            }
194:
195:            public Layout getLayout() {
196:                return layout;
197:            }
198:
199:            public boolean requiresLayout() {
200:                return (appender != null ? appender.requiresLayout() : true);
201:            }
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.