Source Code Cross Referenced for PrintWriterImpl.java in  » Development » Monolog » org » objectweb » util » monolog » wrapper » printwriter » 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.printwriter 
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.printwriter;
018:
019:        import org.objectweb.util.monolog.api.Logger;
020:        import org.objectweb.util.monolog.api.BasicLevel;
021:        import org.objectweb.util.monolog.api.Loggable;
022:        import org.objectweb.util.monolog.api.LoggerFactory;
023:
024:        import java.io.PrintWriter;
025:
026:        /**
027:         * This class is a PrintWriter wrapper. It exports the PrintWriter methods but
028:         * fowards the message to a Logger. This implementation bufferizes the data when
029:         * a print method is used. The buffer and the data are always written when a
030:         * println method is used. No end of line are inserted by the println methods.
031:         * A line is equals to a monolog message.
032:         *
033:         * @author Sebastien Chassande-Barrioz
034:         */
035:        public class PrintWriterImpl extends PrintWriter implements  Loggable {
036:
037:            //private static Writer empty = new EmptyWriter();
038:
039:            /**
040:             * The inner logger instance
041:             */
042:            protected Logger logger = null;
043:            protected LoggerFactory loggerFactory = null;
044:
045:            protected int level;
046:
047:            /**
048:             * This field is the buffer which represents the current line.
049:             */
050:            protected String currentLine = "";
051:
052:            /**
053:             * This field indicates the setError method was called.
054:             */
055:            protected boolean errors = false;
056:
057:            /**
058:             * It builds a PrintWriterImpl instance. The default level is DEBUG
059:             *
060:             * @param l is the logger toward which the message must be send
061:             * @throws NullPointerException if the parameter is null.
062:             */
063:            public PrintWriterImpl(Logger l) throws NullPointerException {
064:                super (new EmptyWriter());
065:                if (l == null)
066:                    throw new NullPointerException("Logger parameter is null");
067:                logger = l;
068:                level = BasicLevel.DEBUG;
069:            }
070:
071:            /**
072:             * It builds a PrintWriterImpl instance. The default level is DEBUG
073:             *
074:             * @param logger is the logger toward which the message must be send
075:             * @param loggerFactory is the loggerFactory of the logger
076:             * @throws NullPointerException if one of the parameters is null.
077:             */
078:            public PrintWriterImpl(Logger logger, LoggerFactory loggerFactory)
079:                    throws NullPointerException {
080:                this (logger);
081:                if (loggerFactory == null)
082:                    throw new NullPointerException(
083:                            "LoggerFactory parameter is null");
084:                this .loggerFactory = loggerFactory;
085:            }
086:
087:            /**
088:             * It builds a PrintWriterImpl instance.
089:             *
090:             * @param l is the logger toward which the message must be send
091:             * @param level is the level used to log message. 
092:             * @throws NullPointerException if the parameter is null.
093:             */
094:            public PrintWriterImpl(Logger l, int level)
095:                    throws NullPointerException {
096:                super (new EmptyWriter());
097:                if (l == null)
098:                    throw new NullPointerException("Logger parameter is null");
099:                logger = l;
100:                this .level = level;
101:            }
102:
103:            public int getLevel() {
104:                return level;
105:            }
106:
107:            public void setLevel(int level) {
108:                this .level = level;
109:            }
110:
111:            // IMPLEMENTATION OF THE Loggable INTERFACE //
112:            //------------------------------------------//
113:
114:            /**
115:             * Retrieves the logger instance used
116:             */
117:            public Logger getLogger() {
118:                return logger;
119:            }
120:
121:            /**
122:             * Assigns the logger instance to use
123:             */
124:            public void setLogger(Logger logger) {
125:                this .logger = logger;
126:            }
127:
128:            /**
129:             * Retrieves the logger factory instance used
130:             */
131:            public LoggerFactory getLoggerFactory() {
132:                return loggerFactory;
133:            }
134:
135:            /**
136:             * Assigns the logger factory instance to use
137:             */
138:            public void setLoggerFactory(LoggerFactory lf) {
139:                this .loggerFactory = lf;
140:            }
141:
142:            // IMPLEMENTATION OF THE PrintWriter CLASS //
143:            //-----------------------------------------//
144:
145:            /**
146:             * Flush the stream and check its error state.
147:             */
148:            public boolean checkError() {
149:                if (currentLine.length() > 0) {
150:                    logger.log(level, currentLine);
151:                    currentLine = "";
152:                }
153:                return errors;
154:            }
155:
156:            /**
157:             * It writes the buffer if it is not empty
158:             */
159:            public void close() {
160:                if (currentLine.length() > 0) {
161:                    logger.log(level, currentLine);
162:                    currentLine = "";
163:                }
164:            }
165:
166:            /**
167:             * It writes the buffer if it is not empty
168:             */
169:            public void flush() {
170:                if (currentLine.length() > 0) {
171:                    logger.log(level, currentLine);
172:                    currentLine = "";
173:                }
174:            }
175:
176:            /**
177:             * Print a boolean value in the buffer.
178:             */
179:            public void print(boolean x) {
180:                currentLine += x;
181:            }
182:
183:            /**
184:             * Print a character in the buffer.
185:             */
186:            public void print(char x) {
187:                currentLine += x;
188:            }
189:
190:            /**
191:             * Print an array of characters in the buffer.
192:             */
193:            public void print(char[] x) {
194:                currentLine += new String(x);
195:            }
196:
197:            /**
198:             * Print a double-precision floating-point number in the buffer.
199:             */
200:            public void print(double x) {
201:                currentLine += x;
202:            }
203:
204:            /**
205:             * Print a floating-point number in the buffer.
206:             */
207:            public void print(float x) {
208:                currentLine += x;
209:            }
210:
211:            /**
212:             * Print an integer in the buffer.
213:             */
214:            public void print(int x) {
215:                currentLine += x;
216:            }
217:
218:            /**
219:             * Print a long integer in the buffer.
220:             */
221:            public void print(long x) {
222:                currentLine += x;
223:            }
224:
225:            /**
226:             * Print an object in the buffer.
227:             */
228:            public void print(Object x) {
229:                currentLine += x;
230:            }
231:
232:            /**
233:             * Print a string in the buffer.
234:             */
235:            public void print(String x) {
236:                currentLine += x;
237:            }
238:
239:            /**
240:             * Send the buffer to the logger
241:             */
242:            public void println() {
243:                logger.log(level, currentLine);
244:                currentLine = "";
245:            }
246:
247:            /**
248:             * Send the buffer and a boolean value to the logger
249:             */
250:            public void println(boolean x) {
251:                logger.log(level, currentLine + x);
252:                currentLine = "";
253:            }
254:
255:            /**
256:             * Send the buffer and a character to the logger
257:             */
258:            public void println(char x) {
259:                logger.log(level, currentLine + x);
260:                currentLine = "";
261:            }
262:
263:            /**
264:             * Send the buffer and an array of characters to the logger
265:             */
266:            public void println(char[] x) {
267:                logger.log(level, currentLine + new String(x));
268:                currentLine = "";
269:            }
270:
271:            /**
272:             * Send the buffer and a a double-precision floating-point number to the
273:             * logger.
274:             */
275:            public void println(double x) {
276:                logger.log(level, currentLine + x);
277:                currentLine = "";
278:            }
279:
280:            /**
281:             * Send the buffer and a floating-point number to the logger
282:             */
283:            public void println(float x) {
284:                logger.log(level, currentLine + x);
285:                currentLine = "";
286:            }
287:
288:            /**
289:             * Send the buffer and an integer to the logger
290:             */
291:            public void println(int x) {
292:                logger.log(level, currentLine + x);
293:                currentLine = "";
294:            }
295:
296:            /**
297:             * Send the buffer and a long integer number to the logger
298:             */
299:            public void println(long x) {
300:                logger.log(level, currentLine + x);
301:                currentLine = "";
302:            }
303:
304:            /**
305:             * Send the buffer and an object to the logger
306:             */
307:            public void println(Object x) {
308:                logger.log(level, currentLine + x);
309:                currentLine = "";
310:            }
311:
312:            /**
313:             * Send the buffer and a String to the logger
314:             */
315:            public void println(String x) {
316:                logger.log(level, currentLine + x);
317:                currentLine = "";
318:            }
319:
320:            /**
321:             * Indicate that an error has occurred.
322:             */
323:            protected void setError() {
324:                errors = true;
325:                logger.log(BasicLevel.ERROR, currentLine + "PrintWriter error");
326:                currentLine = "";
327:            }
328:
329:            /**
330:             * Write an array of characters in the buffer.
331:             */
332:            public void write(char[] buf) {
333:                currentLine += new String(buf);
334:            }
335:
336:            /**
337:             * Write a portion of an array of characters  in the buffer.
338:             */
339:            public void write(char[] buf, int off, int len) {
340:                currentLine += new String(buf, off, len);
341:            }
342:
343:            /**
344:             * Write a single character in the buffer.
345:             */
346:            public void write(int c) {
347:                currentLine += c;
348:            }
349:
350:            /**
351:             * Write a string in the buffer.
352:             */
353:            public void write(String s) {
354:                currentLine += s;
355:            }
356:
357:            /**
358:             * Write a portion of a string in the buffer.
359:             */
360:            public void write(String s, int off, int len) {
361:                currentLine += (s != null ? s.substring(off, len) : "");
362:            }
363:
364:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.