KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap 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 the methods called from a Java Method
39  */

40 public class SnippetCalls extends AbstractSnippet implements IXmlSource, IXmlJdomSource, IXmlConstants {
41     
42     
43     /**
44      * inner store of the parameters / Objects making up method signature
45      */

46     private HashMap JavaDoc innerParams;
47     
48     /**
49      * inner store of the class that is being called
50      */

51     private String JavaDoc innerClassCalled;
52     
53     /**
54      * inner store of the method that is being called
55      */

56     private String JavaDoc innerMethodCalled;
57     
58     
59     /**
60      * Creates new SnippetMethod
61      * @param name of this snippet
62      * @param accessModifier
63      * @param parameters , HashMap with value pairs 1,Integer 2,Integer 3,String
64      * or whatever the method signature is
65      */

66     public SnippetCalls(String JavaDoc classCalled, String JavaDoc methodCalled, HashMap JavaDoc parameters) {
67         
68         this.innerClassCalled=classCalled;
69         this.innerMethodCalled=methodCalled;
70         
71         //Check and set the method signature
72
if (parameters==null) {
73             this.innerParams = new HashMap JavaDoc();
74         } else {
75             this.innerParams = parameters;
76         }
77     }
78     
79     
80     /**
81      * over-ride Object.toString() to provide more information about this class
82      * @return stringDescription of Class
83      */

84     public String JavaDoc toString(){
85         
86         //Local Variables
87
StringBuffer JavaDoc stringDescription = new StringBuffer JavaDoc();
88         
89         stringDescription.append("Calls:\n");
90         stringDescription.append(this.innerClassCalled);
91         stringDescription.append("\n");
92         stringDescription.append(this.innerMethodCalled);
93         stringDescription.append("\n");
94         
95         stringDescription.append("(");
96         
97         //Loop to get method paramters
98
int counter=0;
99         Object JavaDoc tmpObject;
100         
101         while (counter>-1){
102             tmpObject=innerParams.get(String.valueOf(counter));
103             if (tmpObject==null) {
104                 counter=-1;
105             } else {
106                 counter++;
107                 stringDescription.append(tmpObject);
108                 stringDescription.append(":");
109             }
110             
111         }
112         
113         
114         stringDescription.append(")");
115         
116         
117         //return value
118

119         return stringDescription.toString();
120     }
121     
122     
123     /**
124      * Get an XML Representation of this Class (as String of XML)
125      * @return String with the XML description
126      */

127     public String JavaDoc toXml() {
128         
129         return super.toXml(getNodes());
130         
131     }
132     
133     
134     /**
135      * Get an XML Representation of this Class (as Jdom nodes)
136      * @return methodRoot with the XML description
137      */

138     public Element getNodes(){
139         
140         //Local Variables
141
int counter=0;
142         Object JavaDoc tmpObject;
143         String JavaDoc tmpString;
144         Element calledRoot = new Element(ELEMENT_CALLS);
145         Element paramTag;
146         
147         //Add Class Name + access info
148
calledRoot.setAttribute(ATTRIBUTE_CLASS,this.innerClassCalled);
149         
150         //Add MethodIfno
151
calledRoot.setAttribute(ATTRIBUTE_METHOD,this.innerMethodCalled);
152        
153         //Add Parameter Info
154

155         while (counter>-1){
156             tmpObject=innerParams.get(String.valueOf(counter));
157             if (tmpObject==null) {
158                 counter=-1;
159             } else {
160                 counter++;
161                 
162                 //Create Element out of this Object
163
tmpString=(String JavaDoc)tmpObject;
164                 paramTag = new Element(ELEMENT_PARAM);
165                 paramTag.setAttribute(ATTRIBUTE_NAME,tmpString);
166                 
167                 //Now add as child of this called root tag
168
calledRoot.addContent(paramTag);
169                 
170             }
171             
172         }
173         
174
175         return calledRoot;
176     }
177     
178     
179     
180 }
181
Popular Tags