001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Johannes Bellert
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.com
021: * e-Mail: Johannes.Bellert@ercgroup.com
022: *
023: * * Created on Apr 25, 2004
024: *
025: */
026: package org.hammurapi.inspectors.metrics;
027:
028: import java.util.Vector;
029:
030: import org.apache.xpath.CachedXPathAPI;
031: import org.apache.xpath.XPathAPI;
032: import org.hammurapi.HammurapiException;
033: import org.w3c.dom.Document;
034: import org.w3c.dom.Element;
035: import org.w3c.dom.Node;
036: import org.w3c.dom.traversal.NodeIterator;
037:
038: /**
039: * @author Johannes Bellert
040: *
041: */
042: public class TechStackEntity {
043:
044: private String name = "";
045: private String rating = "<undefined>";
046: private String complexity = "";
047: private String homeUrl = "NA";
048:
049: public boolean markIfPartOfJarFileList(String jarName) {
050: boolean ret = false;
051: int i = 0;
052: while (!ret && i < getJarFileList().size()) {
053: JarFile jf = (JarFile) getJarFileList().elementAt(i);
054: System.out.println(jarName + " <> " + jf.getName());
055: if (jarName.equals(jf.getName())) {
056: jf.setIsUsed(true);
057: ret = true;
058: }
059: i++;
060: }
061: return ret;
062: }
063:
064: /**
065: * @return Returns the jarFileList.
066: */
067: public Vector getJarFileList() {
068: return jarFileList;
069: }
070:
071: /**
072: * @param jarFileList The jarFileList to set.
073: */
074: public void setJarFileList(Vector jarFileList) {
075: this .jarFileList = jarFileList;
076: }
077:
078: /**
079: * @return Returns the licenseList.
080: */
081: public Vector getLicenseList() {
082: return licenseList;
083: }
084:
085: /**
086: * @param licenseList The licenseList to set.
087: */
088: public void setLicenseList(Vector licenseList) {
089: this .licenseList = licenseList;
090: }
091:
092: private Vector licenseList = new Vector();
093: private Vector jarFileList = new Vector();
094: private Vector variableMapping = new Vector();
095: private Vector extensionMapping = new Vector();
096:
097: /**
098: * @return Returns the extensionMapping.
099: */
100: public Vector getExtensionMapping() {
101: return extensionMapping;
102: }
103:
104: /**
105: * @param extensionMapping The extensionMapping to set.
106: */
107: public void setExtensionMapping(Vector extensionMapping) {
108: this .extensionMapping = extensionMapping;
109: }
110:
111: /**
112: * @return Returns the variableMapping.
113: */
114: public Vector getVariableMapping() {
115: return variableMapping;
116: }
117:
118: /**
119: * @param variableMapping The variableMapping to set.
120: */
121: public void setVariableMapping(Vector variableMapping) {
122: this .variableMapping = variableMapping;
123: }
124:
125: public TechStackEntity(Element holder) throws HammurapiException {
126: super ();
127: try {
128: CachedXPathAPI cxpa = new CachedXPathAPI();
129:
130: name = holder.getAttribute("name");
131:
132: rating = holder.getAttribute("rating");
133: complexity = holder.getAttribute("complexity");
134:
135: NodeIterator itvmNode = XPathAPI.selectNodeIterator(holder,
136: "VariableMapping");
137: Node vmNode;
138: while ((vmNode = itvmNode.nextNode()) != null) {
139: if (vmNode instanceof Element) {
140: //System.out.println( " vmNode.getAttribute(name)" + ((Element)vmNode).getAttribute("name") );
141: this .variableMapping
142: .add((String) ((Element) vmNode)
143: .getAttribute("name"));
144: }
145: }
146: NodeIterator itxmNode = XPathAPI.selectNodeIterator(holder,
147: "ExtensionMapping");
148: Node xmNode;
149: while ((xmNode = itxmNode.nextNode()) != null) {
150: if (xmNode instanceof Element) {
151: // System.out.println( " xmNode.getAttribute(name)" + ((Element)xmNode).getAttribute("name") );
152: this .extensionMapping
153: .add((String) ((Element) xmNode)
154: .getAttribute("name"));
155: }
156: }
157:
158: NodeIterator itLicNode = XPathAPI.selectNodeIterator(
159: holder, "License");
160: Node licNode;
161: while ((licNode = itLicNode.nextNode()) != null) {
162: if (licNode instanceof Element) {
163: this .licenseList.add((String) ((Element) licNode)
164: .getAttribute("name"));
165: }
166: }
167: NodeIterator itJarNode = XPathAPI.selectNodeIterator(
168: holder, "JarFile");
169: Node jarNode;
170: while ((jarNode = itJarNode.nextNode()) != null) {
171: if (jarNode instanceof Element) {
172: this .jarFileList
173: .add(new JarFile((Element) jarNode));
174: }
175: }
176: NodeIterator itHome = XPathAPI.selectNodeIterator(holder,
177: "Home");
178: Node homeNode;
179: while ((homeNode = itHome.nextNode()) != null) {
180: if (homeNode instanceof Element) {
181: this .homeUrl = (String) ((Element) homeNode)
182: .getAttribute("url");
183: }
184: }
185: } catch (Exception e) {
186: throw new HammurapiException(e);
187: }
188: }
189:
190: public String toString() {
191: return name;
192: }
193:
194: /**
195: * @return Returns the complexity.
196: */
197: public String getComplexity() {
198: return complexity;
199: }
200:
201: /**
202: * @param complexity The complexity to set.
203: */
204: public void setComplexity(String complexity) {
205: this .complexity = complexity;
206: }
207:
208: /**
209: * @return Returns the name.
210: */
211: public String getName() {
212: return name;
213: }
214:
215: /**
216: * @param name The name to set.
217: */
218: public void setName(String name) {
219: this .name = name;
220: }
221:
222: /**
223: * @return Returns the rating.
224: */
225: public String getRating() {
226: return rating;
227: }
228:
229: /**
230: * @param rating The rating to set.
231: */
232: public void setRating(String rating) {
233: this .rating = rating;
234: }
235:
236: public TechStackEntity(String _name, String _rating) {
237: super ();
238: name = _name;
239: rating = _rating;
240:
241: }
242:
243: public Element toDom(Document document) {
244:
245: Element ret = document.createElement("TechStackEntity");
246: ret.setAttribute("name", this .name);
247:
248: ret.setAttribute("complexity", this .complexity);
249: ret.setAttribute("rating", this .rating);
250:
251: for (int i = 0; i < licenseList.size(); i++) {
252: Element retA = document.createElement("License");
253: retA.setAttribute("name", (String) this .licenseList
254: .elementAt(i));
255: ret.appendChild(retA);
256: }
257:
258: for (int i = 0; i < jarFileList.size(); i++) {
259: ret.appendChild(((JarFile) jarFileList.elementAt(i))
260: .toDom(document));
261: }
262: Element retURL = document.createElement("Home");
263: retURL.setAttribute("url", this.homeUrl);
264: ret.appendChild(retURL);
265: return ret;
266: }
267:
268: }
|