KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > firstpartners > nounit > snippet > SnippetPackage


1 package net.firstpartners.nounit.snippet;
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.util.Iterator JavaDoc;
28
29 import net.firstpartners.nounit.snippet.xml.IXmlConstants;
30 import net.firstpartners.nounit.snippet.xml.IXmlJdomSource;
31 import net.firstpartners.nounit.snippet.xml.IXmlSource;
32
33 import org.jdom.Element;
34
35 /**
36  * Holds Information about a Java Package
37  */

38 public class SnippetPackage
39 extends AbstractSnippet
40 implements IXmlSource , IXmlJdomSource , IXmlConstants {
41       
42     /**
43      * inner store of the classes within this package
44      */

45     private Snippets innerClasses;
46     
47     /**
48      * Creates new SnippetPackage
49      * @param location of this snippet
50      * @param classes (as Snippets)
51      */

52     public SnippetPackage(String JavaDoc location, Snippets classes) {
53                              
54         super.innerName=location;
55         this.innerClasses = classes;
56     }
57
58      
59     /**
60      * over-ride Object.toString() to provide more information about this class
61      * @return stringDescription of Class
62      */

63     public String JavaDoc toString(){
64         
65         //Local Variables
66
StringBuffer JavaDoc stringDescription = new StringBuffer JavaDoc();
67                 
68         //Build up return string
69
stringDescription.append("package location ");
70         stringDescription.append(super.innerName);
71         
72         stringDescription.append("\n");
73         //Loop to get method paramters
74
Iterator JavaDoc classValues = this.innerClasses.getIterator();
75         
76         while (classValues.hasNext()){
77             
78             stringDescription.append("\n");
79             stringDescription.append(classValues.next());
80             stringDescription.append("\n");
81                         
82         }
83        
84         //return value
85

86         return stringDescription.toString();
87     }
88     
89     /**
90      * Get an XML Representation of this Class (as String of XML)
91      * @return String with the XML description
92      */

93     public String JavaDoc toXml() {
94         
95         return super.toXml(getNodes());
96        
97     }
98     
99     
100     /**
101      * Get an XML Representation of this Class (as Jdom nodes)
102      * @return methodRoot with the XML description
103      */

104     public Element getNodes(){
105
106         //Local Variables
107
Element packageRoot = new Element(ELEMENT_PACKAGE);
108         
109         //Add Name, access and info
110
packageRoot.setAttribute(ATTRIBUTE_PACKAGE_LOCATION,innerName);
111         
112         //Add Class Info
113
packageRoot = innerClasses.addNodesTo(packageRoot);
114                         
115         //Return Class Element
116
return packageRoot;
117              
118     }
119     
120 }
121
Popular Tags