KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > dependency > GraphSummarizer


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.dependency;
34
35 import org.apache.log4j.*;
36
37 public class GraphSummarizer extends GraphCopier {
38     private SelectionCriteria scopeCriteria;
39     private SelectionCriteria filterCriteria;
40
41     public GraphSummarizer(SelectionCriteria scopeCriteria, SelectionCriteria filterCriteria) {
42         super(new SelectiveTraversalStrategy(scopeCriteria, filterCriteria));
43
44         this.scopeCriteria = scopeCriteria;
45         this.filterCriteria = filterCriteria;
46     }
47     
48     public void visitPackageNode(PackageNode node) {
49         Logger.getLogger(getClass()).debug("node = " + node);
50         
51         boolean inScope = scopeCriteria.matchesPackageName(node.getName());
52
53         if (inScope) {
54             preprocessPackageNode(node);
55             
56             if (getStrategy().doPreOutboundTraversal()) {
57                 traverseOutbound(node.getOutboundDependencies());
58             }
59             
60             if (getStrategy().doPreInboundTraversal()) {
61                 traverseInbound(node.getInboundDependencies());
62             }
63             
64             preprocessAfterDependenciesPackageNode(node);
65         }
66             
67         traverseNodes(node.getClasses());
68
69         if (inScope) {
70             postprocessBeforeDependenciesPackageNode(node);
71
72             if (getStrategy().doPostOutboundTraversal()) {
73                 traverseOutbound(node.getOutboundDependencies());
74             }
75             
76             if (getStrategy().doPostInboundTraversal()) {
77                 traverseInbound(node.getInboundDependencies());
78             }
79
80             postprocessPackageNode(node);
81         }
82     }
83
84     protected void preprocessPackageNode(PackageNode node) {
85         if (scopeCriteria.isMatchingPackages()) {
86             super.preprocessPackageNode(node);
87         }
88     }
89     
90     protected void postprocessPackageNode(PackageNode node) {
91         if (scopeCriteria.isMatchingPackages()) {
92             super.postprocessPackageNode(node);
93         }
94     }
95
96     public void visitInboundPackageNode(PackageNode node) {
97         if (getCurrentNode() != null && filterCriteria.matchesPackageName(node.getName())) {
98             if (filterCriteria.isMatchingPackages()) {
99                 getFilterFactory().createPackage(node.getName(), node.isConfirmed()).addDependency(getCurrentNode());
100             }
101         }
102     }
103
104     public void visitOutboundPackageNode(PackageNode node) {
105         if (getCurrentNode() != null && filterCriteria.matchesPackageName(node.getName())) {
106             if (filterCriteria.isMatchingPackages()) {
107                 getCurrentNode().addDependency(getFilterFactory().createPackage(node.getName(), node.isConfirmed()));
108             }
109         }
110     }
111
112     public void visitClassNode(ClassNode node) {
113         boolean inScope = scopeCriteria.matchesClassName(node.getName());
114         
115         if (inScope) {
116             preprocessClassNode(node);
117             
118             if (getStrategy().doPreOutboundTraversal()) {
119                 traverseOutbound(node.getOutboundDependencies());
120             }
121             
122             if (getStrategy().doPreInboundTraversal()) {
123                 traverseInbound(node.getInboundDependencies());
124             }
125         
126             preprocessAfterDependenciesClassNode(node);
127         }
128         
129         traverseNodes(node.getFeatures());
130             
131         if (inScope) {
132             postprocessBeforeDependenciesClassNode(node);
133
134             if (getStrategy().doPostOutboundTraversal()) {
135                 traverseOutbound(node.getOutboundDependencies());
136             }
137             
138             if (getStrategy().doPostInboundTraversal()) {
139                 traverseInbound(node.getInboundDependencies());
140             }
141             
142             postprocessClassNode(node);
143         }
144     }
145
146     protected void preprocessClassNode(ClassNode node) {
147         if (scopeCriteria.isMatchingClasses()) {
148             super.preprocessClassNode(node);
149         }
150     }
151     
152     protected void postprocessClassNode(ClassNode node) {
153         if (scopeCriteria.isMatchingClasses()) {
154             super.postprocessClassNode(node);
155         }
156     }
157
158     public void visitInboundClassNode(ClassNode node) {
159         if (getCurrentNode() != null && filterCriteria.matchesClassName(node.getName())) {
160             if (filterCriteria.isMatchingClasses()) {
161                 getFilterFactory().createClass(node.getName(), node.isConfirmed()).addDependency(getCurrentNode());
162             } else if (filterCriteria.isMatchingPackages()) {
163                 getFilterFactory().createPackage(node.getPackageNode().getName(), node.getPackageNode().isConfirmed()).addDependency(getCurrentNode());
164             }
165         }
166     }
167
168     public void visitOutboundClassNode(ClassNode node) {
169         if (getCurrentNode() != null && filterCriteria.matchesClassName(node.getName())) {
170             if (filterCriteria.isMatchingClasses()) {
171                 getCurrentNode().addDependency(getFilterFactory().createClass(node.getName(), node.isConfirmed()));
172             } else if (filterCriteria.isMatchingPackages()) {
173                 getCurrentNode().addDependency(getFilterFactory().createPackage(node.getPackageNode().getName(), node.getPackageNode().isConfirmed()));
174             }
175         }
176     }
177
178     public void visitFeatureNode(FeatureNode node) {
179         if (scopeCriteria.matchesFeatureName(node.getName())) {
180             preprocessFeatureNode(node);
181             
182             if (getStrategy().doPreOutboundTraversal()) {
183                 traverseOutbound(node.getOutboundDependencies());
184             }
185             
186             if (getStrategy().doPreInboundTraversal()) {
187                 traverseInbound(node.getInboundDependencies());
188             }
189             
190             if (getStrategy().doPostOutboundTraversal()) {
191                 traverseOutbound(node.getOutboundDependencies());
192             }
193             
194             if (getStrategy().doPostInboundTraversal()) {
195                 traverseInbound(node.getInboundDependencies());
196             }
197             
198             postprocessFeatureNode(node);
199         }
200     }
201
202     protected void preprocessFeatureNode(FeatureNode node) {
203         if (scopeCriteria.isMatchingFeatures()) {
204             super.preprocessFeatureNode(node);
205         }
206     }
207     
208     protected void postprocessFeatureNode(FeatureNode node) {
209         if (scopeCriteria.isMatchingFeatures()) {
210             super.postprocessFeatureNode(node);
211         }
212     }
213     
214     public void visitInboundFeatureNode(FeatureNode node) {
215         if (getCurrentNode() != null && filterCriteria.matchesFeatureName(node.getName())) {
216             if (filterCriteria.isMatchingFeatures()) {
217                 getFilterFactory().createFeature(node.getName(), node.isConfirmed()).addDependency(getCurrentNode());
218             } else if (filterCriteria.isMatchingClasses()) {
219                 getFilterFactory().createClass(node.getClassNode().getName(), node.getClassNode().isConfirmed()).addDependency(getCurrentNode());
220             } else if (filterCriteria.isMatchingPackages()) {
221                 getFilterFactory().createPackage(node.getClassNode().getPackageNode().getName(), node.getClassNode().getPackageNode().isConfirmed()).addDependency(getCurrentNode());
222             }
223         }
224     }
225
226     public void visitOutboundFeatureNode(FeatureNode node) {
227         if (getCurrentNode() != null && filterCriteria.matchesFeatureName(node.getName())) {
228             if (filterCriteria.isMatchingFeatures()) {
229                 getCurrentNode().addDependency(getFilterFactory().createFeature(node.getName(), node.isConfirmed()));
230             } else if (filterCriteria.isMatchingClasses()) {
231                 getCurrentNode().addDependency(getFilterFactory().createClass(node.getClassNode().getName(), node.getClassNode().isConfirmed()));
232             } else if (filterCriteria.isMatchingPackages()) {
233                 getCurrentNode().addDependency(getFilterFactory().createPackage(node.getClassNode().getPackageNode().getName(), node.getClassNode().getPackageNode().isConfirmed()));
234             }
235         }
236     }
237 }
238
Popular Tags