Source Code Cross Referenced for JPDALogWriter.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jpda » tests » share » 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 » Apache Harmony Java SE » org package » org.apache.harmony.jpda.tests.share 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *
015:         *  See the License for the specific language governing permissions and
016:         *  limitations under the License.
017:         */
018:
019:        /**
020:         * @author Vitaly A. Provodin
021:         * @version $Revision: 1.6 $
022:         */
023:
024:        /**
025:         * Created on 28.03.2005
026:         */package org.apache.harmony.jpda.tests.share;
027:
028:        import java.io.PrintStream;
029:
030:        import org.apache.harmony.jpda.tests.framework.LogWriter;
031:
032:        /**
033:         * This class provides logging messages to underlying output stream. There are
034:         * can be several JPDALogWriter objects writing to the same underlying stream
035:         * with different prefixes.
036:         */
037:        public class JPDALogWriter extends LogWriter {
038:
039:            protected String printPrefix;
040:
041:            protected String errorMessage;
042:
043:            protected LogStream logStream;
044:
045:            public boolean enablePrint = true;
046:
047:            /**
048:             * Constructs an instance of the class for given output stream.
049:             * 
050:             * @param outputStream
051:             *            stream for output
052:             * @param prefix
053:             *            prefix for messages or null
054:             * @param enablePrint
055:             *            flag for enabling print to log
056:             */
057:            public JPDALogWriter(PrintStream outputStream, String prefix,
058:                    boolean enablePrint) {
059:                super (prefix);
060:                this .enablePrint = enablePrint;
061:                logStream = new LogStream(outputStream);
062:            }
063:
064:            /**
065:             * Constructs an instance of the class for given output stream.
066:             * 
067:             * @param outputStream
068:             *            stream for output
069:             * @param prefix
070:             *            prefix for messages or null
071:             */
072:            public JPDALogWriter(PrintStream outputStream, String prefix) {
073:                this (outputStream, prefix, true);
074:            }
075:
076:            /**
077:             * Constructs an instance of the class to log to the same output stream.
078:             * 
079:             * @param logWriter
080:             *            log writer containing stream for output
081:             * @param prefix
082:             *            prefix for messages or null
083:             */
084:            public JPDALogWriter(JPDALogWriter logWriter, String prefix) {
085:                super (prefix);
086:                logStream = logWriter.getLogStream();
087:            }
088:
089:            /**
090:             * Sets prefix for messages.
091:             * 
092:             * @param prefix
093:             *            to be set
094:             */
095:            public void setPrefix(String prefix) {
096:                super .setPrefix(prefix);
097:                if (prefix == null || prefix.length() <= 0) {
098:                    printPrefix = "";
099:                } else {
100:                    printPrefix = prefix + "> ";
101:                }
102:            }
103:
104:            /**
105:             * Prints error message.
106:             * 
107:             * @param message
108:             *            error message to be printed
109:             */
110:            public void printError(String message) {
111:                if (null == errorMessage) {
112:                    errorMessage = message;
113:                }
114:                logStream.println(getErrorPrefix() + message);
115:            }
116:
117:            /**
118:             * Prints exception information with explaining message.
119:             * 
120:             * @param message
121:             *            explaining message to be printed
122:             * @param throwable
123:             *            exception to be printed
124:             */
125:            public void printError(String message, Throwable throwable) {
126:                if (null == errorMessage) {
127:                    errorMessage = message;
128:                }
129:                logStream
130:                        .printStackTrace(getErrorPrefix() + message, throwable);
131:            }
132:
133:            /**
134:             * Prints exception information w/o explaining message.
135:             * 
136:             * @param throwable
137:             *            exception to be printed
138:             */
139:            public void printError(Throwable throwable) {
140:                logStream.printStackTrace(null, throwable);
141:            }
142:
143:            /**
144:             * Prints message to the output stream w/o line feed.
145:             * 
146:             * @param message
147:             *            to be printed
148:             */
149:            public void print(String message) {
150:                if (enablePrint) {
151:                    logStream.print(printPrefix + message);
152:                }
153:            }
154:
155:            /**
156:             * Prints message to the output stream with line feed.
157:             * 
158:             * @param message
159:             *            to be printed
160:             */
161:            public void println(String message) {
162:                if (enablePrint) {
163:                    logStream.println(printPrefix + message);
164:                }
165:            }
166:
167:            /**
168:             * Returns saved error message.
169:             * 
170:             * @return message string
171:             */
172:            public String getErrorMessage() {
173:                return errorMessage;
174:            }
175:
176:            // /////////////////////////////////////////////////////////////////////////////
177:
178:            /**
179:             * Get prefix for error messages.
180:             */
181:            protected String getErrorPrefix() {
182:                return "# ERROR: " + printPrefix;
183:            }
184:
185:            /**
186:             * Get underlying LogStream object.
187:             */
188:            protected LogStream getLogStream() {
189:                return logStream;
190:            }
191:
192:            /**
193:             * Underlying stream with synchronous access.
194:             */
195:            protected static class LogStream {
196:                protected PrintStream outputStream;
197:
198:                /**
199:                 * A constructor.
200:                 * 
201:                 * @param outputStream
202:                 */
203:                public LogStream(PrintStream outputStream) {
204:                    setOutputStream(outputStream);
205:                }
206:
207:                /**
208:                 * @return The associated output stream.
209:                 */
210:                public synchronized PrintStream getOutputStream() {
211:                    return outputStream;
212:                }
213:
214:                /**
215:                 * Sets new output stream.
216:                 * 
217:                 * @param outputStream
218:                 *            new output stream
219:                 */
220:                public synchronized void setOutputStream(
221:                        PrintStream outputStream) {
222:                    this .outputStream = outputStream;
223:                }
224:
225:                /**
226:                 * Prints the given message with the newline to the output stream.
227:                 * 
228:                 * @param message
229:                 *            log message
230:                 */
231:                public synchronized void println(String message) {
232:                    outputStream.println(message);
233:                }
234:
235:                /**
236:                 * Prints the given message to the output stream.
237:                 * 
238:                 * @param message
239:                 *            log message
240:                 */
241:                public synchronized void print(String message) {
242:                    outputStream.print(message);
243:                    outputStream.flush();
244:                }
245:
246:                /**
247:                 * Prints the given message and the call stack of the exception to the
248:                 * output stream.
249:                 * 
250:                 * @param message
251:                 *            log message
252:                 * @param throwable
253:                 *            exception
254:                 */
255:                public synchronized void printStackTrace(String message,
256:                        Throwable throwable) {
257:                    if (message != null) {
258:                        println(message);
259:                    }
260:                    throwable.printStackTrace(outputStream);
261:                }
262:            }
263:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.