Source Code Cross Referenced for AbstractOutputTarget.java in  » Net » openfire » org » jivesoftware » util » log » output » 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 » Net » openfire » org.jivesoftware.util.log.output 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) The Apache Software Foundation. All rights reserved.
003:         *
004:         * This software is published under the terms of the Apache Software License
005:         * version 1.1, a copy of which has been included with this distribution in
006:         * the LICENSE file.
007:         */
008:        package org.jivesoftware.util.log.output;
009:
010:        import org.jivesoftware.util.log.LogEvent;
011:        import org.jivesoftware.util.log.format.Formatter;
012:
013:        /**
014:         * Abstract output target.
015:         * Any new output target that is writing to a single connected
016:         * resource should extend this class directly or indirectly.
017:         *
018:         * @author <a href="mailto:peter@apache.org">Peter Donald</a>
019:         */
020:        public abstract class AbstractOutputTarget extends AbstractTarget {
021:            /**
022:             * Formatter for target.
023:             */
024:            private Formatter m_formatter;
025:
026:            /**
027:             * Parameterless constructor.
028:             */
029:            public AbstractOutputTarget() {
030:            }
031:
032:            public AbstractOutputTarget(final Formatter formatter) {
033:                m_formatter = formatter;
034:            }
035:
036:            /**
037:             * Retrieve the associated formatter.
038:             *
039:             * @return the formatter
040:             * @deprecated Access to formatter is not advised and this method will be removed
041:             *             in future iterations. It remains only for backwards compatability.
042:             */
043:            public synchronized Formatter getFormatter() {
044:                return m_formatter;
045:            }
046:
047:            /**
048:             * Set the formatter.
049:             *
050:             * @param formatter the formatter
051:             * @deprecated In future this method will become protected access.
052:             */
053:            public synchronized void setFormatter(final Formatter formatter) {
054:                writeTail();
055:                m_formatter = formatter;
056:                writeHead();
057:            }
058:
059:            /**
060:             * Abstract method to send data.
061:             *
062:             * @param data the data to be output
063:             */
064:            protected void write(final String data) {
065:                output(data);
066:            }
067:
068:            /**
069:             * Abstract method that will output event.
070:             *
071:             * @param data the data to be output
072:             * @deprecated User should overide send() instead of output(). Output exists
073:             *             for backwards compatability and will be removed in future.
074:             */
075:            protected void output(final String data) {
076:            }
077:
078:            protected void doProcessEvent(LogEvent event) {
079:                final String data = format(event);
080:                write(data);
081:            }
082:
083:            /**
084:             * Startup log session.
085:             */
086:            protected synchronized void open() {
087:                if (!isOpen()) {
088:                    super .open();
089:                    writeHead();
090:                }
091:            }
092:
093:            /**
094:             * Shutdown target.
095:             * Attempting to send to target after close() will cause errors to be logged.
096:             */
097:            public synchronized void close() {
098:                if (isOpen()) {
099:                    writeTail();
100:                    super .close();
101:                }
102:            }
103:
104:            /**
105:             * Helper method to format an event into a string, using the formatter if available.
106:             *
107:             * @param event the LogEvent
108:             * @return the formatted string
109:             */
110:            private String format(final LogEvent event) {
111:                if (null != m_formatter) {
112:                    return m_formatter.format(event);
113:                } else {
114:                    return event.toString();
115:                }
116:            }
117:
118:            /**
119:             * Helper method to send out log head.
120:             * The head initiates a session of logging.
121:             */
122:            private void writeHead() {
123:                if (!isOpen())
124:                    return;
125:
126:                final String head = getHead();
127:                if (null != head) {
128:                    write(head);
129:                }
130:            }
131:
132:            /**
133:             * Helper method to send out log tail.
134:             * The tail completes a session of logging.
135:             */
136:            private void writeTail() {
137:                if (!isOpen())
138:                    return;
139:
140:                final String tail = getTail();
141:                if (null != tail) {
142:                    write(tail);
143:                }
144:            }
145:
146:            /**
147:             * Helper method to retrieve head for log session.
148:             * TODO: Extract from formatter
149:             *
150:             * @return the head string
151:             */
152:            private String getHead() {
153:                return null;
154:            }
155:
156:            /**
157:             * Helper method to retrieve tail for log session.
158:             * TODO: Extract from formatter
159:             *
160:             * @return the head string
161:             */
162:            private String getTail() {
163:                return null;
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.