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 LinkMinimizer extends VisitorBase {
036: public LinkMinimizer() {
037: super ();
038:
039: getStrategy().setPreOutboundTraversal(false);
040: getStrategy().setPreInboundTraversal(false);
041: getStrategy().setPostOutboundTraversal(false);
042: getStrategy().setPostInboundTraversal(false);
043: }
044:
045: public LinkMinimizer(TraversalStrategy strategy) {
046: super (strategy);
047:
048: getStrategy().setPreOutboundTraversal(false);
049: getStrategy().setPreInboundTraversal(false);
050: getStrategy().setPostOutboundTraversal(false);
051: getStrategy().setPostInboundTraversal(false);
052: }
053:
054: protected void postprocessPackageNode(PackageNode node) {
055: traverseOutbound(node.getOutboundDependencies());
056:
057: super .postprocessPackageNode(node);
058: }
059:
060: protected void postprocessClassNode(ClassNode node) {
061: for (Node target : getStrategy().order(
062: node.getOutboundDependencies())) {
063: node.getPackageNode().removeDependency(target);
064:
065: target.acceptOutbound(this );
066:
067: pushNode(node.getPackageNode());
068: target.acceptOutbound(this );
069: popNode();
070: }
071:
072: super .postprocessClassNode(node);
073: }
074:
075: public void visitOutboundClassNode(ClassNode node) {
076: getCurrentNode().removeDependency(node.getPackageNode());
077: }
078:
079: protected void postprocessFeatureNode(FeatureNode node) {
080: for (Node target : getStrategy().order(
081: node.getOutboundDependencies())) {
082: node.getClassNode().removeDependency(target);
083: node.getClassNode().getPackageNode().removeDependency(
084: target);
085:
086: target.acceptOutbound(this );
087:
088: pushNode(node.getClassNode());
089: target.acceptOutbound(this );
090: popNode();
091:
092: pushNode(node.getClassNode().getPackageNode());
093: target.acceptOutbound(this );
094: popNode();
095: }
096:
097: super .postprocessFeatureNode(node);
098: }
099:
100: public void visitOutboundFeatureNode(FeatureNode node) {
101: getCurrentNode().removeDependency(node.getClassNode());
102: getCurrentNode().removeDependency(
103: node.getClassNode().getPackageNode());
104: }
105: }
|