KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > management > stats > printers > CSVPrinter


1 /*
2  * $Id: CSVPrinter.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.management.stats.printers;
12
13 import java.io.OutputStream JavaDoc;
14 import java.io.Writer JavaDoc;
15 import java.util.Collection JavaDoc;
16
17 /**
18  * <code>CSVPrinter</code> prints component stats in CSV format
19  *
20  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
21  * @version $Revision: 3798 $
22  */

23 public class CSVPrinter extends AbstractTablePrinter
24 {
25     private String JavaDoc delim = ",";
26     private boolean printHeaders = true;
27
28     public CSVPrinter(Writer JavaDoc out)
29     {
30         super(out);
31     }
32
33     public CSVPrinter(OutputStream JavaDoc out)
34     {
35         super(out);
36     }
37
38     public void print(Collection JavaDoc stats)
39     {
40         try
41         {
42             String JavaDoc[][] table = getTable(stats);
43             int i = (printHeaders ? 0 : 1);
44             for (; i < table.length; i++)
45             {
46                 for (int j = 0; j < table[0].length; j++)
47                 {
48                     print(table[i][j]);
49                     if (j + 1 != table[i].length)
50                     {
51                         print(delim);
52                     }
53                 }
54                 println();
55             }
56         }
57         catch (Throwable JavaDoc e)
58         {
59             e.printStackTrace();
60         }
61     }
62
63     public boolean isPrintHeaders()
64     {
65         return printHeaders;
66     }
67
68     public void setPrintHeaders(boolean printHeaders)
69     {
70         this.printHeaders = printHeaders;
71     }
72 }
73
Popular Tags