KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > util > diagnostics > ReporterWriter


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.util.diagnostics;
25
26 import java.io.*;
27 import java.util.*;
28 import com.sun.enterprise.util.StringUtils;
29
30 /** The basic mechanism used to "report".
31  *
32  * sends output to a Swing window.
33  */

34 public class ReporterWriter implements IReporterEnum
35 {
36     /** Create a new place (or mechanism) for routing output from the Reporter classes.
37      *
38      * @param title The title of the output window
39      */

40     protected ReporterWriter(String JavaDoc title)
41     {
42         this.title = title;
43         out = System.out;
44     }
45
46     ///////////////////////////////////////////////////////////////
47

48         /** puts a message in the window.
49          *
50          * Subclasses should redefine this function to change the report output destination.
51          * @param severity The severity level of the message. This is translated into one of the named constants
52          * for output.
53          * @param s The text of the message to "report".
54          */

55     protected void println(int severity, String JavaDoc s)
56     {
57         String JavaDoc type;
58         String JavaDoc msg;
59         
60         /*
61         if(severity > WARN)
62         {
63             type = "<B>" + severityNames[severity] + "</B>";
64             msg = StringUtils.padRight(type, longestSeverityLength + 7) + s;
65         }
66         else
67         */

68         {
69             type = severityNames[severity];
70             msg = StringUtils.padRight(severityNames[severity], longestSeverityLength) + s;
71         }
72
73         out.println(msg);
74         getFrame().pr(msg);
75     }
76
77     ///////////////////////////////////////////////////////////////
78

79     private ReporterFrame getFrame()
80     {
81         if(frame == null)
82         {
83             // first call!!
84
frame = new ReporterFrame(title);
85             frame.show();
86             calcLongestString();
87         }
88
89         return frame;
90     }
91
92     ///////////////////////////////////////////////////////////////
93

94     private void calcLongestString()
95     {
96         int maxLen = 0;
97
98         for(int i = 0; i < severityNames.length; i++)
99         {
100             int len = severityNames[i].length();
101
102             if(len > maxLen)
103                 maxLen = len;
104         }
105         longestSeverityLength = maxLen + 2;
106     }
107
108     ///////////////////////////////////////////////////////////////
109

110     private PrintStream out;
111     private ReporterFrame frame = null;
112     private int longestSeverityLength;
113     private String JavaDoc title;
114
115 }
116
117
Popular Tags