KickJava   Java API By Example, From Geeks To Geeks.

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


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 11, 2004
24  *
25  */

26 package org.hammurapi.inspectors.metrics;
27
28
29 import java.util.HashSet JavaDoc;
30 import java.util.Set JavaDoc;
31
32 import org.w3c.dom.Document JavaDoc;
33 import org.w3c.dom.Element JavaDoc;
34
35 import com.pavelvlasov.jsel.JselException;
36 import com.pavelvlasov.jsel.TypeBody;
37 import com.pavelvlasov.jsel.TypeDefinition;
38 import com.pavelvlasov.jsel.TypeSpecification;
39 import com.pavelvlasov.review.SourceMarker;
40
41 /**
42  * @author mucbj0
43 *
44  * JDepend
45  *
46  * Afferent Couplings (Ca)
47  * The number of other packages that depend upon classes within the package
48  * is an indicator of the package's responsibility.
49  *
50  * Efferent Couplings (Ce)
51  * The number of other packages that the classes in the package depend upon
52  * is an indicator of the package's independence.
53  *
54  * */

55 public class CouplingMetricOfClass extends CouplingMetric{
56     public SourceMarker srcMrk = null;
57     public String JavaDoc name = "";
58     public Set JavaDoc listAfferentTypes = new HashSet JavaDoc();
59     public Set JavaDoc listEfferentTypes = new HashSet JavaDoc();
60
61     public CouplingMetricOfClass( TypeDefinition c){
62                 super();
63                 name = c.getFcn();
64                 
65                 srcMrk = (SourceMarker)c;
66             }
67
68     public CouplingMetricOfClass( TypeBody c){
69                 super();
70                 name = c.getFcn();
71                 
72                 srcMrk = (SourceMarker)c;
73             }
74     public CouplingMetricOfClass( TypeSpecification c)throws JselException{
75                 super();
76                 name = c.getName();
77                 srcMrk = (SourceMarker)c;
78             }
79     
80     public String JavaDoc toString(){
81         return this.name + " CaV: " + afferentVariableCounter + " CeV: " + efferentVariableCounter;
82     }
83 /*
84     public StringBuffer toXml() {
85         StringBuffer sb = new StringBuffer();
86
87         sb.append("<CouplingMetricOfClass ");
88                 sb.append(" type=\"");
89                 sb.append(type.getClassName());
90                 sb.append("\" signature=\"");
91                 sb.append(type.getSignature());
92                 sb.append("\" isAbstract=\"");
93                 sb.append(type.isAbstract());
94                 sb.append("\" isInterface=\"");
95                 sb.append(type.isInterface());
96
97                 sb.append("\">");
98         sb.append( super.toXmlCore() );
99
100         sb.append("<ListAfferentTypes>");
101         for (Iterator it = this.listAfferentTypes.iterator(); it.hasNext();){
102             Type t = (Type)it.next();
103             sb.append( t.toXmlSlim() );
104         }
105         sb.append("</ListAfferentTypes>");
106         sb.append("<ListEfferentTypes>");
107         for (Iterator it = this.listEfferentTypes.iterator(); it.hasNext();){
108                 Type t = (Type)it.next();
109                 sb.append( t.toXmlSlim() );
110             }
111         sb.append("</ListEfferentTypes>");
112
113         sb.append("</CouplingMetricOfClass>");
114         return sb;
115     }
116 */

117     
118     public Element JavaDoc toDom(Document JavaDoc document){
119
120         Element JavaDoc ret=document.createElement("CouplingMetricOfClass");
121         ret.setAttribute("type", name );
122         ret.setAttribute("sourceMarker", srcMrk.getSourceURL() );
123         ret.setAttribute("sourceMarkerLine", String.valueOf( srcMrk.getLine() ) );
124         ret.setAttribute("sourceMarkerColumn", String.valueOf( srcMrk.getColumn()) );
125 // ret.setAttribute("signature", type.getSignature() );
126
// ret.setAttribute("isAbstract", type.isAbstract() );
127
// ret.setAttribute("isInterface", type.isInterface() );
128
super.toDom(document, ret);
129         
130
131         Element JavaDoc lat=document.createElement("ListAfferentTypes");
132         ret.appendChild( lat );
133
134         return ret;
135     }
136
137 }
138
Popular Tags