KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > util > misc > DebugOutImpl


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 package com.sun.appserv.management.util.misc;
24
25 /**
26  */

27 public class DebugOutImpl implements DebugOut
28 {
29     private final String JavaDoc mID;
30     private boolean mDebug;
31     private DebugSink mSink;
32     
33         public
34     DebugOutImpl(
35         final String JavaDoc id,
36         final boolean debug,
37         final DebugSink sink)
38     {
39         mID = id;
40         mDebug = debug;
41         
42         mSink = sink == null ? new DebugSinkImpl( System.out ) : sink ;
43     }
44     
45         public
46     DebugOutImpl(
47         final String JavaDoc id,
48         final boolean debug )
49     {
50         this( id, debug, null );
51     }
52     
53         public String JavaDoc
54     getID()
55     {
56         return mID;
57     }
58     
59         public boolean
60     getDebug()
61     {
62         return mDebug;
63     }
64     
65         
66         public void
67     print( final Object JavaDoc o )
68     {
69         mSink.print( "" + o );
70     }
71     
72         public void
73     println( Object JavaDoc o )
74     {
75         mSink.println( "" + o );
76     }
77     
78         public String JavaDoc
79     toString( final Object JavaDoc... args )
80     {
81         return StringUtil.toString( ", ", args );
82     }
83     
84         public void
85     setDebug( final boolean debug)
86     {
87         mDebug = debug;
88     }
89     
90         public void
91     debug( final Object JavaDoc... args )
92     {
93         if ( getDebug() )
94         {
95             mSink.println( toString( args ) );
96         }
97     }
98     
99         public void
100     debugMethod(
101         final String JavaDoc methodName,
102         final Object JavaDoc... args )
103     {
104         if ( getDebug() )
105         {
106             debug( methodString( methodName, args ) );
107         }
108     }
109     
110         public void
111     debugMethod(
112         final String JavaDoc msg,
113         final String JavaDoc methodName,
114         final Object JavaDoc... args )
115     {
116         if ( getDebug() )
117         {
118             debug( methodString( methodName, args ) + ": " + msg );
119         }
120     }
121     
122   
123         public static String JavaDoc
124     methodString(
125         final String JavaDoc name,
126         final Object JavaDoc... args )
127     {
128         String JavaDoc result = null;
129         
130         if ( args == null || args.length == 0 )
131         {
132             result = name + "()";
133         }
134         else
135         {
136             final String JavaDoc argsString = StringUtil.toString( ", ", args );
137             result = StringUtil.toString( "", name, "(", argsString, ")" );
138         }
139         
140         return result;
141     }
142 }
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
Popular Tags