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 class SelectiveTraversalStrategy implements TraversalStrategy {
038: private SelectionCriteria scopeCriteria;
039: private SelectionCriteria filterCriteria;
040:
041: private boolean preOutboundTraversal = true;
042: private boolean preInboundTraversal = true;
043: private boolean postOutboundTraversal = false;
044: private boolean postInboundTraversal = false;
045:
046: public SelectiveTraversalStrategy() {
047: this (new ComprehensiveSelectionCriteria(),
048: new ComprehensiveSelectionCriteria());
049: }
050:
051: public SelectiveTraversalStrategy(SelectionCriteria scopeCriteria,
052: SelectionCriteria filterCriteria) {
053: this .scopeCriteria = scopeCriteria;
054: this .filterCriteria = filterCriteria;
055: }
056:
057: public boolean doPreOutboundTraversal() {
058: return preOutboundTraversal;
059: }
060:
061: public void setPreOutboundTraversal(boolean preOutboundTraversal) {
062: this .preOutboundTraversal = preOutboundTraversal;
063: }
064:
065: public boolean doPreInboundTraversal() {
066: return preInboundTraversal;
067: }
068:
069: public void setPreInboundTraversal(boolean preInboundTraversal) {
070: this .preInboundTraversal = preInboundTraversal;
071: }
072:
073: public boolean doPostOutboundTraversal() {
074: return postOutboundTraversal;
075: }
076:
077: public void setPostOutboundTraversal(boolean postOutboundTraversal) {
078: this .postOutboundTraversal = postOutboundTraversal;
079: }
080:
081: public boolean doPostInboundTraversal() {
082: return postInboundTraversal;
083: }
084:
085: public void setPostInboundTraversal(boolean postInboundTraversal) {
086: this .postInboundTraversal = postInboundTraversal;
087: }
088:
089: public boolean isInScope(PackageNode node) {
090: return scopeCriteria.matches(node);
091: }
092:
093: public boolean isInScope(ClassNode node) {
094: return scopeCriteria.matches(node);
095: }
096:
097: public boolean isInScope(FeatureNode node) {
098: return scopeCriteria.matches(node);
099: }
100:
101: public boolean isInFilter(PackageNode node) {
102: return filterCriteria.matches(node);
103: }
104:
105: public boolean isInFilter(ClassNode node) {
106: return filterCriteria.matches(node);
107: }
108:
109: public boolean isInFilter(FeatureNode node) {
110: return filterCriteria.matches(node);
111: }
112:
113: public Collection<? extends Node> order(
114: Collection<? extends Node> collection) {
115: return new ArrayList<Node>(collection);
116: }
117: }
|