001: package net.firstpartners.nounit.snippet;
002:
003: /**
004: * Title: NoUnit - Identify Classes that are not being unit Tested
005: *
006: * Copyright (C) 2001 Paul Browne , FirstPartners.net
007: *
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or (at your option) any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * @author Paul Browne
024: * @version 0.7
025: */
026:
027: import java.util.HashMap;
028:
029: import net.firstpartners.nounit.snippet.xml.IXmlConstants;
030: import net.firstpartners.nounit.snippet.xml.IXmlJdomSource;
031: import net.firstpartners.nounit.snippet.xml.IXmlSource;
032:
033: import org.jdom.Element;
034:
035: /**
036: * Holds Information about the methods called from a Java Method
037: */
038: public class SnippetCalls extends AbstractSnippet implements
039: IXmlSource, IXmlJdomSource, IXmlConstants {
040:
041: /**
042: * inner store of the parameters / Objects making up method signature
043: */
044: private HashMap innerParams;
045:
046: /**
047: * inner store of the class that is being called
048: */
049: private String innerClassCalled;
050:
051: /**
052: * inner store of the method that is being called
053: */
054: private String innerMethodCalled;
055:
056: /**
057: * Creates new SnippetMethod
058: * @param name of this snippet
059: * @param accessModifier
060: * @param parameters , HashMap with value pairs 1,Integer 2,Integer 3,String
061: * or whatever the method signature is
062: */
063: public SnippetCalls(String classCalled, String methodCalled,
064: HashMap parameters) {
065:
066: this .innerClassCalled = classCalled;
067: this .innerMethodCalled = methodCalled;
068:
069: //Check and set the method signature
070: if (parameters == null) {
071: this .innerParams = new HashMap();
072: } else {
073: this .innerParams = parameters;
074: }
075: }
076:
077: /**
078: * over-ride Object.toString() to provide more information about this class
079: * @return stringDescription of Class
080: */
081: public String toString() {
082:
083: //Local Variables
084: StringBuffer stringDescription = new StringBuffer();
085:
086: stringDescription.append("Calls:\n");
087: stringDescription.append(this .innerClassCalled);
088: stringDescription.append("\n");
089: stringDescription.append(this .innerMethodCalled);
090: stringDescription.append("\n");
091:
092: stringDescription.append("(");
093:
094: //Loop to get method paramters
095: int counter = 0;
096: Object tmpObject;
097:
098: while (counter > -1) {
099: tmpObject = innerParams.get(String.valueOf(counter));
100: if (tmpObject == null) {
101: counter = -1;
102: } else {
103: counter++;
104: stringDescription.append(tmpObject);
105: stringDescription.append(":");
106: }
107:
108: }
109:
110: stringDescription.append(")");
111:
112: //return value
113:
114: return stringDescription.toString();
115: }
116:
117: /**
118: * Get an XML Representation of this Class (as String of XML)
119: * @return String with the XML description
120: */
121: public String toXml() {
122:
123: return super .toXml(getNodes());
124:
125: }
126:
127: /**
128: * Get an XML Representation of this Class (as Jdom nodes)
129: * @return methodRoot with the XML description
130: */
131: public Element getNodes() {
132:
133: //Local Variables
134: int counter = 0;
135: Object tmpObject;
136: String tmpString;
137: Element calledRoot = new Element(ELEMENT_CALLS);
138: Element paramTag;
139:
140: //Add Class Name + access info
141: calledRoot.setAttribute(ATTRIBUTE_CLASS, this .innerClassCalled);
142:
143: //Add MethodIfno
144: calledRoot.setAttribute(ATTRIBUTE_METHOD,
145: this .innerMethodCalled);
146:
147: //Add Parameter Info
148:
149: while (counter > -1) {
150: tmpObject = innerParams.get(String.valueOf(counter));
151: if (tmpObject == null) {
152: counter = -1;
153: } else {
154: counter++;
155:
156: //Create Element out of this Object
157: tmpString = (String) tmpObject;
158: paramTag = new Element(ELEMENT_PARAM);
159: paramTag.setAttribute(ATTRIBUTE_NAME, tmpString);
160:
161: //Now add as child of this called root tag
162: calledRoot.addContent(paramTag);
163:
164: }
165:
166: }
167:
168: return calledRoot;
169: }
170:
171: }
|