KickJava   Java API By Example, From Geeks To Geeks.

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


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

28
29 import java.util.Iterator JavaDoc;
30
31 import net.firstpartners.nounit.snippet.xml.IXmlConstants;
32 import net.firstpartners.nounit.snippet.xml.IXmlJdomSource;
33 import net.firstpartners.nounit.snippet.xml.IXmlSource;
34
35 import org.jdom.Element;
36
37 /**
38  * Holds Information about Java Classes
39  */

40
41 public class SnippetClass
42 extends AbstractSnippet
43 implements IXmlSource , IXmlJdomSource , IXmlConstants {
44
45    
46     /**
47      * inner Store of the Access Modifier
48      */

49     private String JavaDoc innerSuperClass;
50     
51     /**
52      * inner store of the parameters / Objects making up method signature
53      */

54     private Snippets innerMethods;
55     
56     /**
57      * Creates new SnippetPackage
58      * @param name of this snippet
59      * @param accessModifier
60      * @param superClass
61      * @param methods (Snippets Collection)
62      */

63     public SnippetClass(String JavaDoc name,
64                         String JavaDoc accessModifier,
65                         String JavaDoc superClass,
66                         Snippets methods) {
67                              
68         super.innerName=name;
69         super.innerAccess=accessModifier;
70         this.innerSuperClass = superClass;
71         this.innerMethods = methods;
72     }
73
74      
75     /**
76      * over-ride Object.toString() to provide more information about this class
77      * @return stringDescription of Class
78      */

79     public String JavaDoc toString(){
80         
81         //Local Variables
82
StringBuffer JavaDoc stringDescription = new StringBuffer JavaDoc();
83                 
84         //Build up return string
85
stringDescription.append(super.toString());
86         
87         stringDescription.append("\n");
88         stringDescription.append("{");
89         
90         //Loop to get method paramters
91
Iterator JavaDoc methodValues = innerMethods.getIterator();
92         
93         while (methodValues.hasNext()){
94             
95             stringDescription.append("\n");
96             stringDescription.append(methodValues.next());
97                         
98         }
99         
100         //remove trailing ":"
101

102         stringDescription.append("}");
103         
104         //Extends Class Information
105
stringDescription.append("\nextends ");
106         stringDescription.append(innerSuperClass);
107         
108         //return value
109

110         return stringDescription.toString();
111     }
112     
113    /**
114      * Get an XML Representation of this Class (as String of XML)
115      * @return String with the XML description
116      */

117     public String JavaDoc toXml() {
118         
119         return super.toXml(getNodes());
120        
121     }
122     
123     
124     /**
125      * Get an XML Representation of this Class (as Jdom nodes)
126      * @return methodRoot with the XML description
127      */

128     public Element getNodes(){
129
130         //Local Variables
131
Element extendsTag = new Element(ELEMENT_CLASS_EXTENDS);
132         Element classRoot = new Element(ELEMENT_CLASS);
133         
134         //Add Name, access and info
135
classRoot.setAttribute(ATTRIBUTE_NAME,super.innerName);
136         classRoot.setAttribute(ATTRIBUTE_ACCESS,super.innerAccess);
137         
138         //Add Extends Info
139
extendsTag.setAttribute(ATTRIBUTE_NAME,this.innerSuperClass);
140         classRoot.addContent(extendsTag);
141         
142         //Add Method Info
143
classRoot = innerMethods.addNodesTo(classRoot);
144                         
145         //Return Class Element
146
return classRoot;
147         
148         
149     }
150     
151     
152 }
153
Popular Tags