KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > firstpartners > nounit > ui > common > Processor


1 package net.firstpartners.nounit.ui.common;
2
3 /**
4  * Title: NoUnit - Identify Classes that are not being unit Tested
5  *
6  * Copyright (C) 2001 Paul Browne , FirstPartners.net
7  *
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * @author Paul Browne
24  * @version 0.7
25  */

26
27 import java.io.File JavaDoc;
28 import java.io.FileOutputStream JavaDoc;
29
30 import net.firstpartners.nounit.reader.bytecode.ByteCodeProjectSnippetFactory;
31 import net.firstpartners.nounit.report.IReport;
32 import net.firstpartners.nounit.report.ReportPicker;
33 import net.firstpartners.nounit.snippet.Snippets;
34 import net.firstpartners.nounit.utility.NoUnitException;
35
36 import org.jdom.output.XMLOutputter;
37
38
39 /**
40  * Do the main processing Java->Xml->XSLT report
41  */

42 public class Processor implements IProcessor {
43
44     /**
45      * Do the hard work Java->Xml->XSLT report using subclasses
46      * @param inCommandPackage of parameters
47      * @return inCommandPackage with output message
48      */

49     public CommandPackage transform(CommandPackage inCommandPackage)
50         throws NoUnitException{
51             
52         try{
53             
54              
55             //Check for any missing values
56
CommandValueChecker checkArgs = new CommandValueChecker();
57             checkArgs.checkValues(inCommandPackage);
58             
59             //Walk the Package(s) to get the XML
60
ByteCodeProjectSnippetFactory myFactory
61                 = new ByteCodeProjectSnippetFactory(inCommandPackage.getString(
62                                                         CommandPackage.START_DIR));
63             
64             Snippets projectInfo= myFactory.getSnippets();
65             
66             
67             //Combine File and Directory
68
String JavaDoc outDir =
69                 inCommandPackage.getString( CommandPackage.OUTPUT_DIR );
70             File JavaDoc destination = new File JavaDoc( outDir, SystemValues.XML_OUTPUT_NAME );
71         
72             //Delete file if it's already there
73
if ( destination.exists() ) {
74               destination.delete();
75             }
76
77             //Get Handle to file
78
FileOutputStream JavaDoc output = new FileOutputStream JavaDoc(destination);
79
80             //Output Xml to this stream
81
XMLOutputter fmt = new XMLOutputter(" ", true);
82             fmt.output( projectInfo.getFirstItem().getNodes(), output );
83                                     
84             //Do the transformation(s)
85
IReport thisReport = ReportPicker.getReportMaker(inCommandPackage);
86             thisReport.makeReport(inCommandPackage);
87             
88             //Set the output message
89
inCommandPackage.addValue(CommandPackage.USER_MESSAGE,
90                                         "Transformation Successful");
91             
92             
93         } catch (java.io.IOException JavaDoc ioe) {
94             
95             throw new NoUnitException(ioe,"IO Error");
96             
97         } catch (javax.xml.transform.TransformerException JavaDoc te) {
98             
99             throw new NoUnitException(te,"Transformation Error");
100         }
101         
102         return inCommandPackage;
103     }
104
105 }
106
Popular Tags