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.Iterator;
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 Classes
037: */
038:
039: public class SnippetClass extends AbstractSnippet implements
040: IXmlSource, IXmlJdomSource, IXmlConstants {
041:
042: /**
043: * inner Store of the Access Modifier
044: */
045: private String innerSuperClass;
046:
047: /**
048: * inner store of the parameters / Objects making up method signature
049: */
050: private Snippets innerMethods;
051:
052: /**
053: * Creates new SnippetPackage
054: * @param name of this snippet
055: * @param accessModifier
056: * @param superClass
057: * @param methods (Snippets Collection)
058: */
059: public SnippetClass(String name, String accessModifier,
060: String super Class, Snippets methods) {
061:
062: super .innerName = name;
063: super .innerAccess = accessModifier;
064: this .innerSuperClass = super Class;
065: this .innerMethods = methods;
066: }
067:
068: /**
069: * over-ride Object.toString() to provide more information about this class
070: * @return stringDescription of Class
071: */
072: public String toString() {
073:
074: //Local Variables
075: StringBuffer stringDescription = new StringBuffer();
076:
077: //Build up return string
078: stringDescription.append(super .toString());
079:
080: stringDescription.append("\n");
081: stringDescription.append("{");
082:
083: //Loop to get method paramters
084: Iterator methodValues = innerMethods.getIterator();
085:
086: while (methodValues.hasNext()) {
087:
088: stringDescription.append("\n");
089: stringDescription.append(methodValues.next());
090:
091: }
092:
093: //remove trailing ":"
094:
095: stringDescription.append("}");
096:
097: //Extends Class Information
098: stringDescription.append("\nextends ");
099: stringDescription.append(innerSuperClass);
100:
101: //return value
102:
103: return stringDescription.toString();
104: }
105:
106: /**
107: * Get an XML Representation of this Class (as String of XML)
108: * @return String with the XML description
109: */
110: public String toXml() {
111:
112: return super .toXml(getNodes());
113:
114: }
115:
116: /**
117: * Get an XML Representation of this Class (as Jdom nodes)
118: * @return methodRoot with the XML description
119: */
120: public Element getNodes() {
121:
122: //Local Variables
123: Element extendsTag = new Element(ELEMENT_CLASS_EXTENDS);
124: Element classRoot = new Element(ELEMENT_CLASS);
125:
126: //Add Name, access and info
127: classRoot.setAttribute(ATTRIBUTE_NAME, super .innerName);
128: classRoot.setAttribute(ATTRIBUTE_ACCESS, super .innerAccess);
129:
130: //Add Extends Info
131: extendsTag.setAttribute(ATTRIBUTE_NAME, this .innerSuperClass);
132: classRoot.addContent(extendsTag);
133:
134: //Add Method Info
135: classRoot = innerMethods.addNodesTo(classRoot);
136:
137: //Return Class Element
138: return classRoot;
139:
140: }
141:
142: }
|