001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.dependency;
034:
035: public class GraphSummarizer extends GraphCopier {
036: private SelectionCriteria scopeCriteria;
037: private SelectionCriteria filterCriteria;
038:
039: public GraphSummarizer(SelectionCriteria scopeCriteria,
040: SelectionCriteria filterCriteria) {
041: super (new SelectiveTraversalStrategy(scopeCriteria,
042: filterCriteria));
043:
044: this .scopeCriteria = scopeCriteria;
045: this .filterCriteria = filterCriteria;
046: }
047:
048: protected boolean isInScope(PackageNode node) {
049: return scopeCriteria.matchesPackageName(node.getName());
050: }
051:
052: protected void preprocessPackageNode(PackageNode node) {
053: if (scopeCriteria.isMatchingPackages()) {
054: super .preprocessPackageNode(node);
055: }
056: }
057:
058: protected void postprocessPackageNode(PackageNode node) {
059: if (scopeCriteria.isMatchingPackages()) {
060: super .postprocessPackageNode(node);
061: }
062: }
063:
064: public void visitInboundPackageNode(PackageNode node) {
065: if (getCurrentNode() != null
066: && filterCriteria.matchesPackageName(node.getName())) {
067: if (filterCriteria.isMatchingPackages()) {
068: copy(getFilterFactory(), node).addDependency(
069: getCurrentNode());
070: }
071: }
072: }
073:
074: public void visitOutboundPackageNode(PackageNode node) {
075: if (getCurrentNode() != null
076: && filterCriteria.matchesPackageName(node.getName())) {
077: if (filterCriteria.isMatchingPackages()) {
078: getCurrentNode().addDependency(
079: copy(getFilterFactory(), node));
080: }
081: }
082: }
083:
084: protected boolean isInScope(ClassNode node) {
085: return scopeCriteria.matchesClassName(node.getName());
086: }
087:
088: protected void preprocessClassNode(ClassNode node) {
089: if (scopeCriteria.isMatchingClasses()) {
090: super .preprocessClassNode(node);
091: }
092: }
093:
094: protected void postprocessClassNode(ClassNode node) {
095: if (scopeCriteria.isMatchingClasses()) {
096: super .postprocessClassNode(node);
097: }
098: }
099:
100: public void visitInboundClassNode(ClassNode node) {
101: if (getCurrentNode() != null
102: && filterCriteria.matchesClassName(node.getName())) {
103: if (filterCriteria.isMatchingClasses()) {
104: copy(getFilterFactory(), node).addDependency(
105: getCurrentNode());
106: } else if (filterCriteria.isMatchingPackages()) {
107: copy(getFilterFactory(), node.getPackageNode())
108: .addDependency(getCurrentNode());
109: }
110: }
111: }
112:
113: public void visitOutboundClassNode(ClassNode node) {
114: if (getCurrentNode() != null
115: && filterCriteria.matchesClassName(node.getName())) {
116: if (filterCriteria.isMatchingClasses()) {
117: getCurrentNode().addDependency(
118: copy(getFilterFactory(), node));
119: } else if (filterCriteria.isMatchingPackages()) {
120: getCurrentNode()
121: .addDependency(
122: copy(getFilterFactory(), node
123: .getPackageNode()));
124: }
125: }
126: }
127:
128: protected boolean isInScope(FeatureNode node) {
129: return scopeCriteria.matchesFeatureName(node.getName());
130: }
131:
132: protected void preprocessFeatureNode(FeatureNode node) {
133: if (scopeCriteria.isMatchingFeatures()) {
134: super .preprocessFeatureNode(node);
135: }
136: }
137:
138: protected void postprocessFeatureNode(FeatureNode node) {
139: if (scopeCriteria.isMatchingFeatures()) {
140: super .postprocessFeatureNode(node);
141: }
142: }
143:
144: public void visitInboundFeatureNode(FeatureNode node) {
145: if (getCurrentNode() != null
146: && filterCriteria.matchesFeatureName(node.getName())) {
147: if (filterCriteria.isMatchingFeatures()) {
148: copy(getFilterFactory(), node).addDependency(
149: getCurrentNode());
150: } else if (filterCriteria.isMatchingClasses()) {
151: copy(getFilterFactory(), node.getClassNode())
152: .addDependency(getCurrentNode());
153: } else if (filterCriteria.isMatchingPackages()) {
154: copy(getFilterFactory(),
155: node.getClassNode().getPackageNode())
156: .addDependency(getCurrentNode());
157: }
158: }
159: }
160:
161: public void visitOutboundFeatureNode(FeatureNode node) {
162: if (getCurrentNode() != null
163: && filterCriteria.matchesFeatureName(node.getName())) {
164: if (filterCriteria.isMatchingFeatures()) {
165: getCurrentNode().addDependency(
166: copy(getFilterFactory(), node));
167: } else if (filterCriteria.isMatchingClasses()) {
168: getCurrentNode().addDependency(
169: copy(getFilterFactory(), node.getClassNode()));
170: } else if (filterCriteria.isMatchingPackages()) {
171: getCurrentNode().addDependency(
172: copy(getFilterFactory(), node.getClassNode()
173: .getPackageNode()));
174: }
175: }
176: }
177: }
|