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 Java Methods
037: */
038: public class SnippetMethod 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 methods called by this method
048: */
049: private Snippets innerMethodsCalled;
050:
051: /**
052: * Creates new SnippetMethod
053: * @param name of this snippet
054: * @param accessModifier
055: * @param parameters , HashMap with value pairs 1,Integer 2,Integer 3,String
056: * or whatever the method signature is
057: * @param methodsCalled (as Snippets) by this method
058: */
059: public SnippetMethod(String name, String accessModifier,
060: HashMap parameters, Snippets methodsCalled) {
061:
062: super .innerName = name;
063: super .innerAccess = accessModifier;
064:
065: //Check and set the method signature
066: if (parameters == null) {
067: this .innerParams = new HashMap();
068: } else {
069: this .innerParams = parameters;
070: }
071:
072: //Check and set the methods called
073: if (parameters == null) {
074: this .innerMethodsCalled = new Snippets();
075: } else {
076: this .innerMethodsCalled = methodsCalled;
077: }
078: }
079:
080: /**
081: * over-ride Object.toString() to provide more information about this class
082: * @return stringDescription of Class
083: */
084: public String toString() {
085:
086: //Local Variables
087: StringBuffer stringDescription = new StringBuffer();
088:
089: //Build up return string
090: stringDescription.append(super .toString());
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 paramTag = new Element(ELEMENT_PARAM);
138: Element methodRoot = new Element(ELEMENT_METHOD);
139:
140: //Add Name + access info
141: methodRoot.setAttribute(ATTRIBUTE_NAME, super .innerName);
142: methodRoot.setAttribute(ATTRIBUTE_ACCESS, super .innerAccess);
143:
144: //Add Classe names that make up this method signature (under Param Tag)
145: while (counter > -1) {
146: tmpObject = innerParams.get(String.valueOf(counter));
147: if (tmpObject == null) {
148: counter = -1;
149: } else {
150: counter++;
151:
152: //Create Element out of this Object
153: tmpString = (String) tmpObject;
154: paramTag = new Element(ELEMENT_PARAM);
155: paramTag.setAttribute(ATTRIBUTE_NAME, tmpString);
156:
157: //Now add as child of this method
158: methodRoot.addContent(paramTag);
159:
160: }
161:
162: }
163:
164: //Now add the called methods to this mehtod root
165: methodRoot = innerMethodsCalled.addNodesTo(methodRoot);
166:
167: return methodRoot;
168: }
169:
170: }
|