1 23 24 package org.enhydra.xml.xmlc.parsers; 25 26 import java.io.IOException ; 27 import java.io.PrintWriter ; 28 import java.io.Writer ; 29 30 import org.enhydra.xml.xmlc.codegen.IndentWriter; 31 32 38 public class ParseTracer extends IndentWriter { 39 42 private boolean fEnabled; 43 44 49 private static class NullWriter extends Writer { 50 51 public NullWriter() { 52 } 53 54 55 public void write(int c) throws IOException { 56 } 57 58 59 public void write(char[] cbuf, int off, int len) throws IOException { 60 } 61 62 63 public void flush() throws IOException { 64 } 65 66 67 public void close() throws IOException { 68 } 69 } 70 71 75 public ParseTracer(PrintWriter traceOut) { 76 super(((traceOut != null) ? traceOut 77 : new PrintWriter (new NullWriter())), true); 78 fEnabled = (traceOut != null); 79 setZeroCheck(false); 80 } 81 82 85 public final boolean enabled() { 86 return fEnabled; 87 } 88 89 93 private String formatNumber(int number, 94 int width) { 95 String num = Integer.toString(number); 96 StringBuffer buf = new StringBuffer (num.length()+width); 97 for (int cnt = width-num.length(); cnt >= 0; cnt--) { 98 buf.append(' '); 99 } 100 buf.append(num); 101 return buf.toString(); 102 } 103 104 107 public void trace(String str) { 108 if (fEnabled) { 109 printPrefix(formatNumber(getIndentLevel(), 2) + ">"); 110 super.println(str); 111 } 112 } 113 114 117 public void print(String str) { 118 if (fEnabled) { 119 super.print(str); 120 } 121 } 122 123 126 public void println() { 127 if (fEnabled) { 128 super.println(); 129 } 130 } 131 132 135 public void println(String str) { 136 if (fEnabled) { 137 super.println(str); 138 } 139 } 140 } 141 | Popular Tags |