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: import java.util.*;
036:
037: public abstract class ClosureLayerSelector extends ClosureSelector {
038: private Node currentNode;
039:
040: private Collection<? extends Node> coverage;
041:
042: public ClosureLayerSelector() {
043: super ();
044: }
045:
046: public ClosureLayerSelector(NodeFactory factory,
047: Collection<? extends Node> coverage) {
048: super (factory);
049:
050: setCoverage(coverage);
051: }
052:
053: public void reset() {
054: super .reset();
055:
056: currentNode = null;
057: }
058:
059: public Collection<? extends Node> getCoverage() {
060: return coverage;
061: }
062:
063: public void setCoverage(Collection<? extends Node> coverage) {
064: this .coverage = coverage;
065: }
066:
067: public void visitPackageNode(PackageNode node) {
068: currentNode = getFactory().createPackage(node.getName(),
069: node.isConfirmed());
070: }
071:
072: public void visitInboundPackageNode(PackageNode node) {
073: if (!getCoverage().contains(node)) {
074: getSelectedNodes().add(node);
075:
076: Node copy = getFactory().createPackage(node.getName(),
077: node.isConfirmed());
078: getCopiedNodes().add(copy);
079: copy.addDependency(currentNode);
080: }
081: }
082:
083: public void visitOutboundPackageNode(PackageNode node) {
084: if (!getCoverage().contains(node)) {
085: getSelectedNodes().add(node);
086:
087: Node copy = getFactory().createPackage(node.getName(),
088: node.isConfirmed());
089: getCopiedNodes().add(copy);
090: currentNode.addDependency(copy);
091: }
092: }
093:
094: public void visitClassNode(ClassNode node) {
095: currentNode = getFactory().createClass(node.getName(),
096: node.isConfirmed());
097: }
098:
099: public void visitInboundClassNode(ClassNode node) {
100: if (!getCoverage().contains(node)) {
101: getSelectedNodes().add(node);
102:
103: Node copy = getFactory().createClass(node.getName(),
104: node.isConfirmed());
105: getCopiedNodes().add(copy);
106: copy.addDependency(currentNode);
107: }
108: }
109:
110: public void visitOutboundClassNode(ClassNode node) {
111: if (!getCoverage().contains(node)) {
112: getSelectedNodes().add(node);
113:
114: Node copy = getFactory().createClass(node.getName(),
115: node.isConfirmed());
116: getCopiedNodes().add(copy);
117: currentNode.addDependency(copy);
118: }
119: }
120:
121: public void visitFeatureNode(FeatureNode node) {
122: currentNode = getFactory().createFeature(node.getName(),
123: node.isConfirmed());
124: }
125:
126: public void visitInboundFeatureNode(FeatureNode node) {
127: if (!getCoverage().contains(node)) {
128: getSelectedNodes().add(node);
129:
130: Node copy = getFactory().createFeature(node.getName(),
131: node.isConfirmed());
132: getCopiedNodes().add(copy);
133: copy.addDependency(currentNode);
134: }
135: }
136:
137: public void visitOutboundFeatureNode(FeatureNode node) {
138: if (!getCoverage().contains(node)) {
139: getSelectedNodes().add(node);
140:
141: Node copy = getFactory().createFeature(node.getName(),
142: node.isConfirmed());
143: getCopiedNodes().add(copy);
144: currentNode.addDependency(copy);
145: }
146: }
147: }
|