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 GraphCopier extends VisitorBase {
036: private NodeFactory scopeFactory = new NodeFactory();
037: private NodeFactory filterFactory = new NodeFactory();
038:
039: public GraphCopier() {
040: super ();
041: }
042:
043: public GraphCopier(TraversalStrategy strategy) {
044: super (strategy);
045: }
046:
047: public NodeFactory getScopeFactory() {
048: return scopeFactory;
049: }
050:
051: public NodeFactory getFilterFactory() {
052: return filterFactory;
053: }
054:
055: protected void preprocessPackageNode(PackageNode node) {
056: super .preprocessPackageNode(copy(getScopeFactory(), node));
057: }
058:
059: public void visitInboundPackageNode(PackageNode node) {
060: if (getStrategy().isInFilter(node)) {
061: copy(getFilterFactory(), node).addDependency(
062: getCurrentNode());
063: }
064: }
065:
066: public void visitOutboundPackageNode(PackageNode node) {
067: if (getStrategy().isInFilter(node)) {
068: getCurrentNode().addDependency(
069: copy(getFilterFactory(), node));
070: }
071: }
072:
073: protected void preprocessClassNode(ClassNode node) {
074: super .preprocessClassNode(copy(getScopeFactory(), node));
075: }
076:
077: public void visitInboundClassNode(ClassNode node) {
078: if (getStrategy().isInFilter(node)) {
079: copy(getFilterFactory(), node).addDependency(
080: getCurrentNode());
081: }
082: }
083:
084: public void visitOutboundClassNode(ClassNode node) {
085: if (getStrategy().isInFilter(node)) {
086: getCurrentNode().addDependency(
087: copy(getFilterFactory(), node));
088: }
089: }
090:
091: protected void preprocessFeatureNode(FeatureNode node) {
092: NodeFactory factory = getScopeFactory();
093: super .preprocessFeatureNode(copy(factory, node));
094: }
095:
096: public void visitInboundFeatureNode(FeatureNode node) {
097: if (getStrategy().isInFilter(node)) {
098: copy(getFilterFactory(), node).addDependency(
099: getCurrentNode());
100: }
101: }
102:
103: public void visitOutboundFeatureNode(FeatureNode node) {
104: if (getStrategy().isInFilter(node)) {
105: getCurrentNode().addDependency(
106: copy(getFilterFactory(), node));
107: }
108: }
109:
110: protected PackageNode copy(NodeFactory factory, PackageNode node) {
111: return factory
112: .createPackage(node.getName(), node.isConfirmed());
113: }
114:
115: protected ClassNode copy(NodeFactory factory, ClassNode node) {
116: copy(factory, node.getPackageNode());
117: return factory.createClass(node.getName(), node.isConfirmed());
118: }
119:
120: protected FeatureNode copy(NodeFactory factory, FeatureNode node) {
121: copy(factory, node.getClassNode());
122: return factory
123: .createFeature(node.getName(), node.isConfirmed());
124: }
125: }
|