KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > text > ConsoleNonPortableReasonFormatter


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.text;
5
6 import com.tc.util.NonPortableDetail;
7 import com.tc.util.NonPortableReason;
8
9 import java.io.PrintWriter JavaDoc;
10 import java.util.Collection JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.LinkedList JavaDoc;
13
14 public class ConsoleNonPortableReasonFormatter implements NonPortableReasonFormatter {
15
16   private final PrintWriter JavaDoc out;
17   private final StringFormatter stringFormatter;
18   private final Collection JavaDoc details;
19   private int maxLabelLength;
20   private final String JavaDoc separator;
21   private final ParagraphFormatter paragraphFormatter;
22
23   public ConsoleNonPortableReasonFormatter(PrintWriter JavaDoc out, String JavaDoc separator, StringFormatter stringFormatter,
24                                            ParagraphFormatter paragraphFormatter) {
25     this.out = out;
26     this.separator = separator;
27     this.stringFormatter = stringFormatter;
28     this.paragraphFormatter = paragraphFormatter;
29     details = new LinkedList JavaDoc();
30   }
31
32   public void formatReasonTypeName(byte type) {
33     String JavaDoc name;
34     switch(type) {
35       case NonPortableReason.CLASS_NOT_ADAPTABLE:
36         name = "CLASS_NOT_ADAPTABLE";
37         break;
38       case NonPortableReason.SUPER_CLASS_NOT_ADAPTABLE:
39         name = "SUPER_CLASS_NOT_ADAPTABLE";
40         break;
41       case NonPortableReason.SUBCLASS_OF_LOGICALLY_MANAGED_CLASS:
42         name = "SUBCLASS_OF_LOGICALLY_MANAGED_CLASS";
43         break;
44       case NonPortableReason.CLASS_NOT_IN_BOOT_JAR:
45         name = "CLASS_NOT_IN_BOOT_JAR";
46         break;
47       case NonPortableReason.CLASS_NOT_INCLUDED_IN_CONFIG:
48         name = "CLASS_NOT_INCLUDED_IN_CONFIG";
49         break;
50       case NonPortableReason.SUPER_CLASS_NOT_INSTRUMENTED:
51         name = "SUPER_CLASS_NOT_INSTRUMENTED";
52         break;
53       default:
54         name = "UNDEFINED";
55     }
56     out.print(name);
57   }
58   
59   public void formatDetail(NonPortableDetail detail) {
60     details.add(detail);
61     if (detail.getLabel().length() > maxLabelLength) {
62       maxLabelLength = detail.getLabel().length();
63     }
64   }
65
66   public void flush() {
67     for (Iterator JavaDoc i = details.iterator(); i.hasNext();) {
68       NonPortableDetail detail = (NonPortableDetail) i.next();
69       out.print(stringFormatter.rightPad(maxLabelLength, detail.getLabel()));
70       out.print(separator);
71       out.print(detail.getValue());
72       if (i.hasNext()) {
73         out.println();
74       }
75     }
76     details.clear();
77     out.flush();
78   }
79
80   public void formatReasonText(String JavaDoc reasonText) {
81     out.println(paragraphFormatter.format(reasonText));
82     out.println();
83   }
84
85 }
86
Popular Tags