1 19 package com.mysql.jdbc; 20 21 import java.sql.DriverManager ; 22 23 import java.util.Hashtable ; 24 import java.util.StringTokenizer ; 25 26 27 36 public class Debug { 37 private static final Hashtable CLASSES = new Hashtable (); 38 private static final Object MUTEX = new Object (); 39 private static boolean watchAll = false; 40 41 53 public static void methodCall(Object source, String method, Object [] args) { 54 synchronized (MUTEX) { 55 if (watchAll || CLASSES.contains(source.getClass().getName())) { 56 StringBuffer mesg = new StringBuffer ("\nTRACE: "); 58 mesg.append(source.toString()); 59 mesg.append("."); 60 mesg.append(method); 61 mesg.append("( "); 62 63 for (int i = 0; i < (args.length - 1); i++) { 65 if (args[i] == null) { 66 mesg.append("null"); 67 } else { 68 if (args[i] instanceof String ) { 69 mesg.append("\""); 70 } 71 72 mesg.append(args[i].toString()); 73 74 if (args[i] instanceof String ) { 75 mesg.append("\""); 76 } 77 } 78 79 mesg.append(", "); 80 } 81 82 if (args.length > 0) { 83 if (args[args.length - 1] instanceof String ) { 84 mesg.append("\""); 85 } 86 87 mesg.append(args[args.length - 1]); 88 89 if (args[args.length - 1] instanceof String ) { 90 mesg.append("\""); 91 } 92 } 93 94 mesg.append(" )\n"); 95 96 if (DriverManager.getLogStream() == null) { 97 System.out.println(mesg.toString()); 98 } else { 99 DriverManager.println(mesg.toString()); 100 } 101 } 102 } 103 } 104 105 116 public static void msg(Object source, String message) { 117 synchronized (MUTEX) { 118 if (watchAll || CLASSES.contains(source.getClass().getName())) { 119 StringBuffer mesg = new StringBuffer ("\nTRACE: "); 121 mesg.append(source.toString()); 122 mesg.append(": "); 123 mesg.append(message); 124 mesg.append("\n"); 125 126 if (DriverManager.getLogStream() == null) { 127 System.out.println(mesg.toString()); 128 } else { 129 DriverManager.println(mesg.toString()); 130 } 131 } 132 } 133 } 134 135 147 public static void returnValue(Object source, String method, Object value) { 148 synchronized (MUTEX) { 149 if (watchAll || CLASSES.contains(source.getClass().getName())) { 150 StringBuffer mesg = new StringBuffer ("\nTRACE: "); 152 mesg.append(source.toString()); 153 mesg.append("."); 154 mesg.append(method); 155 mesg.append(": Returning -> "); 156 157 if (value == null) { 158 mesg.append("null"); 159 } else { 160 mesg.append(value.toString()); 161 } 162 163 mesg.append("\n"); 164 165 if (DriverManager.getLogStream() == null) { 166 System.out.println(mesg.toString()); 167 } else { 168 DriverManager.println(mesg.toString()); 169 } 170 } 171 } 172 } 173 174 181 public static void trace(String classList) { 182 StringTokenizer tokenizer = new StringTokenizer (classList, ":"); 183 184 synchronized (MUTEX) { 185 watchAll = false; 186 187 if (classList.equals("ALL")) { 188 watchAll = true; 189 } else { 190 while (tokenizer.hasMoreTokens()) { 191 String className = tokenizer.nextToken().trim(); 192 193 if (!CLASSES.contains(className)) { 194 CLASSES.put(className, className); 195 } 196 } 197 } 198 } 199 } 200 } 201 | Popular Tags |