1 | /* |
2 | * Copyright (c) 2001-2009, 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 | public class GraphSummarizer extends GraphCopier { |
36 | private SelectionCriteria scopeCriteria; |
37 | private SelectionCriteria filterCriteria; |
38 | |
39 | public GraphSummarizer(SelectionCriteria scopeCriteria, SelectionCriteria filterCriteria) { |
40 | super(new SelectiveTraversalStrategy(scopeCriteria, filterCriteria)); |
41 | |
42 | this.scopeCriteria = scopeCriteria; |
43 | this.filterCriteria = filterCriteria; |
44 | } |
45 | |
46 | protected boolean isInScope(PackageNode node) { |
47 | return scopeCriteria.matchesPackageName(node.getName()); |
48 | } |
49 | |
50 | protected void preprocessPackageNode(PackageNode node) { |
51 | if (scopeCriteria.isMatchingPackages()) { |
52 | super.preprocessPackageNode(node); |
53 | } |
54 | } |
55 | |
56 | protected void postprocessPackageNode(PackageNode node) { |
57 | if (scopeCriteria.isMatchingPackages()) { |
58 | super.postprocessPackageNode(node); |
59 | } |
60 | } |
61 | |
62 | public void visitInboundPackageNode(PackageNode node) { |
63 | if (getCurrentNode() != null && filterCriteria.matchesPackageName(node.getName())) { |
64 | if (filterCriteria.isMatchingPackages()) { |
65 | copy(getFilterFactory(), node).addDependency(getCurrentNode()); |
66 | } |
67 | } |
68 | } |
69 | |
70 | public void visitOutboundPackageNode(PackageNode node) { |
71 | if (getCurrentNode() != null && filterCriteria.matchesPackageName(node.getName())) { |
72 | if (filterCriteria.isMatchingPackages()) { |
73 | getCurrentNode().addDependency(copy(getFilterFactory(), node)); |
74 | } |
75 | } |
76 | } |
77 | |
78 | protected boolean isInScope(ClassNode node) { |
79 | return scopeCriteria.matchesClassName(node.getName()); |
80 | } |
81 | |
82 | protected void preprocessClassNode(ClassNode node) { |
83 | if (scopeCriteria.isMatchingClasses()) { |
84 | super.preprocessClassNode(node); |
85 | } |
86 | } |
87 | |
88 | protected void postprocessClassNode(ClassNode node) { |
89 | if (scopeCriteria.isMatchingClasses()) { |
90 | super.postprocessClassNode(node); |
91 | } |
92 | } |
93 | |
94 | public void visitInboundClassNode(ClassNode node) { |
95 | if (getCurrentNode() != null && filterCriteria.matchesClassName(node.getName())) { |
96 | if (filterCriteria.isMatchingClasses()) { |
97 | copy(getFilterFactory(), node).addDependency(getCurrentNode()); |
98 | } else if (filterCriteria.isMatchingPackages()) { |
99 | copy(getFilterFactory(), node.getPackageNode()).addDependency(getCurrentNode()); |
100 | } |
101 | } |
102 | } |
103 | |
104 | public void visitOutboundClassNode(ClassNode node) { |
105 | if (getCurrentNode() != null && filterCriteria.matchesClassName(node.getName())) { |
106 | if (filterCriteria.isMatchingClasses()) { |
107 | getCurrentNode().addDependency(copy(getFilterFactory(), node)); |
108 | } else if (filterCriteria.isMatchingPackages()) { |
109 | getCurrentNode().addDependency(copy(getFilterFactory(), node.getPackageNode())); |
110 | } |
111 | } |
112 | } |
113 | |
114 | protected boolean isInScope(FeatureNode node) { |
115 | return scopeCriteria.matchesFeatureName(node.getName()); |
116 | } |
117 | |
118 | protected void preprocessFeatureNode(FeatureNode node) { |
119 | if (scopeCriteria.isMatchingFeatures()) { |
120 | super.preprocessFeatureNode(node); |
121 | } |
122 | } |
123 | |
124 | protected void postprocessFeatureNode(FeatureNode node) { |
125 | if (scopeCriteria.isMatchingFeatures()) { |
126 | super.postprocessFeatureNode(node); |
127 | } |
128 | } |
129 | |
130 | public void visitInboundFeatureNode(FeatureNode node) { |
131 | if (getCurrentNode() != null && filterCriteria.matchesFeatureName(node.getName())) { |
132 | if (filterCriteria.isMatchingFeatures()) { |
133 | copy(getFilterFactory(), node).addDependency(getCurrentNode()); |
134 | } else if (filterCriteria.isMatchingClasses()) { |
135 | copy(getFilterFactory(), node.getClassNode()).addDependency(getCurrentNode()); |
136 | } else if (filterCriteria.isMatchingPackages()) { |
137 | copy(getFilterFactory(), node.getClassNode().getPackageNode()).addDependency(getCurrentNode()); |
138 | } |
139 | } |
140 | } |
141 | |
142 | public void visitOutboundFeatureNode(FeatureNode node) { |
143 | if (getCurrentNode() != null && filterCriteria.matchesFeatureName(node.getName())) { |
144 | if (filterCriteria.isMatchingFeatures()) { |
145 | getCurrentNode().addDependency(copy(getFilterFactory(), node)); |
146 | } else if (filterCriteria.isMatchingClasses()) { |
147 | getCurrentNode().addDependency(copy(getFilterFactory(), node.getClassNode())); |
148 | } else if (filterCriteria.isMatchingPackages()) { |
149 | getCurrentNode().addDependency(copy(getFilterFactory(), node.getClassNode().getPackageNode())); |
150 | } |
151 | } |
152 | } |
153 | } |