1 23 package com.sun.appserv.management.util.misc; 24 25 27 public class DebugOutImpl implements DebugOut 28 { 29 private final String mID; 30 private boolean mDebug; 31 private DebugSink mSink; 32 33 public 34 DebugOutImpl( 35 final String 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 id, 48 final boolean debug ) 49 { 50 this( id, debug, null ); 51 } 52 53 public String 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 o ) 68 { 69 mSink.print( "" + o ); 70 } 71 72 public void 73 println( Object o ) 74 { 75 mSink.println( "" + o ); 76 } 77 78 public String 79 toString( final Object ... 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 ... args ) 92 { 93 if ( getDebug() ) 94 { 95 mSink.println( toString( args ) ); 96 } 97 } 98 99 public void 100 debugMethod( 101 final String methodName, 102 final Object ... args ) 103 { 104 if ( getDebug() ) 105 { 106 debug( methodString( methodName, args ) ); 107 } 108 } 109 110 public void 111 debugMethod( 112 final String msg, 113 final String methodName, 114 final Object ... args ) 115 { 116 if ( getDebug() ) 117 { 118 debug( methodString( methodName, args ) + ": " + msg ); 119 } 120 } 121 122 123 public static String 124 methodString( 125 final String name, 126 final Object ... args ) 127 { 128 String result = null; 129 130 if ( args == null || args.length == 0 ) 131 { 132 result = name + "()"; 133 } 134 else 135 { 136 final String 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 |