KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > firstpartners > nounit > report > ReportPicker


1 package net.firstpartners.nounit.report;
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 net.firstpartners.nounit.ui.common.CommandPackage;
28 import net.firstpartners.nounit.utility.NoUnitException;
29
30 /**
31  * Creates the Report Class , as requested by the user , to generate the report
32  */

33 public class ReportPicker {
34
35   /**
36    * Return the Appropriate Report to handle this user request
37    * @param inCommandPackage containing the request details
38    * @return IReport Object , Class to generate class
39    * @exception NoUnitException thrown if any page names are invalid
40    * @exception IllegalAccessException Thrown when there's a problem retrieving
41    * the concrete reports's class
42    * @exception InstantiationException Thrown when there's a problem creating an
43    * instance of the report bean from it's class.
44    */

45   public static IReport getReportMaker(CommandPackage inCommandPackage)
46     throws NoUnitException {
47
48     //Internal Objects
49
IReport outReport = null;
50       Object JavaDoc tmpObject = new Object JavaDoc();
51  
52     //Get the report as requested by the user
53
String JavaDoc reportName = inCommandPackage.getString(CommandPackage.REPORT_CLASS);
54       
55     //Quick Check ...
56
if ((reportName==null)||(reportName.equals(""))) {
57         throw new NoUnitException ("Please Specify a report name");
58       }
59       
60     //Check for appropriate report to handle request
61

62        try {
63
64             Class JavaDoc outReportClass = Class.forName(reportName);
65             if (outReportClass != null) {
66               outReport = (IReport)outReportClass.newInstance();
67             }
68
69        } catch (ClassNotFoundException JavaDoc cnfe) {
70             throw new NoUnitException("Could not find Report:"+reportName);
71        } catch (InstantiationException JavaDoc ie) {
72             throw new NoUnitException("Could not create Report:"+reportName);
73        } catch (IllegalAccessException JavaDoc iae) {
74             throw new NoUnitException("Error in creating Report:"+reportName);
75        }
76     
77      return outReport;
78   }
79
80 }
Popular Tags