1 package org.incava.analysis; 2 3 import java.io.*; 4 import java.util.Iterator ; 5 import java.util.Set ; 6 import java.util.TreeSet ; 7 import net.sourceforge.pmd.ast.Token; 8 9 10 13 public abstract class Report 14 { 15 19 protected String fileName = "-"; 20 21 24 private Writer writer; 25 26 29 private Set violations = new TreeSet (); 30 31 36 public Report(Writer writer) 37 { 38 this.writer = writer; 39 } 40 41 46 public Report(OutputStream os) 47 { 48 this(new OutputStreamWriter(os)); 49 } 50 51 57 public Report(Writer writer, String source) 58 { 59 this(writer); 60 61 reset(source); 62 } 63 64 70 public Report(Writer writer, File file) 71 { 72 this(writer); 73 74 reset(file); 75 } 76 77 83 public Report(OutputStream os, String source) 84 { 85 this(os); 86 87 reset(source); 88 } 89 90 96 public Report(OutputStream os, File file) 97 { 98 this(os); 99 100 reset(file); 101 } 102 103 109 public void reset(File file) 110 { 111 tr.Ace.log("file", file); 112 113 try { 114 fileName = file.getCanonicalPath(); 115 } 116 catch (IOException ioe) { 117 } 118 } 119 120 126 public void reset(String source) 127 { 128 tr.Ace.log("source", source); 129 130 fileName = "-"; 131 } 132 133 136 public void flush() 137 { 138 try { 139 tr.Ace.stack("flushing"); 140 141 Iterator it = violations.iterator(); 142 while (it.hasNext()) { 143 Object obj = it.next(); 144 Violation v = (Violation)obj; 145 String str = toString(v); 146 tr.Ace.log("v", v); 147 tr.Ace.log("str", str); 148 writer.write(str); 149 } 150 writer.flush(); 152 } 154 catch (IOException ioe) { 155 } 156 violations = new TreeSet (); 157 } 158 159 164 public void addViolation(Violation v) 165 { 166 tr.Ace.stack("v", v); 167 violations.add(v); 168 } 169 170 173 public Set getViolations() 174 { 175 return violations; 176 } 177 178 184 protected abstract String toString(Violation violation); 185 186 191 protected void write(String str) 192 { 193 tr.Ace.log("str", str); 194 try { 195 writer.write(str); 196 } 197 catch (IOException ioe) { 198 } 199 } 200 } 201
| Popular Tags
|