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.diff;
034:
035: import java.util.*;
036:
037: import org.apache.log4j.*;
038:
039: import com.jeantessier.classreader.*;
040:
041: /**
042: * Documents the difference, if any, for a given object
043: * type (class or interface). Its subclasses only
044: * differ in which Visitor callback they invoke.
045: *
046: * @see Visitor
047: */
048: public class ClassDifferences extends RemovableDifferences {
049: private Classfile oldClass;
050: private Classfile newClass;
051:
052: private boolean declarationModified;
053: private Collection<Differences> featureDifferences = new LinkedList<Differences>();
054:
055: /**
056: * Only the DifferencesFactory can create instances of this class.
057: */
058: ClassDifferences(String name, Classfile oldClass, Classfile newClass) {
059: super (name);
060:
061: setOldClass(oldClass);
062: setNewClass(newClass);
063:
064: if (oldClass != null) {
065: setOldDeclaration(oldClass.getDeclaration());
066: }
067:
068: if (newClass != null) {
069: setNewDeclaration(newClass.getDeclaration());
070: }
071:
072: if (isModified()) {
073: Logger.getLogger(getClass()).debug(
074: getName() + " declaration has been modified.");
075: } else {
076: Logger.getLogger(getClass()).debug(
077: getName() + " declaration has not been modified.");
078: }
079: }
080:
081: public Classfile getOldClass() {
082: return oldClass;
083: }
084:
085: protected void setOldClass(Classfile oldClass) {
086: this .oldClass = oldClass;
087: }
088:
089: public Classfile getNewClass() {
090: return newClass;
091: }
092:
093: protected void setNewClass(Classfile newClass) {
094: this .newClass = newClass;
095: }
096:
097: public boolean isDeclarationModified() {
098: return declarationModified;
099: }
100:
101: /**
102: * Only the DifferencesFactory can set this flag
103: */
104: void setDeclarationModified(boolean declarationModified) {
105: this .declarationModified = declarationModified;
106: }
107:
108: public Collection<Differences> getFeatureDifferences() {
109: return featureDifferences;
110: }
111:
112: public boolean isModified() {
113: return isDeclarationModified()
114: || (getFeatureDifferences().size() != 0);
115: }
116:
117: public void accept(Visitor visitor) {
118: visitor.visitClassDifferences(this);
119: }
120: }
|