KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > inspectors > metrics > TechStackEntity


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Johannes Bellert
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * URL: http://www.hammurapi.com
21  * e-Mail: Johannes.Bellert@ercgroup.com
22  *
23  * * Created on Apr 25, 2004
24  *
25  */

26 package org.hammurapi.inspectors.metrics;
27
28 import java.util.Vector JavaDoc;
29
30 import org.apache.xpath.CachedXPathAPI;
31 import org.apache.xpath.XPathAPI;
32 import org.hammurapi.HammurapiException;
33 import org.w3c.dom.Document JavaDoc;
34 import org.w3c.dom.Element JavaDoc;
35 import org.w3c.dom.Node JavaDoc;
36 import org.w3c.dom.traversal.NodeIterator;
37     
38 /**
39  * @author Johannes Bellert
40  *
41  */

42 public class TechStackEntity {
43     
44     private String JavaDoc name = "";
45     private String JavaDoc rating = "<undefined>";
46     private String JavaDoc complexity = "";
47     private String JavaDoc homeUrl = "NA";
48     
49     
50     
51     public boolean markIfPartOfJarFileList(String JavaDoc jarName){
52         boolean ret = false;
53         int i=0;
54         while( !ret && i<getJarFileList().size()){
55             JarFile jf = (JarFile)getJarFileList().elementAt(i);
56             System.out.println( jarName +" <> " +jf.getName());
57             if(jarName.equals(jf.getName()) ){
58                 jf.setIsUsed(true);
59                 ret =true;
60             }
61             i++;
62         }
63         return ret;
64     }
65     
66     /**
67      * @return Returns the jarFileList.
68      */

69     public Vector JavaDoc getJarFileList() {
70         return jarFileList;
71     }
72     /**
73      * @param jarFileList The jarFileList to set.
74      */

75     public void setJarFileList(Vector JavaDoc jarFileList) {
76         this.jarFileList = jarFileList;
77     }
78     /**
79      * @return Returns the licenseList.
80      */

81     public Vector JavaDoc getLicenseList() {
82         return licenseList;
83     }
84     /**
85      * @param licenseList The licenseList to set.
86      */

87     public void setLicenseList(Vector JavaDoc licenseList) {
88         this.licenseList = licenseList;
89     }
90     private Vector JavaDoc licenseList = new Vector JavaDoc();
91     private Vector JavaDoc jarFileList = new Vector JavaDoc();
92     private Vector JavaDoc variableMapping = new Vector JavaDoc();
93     private Vector JavaDoc extensionMapping = new Vector JavaDoc();
94     
95     /**
96      * @return Returns the extensionMapping.
97      */

98     public Vector JavaDoc getExtensionMapping() {
99         return extensionMapping;
100     }
101     /**
102      * @param extensionMapping The extensionMapping to set.
103      */

104     public void setExtensionMapping(Vector JavaDoc extensionMapping) {
105         this.extensionMapping = extensionMapping;
106     }
107     /**
108      * @return Returns the variableMapping.
109      */

110     public Vector JavaDoc getVariableMapping() {
111         return variableMapping;
112     }
113     /**
114      * @param variableMapping The variableMapping to set.
115      */

116     public void setVariableMapping(Vector JavaDoc variableMapping) {
117         this.variableMapping = variableMapping;
118     }
119
120     public TechStackEntity(Element JavaDoc holder) throws HammurapiException {
121         super();
122         try {
123             CachedXPathAPI cxpa=new CachedXPathAPI();
124             
125             name = holder.getAttribute("name") ;
126     
127             rating = holder.getAttribute("rating") ;
128             complexity = holder.getAttribute("complexity") ;
129             
130                 NodeIterator itvmNode=XPathAPI.selectNodeIterator(holder, "VariableMapping");
131                     Node JavaDoc vmNode;
132                     while ((vmNode=itvmNode.nextNode())!=null) {
133                         if (vmNode instanceof Element JavaDoc) {
134                             //System.out.println( " vmNode.getAttribute(name)" + ((Element)vmNode).getAttribute("name") );
135
this.variableMapping.add( (String JavaDoc)((Element JavaDoc)vmNode).getAttribute("name") );
136                         }
137                     }
138                 NodeIterator itxmNode=XPathAPI.selectNodeIterator(holder, "ExtensionMapping");
139                     Node JavaDoc xmNode;
140                     while ((xmNode=itxmNode.nextNode())!=null) {
141                         if (xmNode instanceof Element JavaDoc) {
142                             // System.out.println( " xmNode.getAttribute(name)" + ((Element)xmNode).getAttribute("name") );
143
this.extensionMapping.add( (String JavaDoc)((Element JavaDoc)xmNode).getAttribute("name") );
144                         }
145                     }
146                                                                                 
147                     NodeIterator itLicNode=XPathAPI.selectNodeIterator(holder, "License");
148                     Node JavaDoc licNode;
149                     while ((licNode=itLicNode.nextNode())!=null) {
150                         if (licNode instanceof Element JavaDoc) {
151                              this.licenseList.add( (String JavaDoc)((Element JavaDoc)licNode).getAttribute("name") );
152                         }
153                     }
154                     NodeIterator itJarNode=XPathAPI.selectNodeIterator(holder, "JarFile");
155                     Node JavaDoc jarNode;
156                     while ((jarNode=itJarNode.nextNode())!=null) {
157                         if (jarNode instanceof Element JavaDoc) {
158                             this.jarFileList.add( new JarFile( (Element JavaDoc)jarNode) );
159                         }
160                     }
161                     NodeIterator itHome=XPathAPI.selectNodeIterator(holder, "Home");
162                     Node JavaDoc homeNode;
163                     while ((homeNode=itHome.nextNode())!=null) {
164                         if (homeNode instanceof Element JavaDoc) {
165                             this.homeUrl = (String JavaDoc)((Element JavaDoc)homeNode).getAttribute("url");
166                         }
167                     }
168         }catch (Exception JavaDoc e){
169             throw new HammurapiException(e);
170         }
171     }
172
173     public String JavaDoc toString(){
174         return name ;
175     }
176     /**
177      * @return Returns the complexity.
178      */

179     public String JavaDoc getComplexity() {
180         return complexity;
181     }
182     /**
183      * @param complexity The complexity to set.
184      */

185     public void setComplexity(String JavaDoc complexity) {
186         this.complexity = complexity;
187     }
188     /**
189      * @return Returns the name.
190      */

191     public String JavaDoc getName() {
192         return name;
193     }
194     /**
195      * @param name The name to set.
196      */

197     public void setName(String JavaDoc name) {
198         this.name = name;
199     }
200     /**
201      * @return Returns the rating.
202      */

203     public String JavaDoc getRating() {
204         return rating;
205     }
206     /**
207      * @param rating The rating to set.
208      */

209     public void setRating(String JavaDoc rating) {
210         this.rating = rating;
211     }
212     public TechStackEntity( String JavaDoc _name, String JavaDoc _rating){
213         super();
214         name = _name;
215         rating = _rating;
216             
217     }
218
219     public Element JavaDoc toDom(Document JavaDoc document){
220
221         Element JavaDoc ret=document.createElement("TechStackEntity");
222         ret.setAttribute("name", this.name );
223         
224         ret.setAttribute("complexity", this.complexity );
225         ret.setAttribute("rating", this.rating );
226     
227         for(int i=0; i<licenseList.size(); i++){
228             Element JavaDoc retA=document.createElement("License");
229             retA.setAttribute("name", (String JavaDoc) this.licenseList.elementAt(i));
230             ret.appendChild( retA);
231         }
232         
233         for(int i=0; i<jarFileList.size(); i++){
234             ret.appendChild( ((JarFile)jarFileList.elementAt(i)).toDom(document) );
235         }
236         Element JavaDoc retURL=document.createElement("Home");
237         retURL.setAttribute("url", this.homeUrl );
238         ret.appendChild( retURL);
239         return ret;
240     }
241
242 }
243
Popular Tags