org.eclipse.emf.compare.diff.engine
Class GenericDiffEngine

java.lang.Object
  extended by org.eclipse.emf.compare.diff.engine.GenericDiffEngine
All Implemented Interfaces:
IDiffEngine

public class GenericDiffEngine
extends java.lang.Object
implements IDiffEngine

This class is useful when one wants to determine a diff from a matching model.


Field Summary
protected static int ANCESTOR_OBJECT
          Allows retrieval of the ancestor matched object.
protected static int LEFT_OBJECT
          Allows retrieval of the left matched object.
protected  org.eclipse.emf.ecore.util.EcoreUtil.CrossReferencer matchCrossReferencer
          If we're currently doing a resourceSet differencing, this will have been initialized with the whole MatchResourceSet.
protected static int RIGHT_OBJECT
          Allows retrieval of the right matched object.
 
Constructor Summary
GenericDiffEngine()
           
 
Method Summary
protected  void addInContainerPackage(DiffGroup root, DiffElement operation, org.eclipse.emf.ecore.EObject targetParent)
          Looks for an already created diff group in order to add the operation, if none exists, create one where the operation belongs to.
protected  void checkAttributesUpdates(DiffGroup root, Match2Elements mapping)
          Deprecated. Override AttributesCheck.checkAttributesUpdates(DiffGroup, Match2Elements) and return your overriden implementation through getAttributesChecker().
protected  void checkAttributesUpdates(DiffGroup root, Match3Elements mapping)
          Deprecated. Override AttributesCheck.checkAttributesUpdates(DiffGroup, Match3Elements) and return your overriden implementation through getAttributesChecker().
protected  void checkContainmentUpdate(DiffGroup current, Match2Elements matchElement)
          This will check whether the left and right element are contained in the same containment reference and create a difference if need be.
protected  void checkContainmentUpdate(DiffGroup root, Match3Elements matchElement)
          This will check whether the left and right element are contained in the same containment reference and create a difference if need be.
protected  void checkForDiffs(DiffGroup current, Match2Elements match)
          This will call all the different checks we need to call for when computing the diff.
protected  void checkForDiffs(DiffGroup current, Match3Elements match)
          This will call all the different checks we need to call for when computing the diff.
protected  void checkMoves(DiffGroup root, Match2Elements matchElement)
          This will check if the elements matched by a given Match2Elements have been moved.
protected  void checkMoves(DiffGroup root, Match3Elements matchElement)
          This will check if the elements matched by a given Match3Element have been moved since the models common ancestor.
protected  void checkReferenceOrderChange(DiffGroup root, org.eclipse.emf.ecore.EReference reference, org.eclipse.emf.ecore.EObject leftElement, org.eclipse.emf.ecore.EObject rightElement, java.util.List<ReferenceChangeLeftTarget> addedReferences, java.util.List<ReferenceChangeRightTarget> removedReferences)
          Deprecated. Replaced by ReferencesCheck.
protected  void checkReferencesUpdates(DiffGroup root, Match2Elements mapping)
          Deprecated. Override ReferencesCheck.checkReferencesUpdates(DiffGroup, Match2Elements) and return your overriden implementation through getReferencesChecker().
protected  void checkReferencesUpdates(DiffGroup root, Match3Elements mapping)
          Deprecated. Override ReferencesCheck.checkReferencesUpdates(DiffGroup, Match3Elements) and return your overriden implementation through getReferencesChecker().
 DiffModel doDiff(MatchModel match)
          Return a diffmodel created using the match model.
 DiffModel doDiff(MatchModel match, boolean threeWay)
          Return a diffmodel created using the match model.
 DiffModel doDiffResourceSet(MatchModel match, boolean threeWay, org.eclipse.emf.ecore.util.EcoreUtil.CrossReferencer crossReferencer)
          Return a diffmodel created using the given match model.
protected  DiffGroup doDiffThreeWay(MatchModel match)
          The diff computing for three way comparisons is handled here.
protected  DiffGroup doDiffTwoWay(MatchModel match)
          The diff computing for two way comparisons is handled here.
protected  AttributesCheck getAttributesChecker()
          Returns the implementation of a AbstractCheck responsible for the verification of updates on attribute values.
protected  org.eclipse.emf.ecore.EObject getMatchedEObject(org.eclipse.emf.ecore.EObject from)
          Return the left or right matched EObject from the one given.
protected  org.eclipse.emf.ecore.EObject getMatchedEObject(org.eclipse.emf.ecore.EObject from, int side)
          Return the specified matched EObject from the one given.
protected  ReferencesCheck getReferencesChecker()
          Returns the implementation of a AbstractCheck responsible for the verification of updates on reference values.
protected  void log(java.lang.Exception e)
          Log an error.
protected  void processUnmatchedElements(DiffGroup diffRoot, java.util.List<UnmatchElement> unmatched)
          This will process the unmatched elements list and create the appropriate DiffElements.
 void reset()
          This will be called with each access from the service to the singleton instance of this engine.
protected  boolean shouldBeIgnored(org.eclipse.emf.ecore.EAttribute attribute)
          Deprecated. Replaced by AttributesCheck.
protected  boolean shouldBeIgnored(org.eclipse.emf.ecore.EReference reference)
          Deprecated. Replaced by ReferencesCheck.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANCESTOR_OBJECT

protected static final int ANCESTOR_OBJECT
Allows retrieval of the ancestor matched object.

See Also:
Constant Field Values

LEFT_OBJECT

protected static final int LEFT_OBJECT
Allows retrieval of the left matched object.

See Also:
Constant Field Values

RIGHT_OBJECT

protected static final int RIGHT_OBJECT
Allows retrieval of the right matched object.

See Also:
Constant Field Values

matchCrossReferencer

protected org.eclipse.emf.ecore.util.EcoreUtil.CrossReferencer matchCrossReferencer
If we're currently doing a resourceSet differencing, this will have been initialized with the whole MatchResourceSet.

Constructor Detail

GenericDiffEngine

public GenericDiffEngine()
Method Detail

doDiff

public DiffModel doDiff(MatchModel match)
Return a diffmodel created using the match model. This implementation is a generic and simple one.

Specified by:
doDiff in interface IDiffEngine
Parameters:
match - The matching model.
Returns:
The corresponding diff model.
See Also:
IDiffEngine.doDiff(org.eclipse.emf.compare.match.metamodel.MatchModel)

doDiff

public DiffModel doDiff(MatchModel match,
                        boolean threeWay)
Return a diffmodel created using the match model. This implementation is a generic and simple one.

Specified by:
doDiff in interface IDiffEngine
Parameters:
match - the matching model
threeWay - True if we're computing a three way comparison, False otherwise.
Returns:
the corresponding diff model
See Also:
IDiffEngine.doDiff(org.eclipse.emf.compare.match.metamodel.MatchModel, boolean)

doDiffResourceSet

public DiffModel doDiffResourceSet(MatchModel match,
                                   boolean threeWay,
                                   org.eclipse.emf.ecore.util.EcoreUtil.CrossReferencer crossReferencer)
Return a diffmodel created using the given match model. crossReferencer has been initialized on the whole MatchResourceSet.

Specified by:
doDiffResourceSet in interface IDiffEngine
Parameters:
match - the matching model
threeWay - True if we're computing a three way comparison, False otherwise.
crossReferencer - This cross referencer has been initialized with the whole MatchResourceSet and can be used to retrieve matched EObjects towards other resources.
Returns:
the corresponding diff model
See Also:
IDiffEngine.doDiffResourceSet(org.eclipse.emf.compare.match.metamodel.MatchModel, boolean, org.eclipse.emf.ecore.util.EcoreUtil.CrossReferencer)

reset

public void reset()
This will be called with each access from the service to the singleton instance of this engine. Clients should dispose of all caches and recorded information within this method's implementation.

Specified by:
reset in interface IDiffEngine
See Also:
IDiffEngine.reset()

addInContainerPackage

protected void addInContainerPackage(DiffGroup root,
                                     DiffElement operation,
                                     org.eclipse.emf.ecore.EObject targetParent)
Looks for an already created diff group in order to add the operation, if none exists, create one where the operation belongs to.

Parameters:
root - root of the DiffModel.
operation - Operation to add to the DiffModel.
targetParent - Parent EObject for the operation.

getAttributesChecker

protected AttributesCheck getAttributesChecker()
Returns the implementation of a AbstractCheck responsible for the verification of updates on attribute values.

Returns:
The implementation of a AbstractCheck responsible for the verification of updates on attribute values.
Since:
1.0

getReferencesChecker

protected ReferencesCheck getReferencesChecker()
Returns the implementation of a AbstractCheck responsible for the verification of updates on reference values.

Returns:
The implementation of a AbstractCheck responsible for the verification of updates on reference values.
Since:
1.0

checkAttributesUpdates

@Deprecated
protected void checkAttributesUpdates(DiffGroup root,
                                                 Match2Elements mapping)
                               throws FactoryException
Deprecated. Override AttributesCheck.checkAttributesUpdates(DiffGroup, Match2Elements) and return your overriden implementation through getAttributesChecker().

This will iterate through all the attributes of the mapping's two elements to check if any of them has been modified.

Parameters:
root - root of the DiffElement to create if one of the attributes has actually been changed.
mapping - This contains the mapping information about the elements we need to check.
Throws:
FactoryException - Thrown if one of the checks fails.

checkAttributesUpdates

@Deprecated
protected void checkAttributesUpdates(DiffGroup root,
                                                 Match3Elements mapping)
                               throws FactoryException
Deprecated. Override AttributesCheck.checkAttributesUpdates(DiffGroup, Match3Elements) and return your overriden implementation through getAttributesChecker().

This will iterate through all the attributes of the mapping's three elements to check if any of them has been modified.

Parameters:
root - root of the DiffElement to create if one of the attribute has actually been changed.
mapping - This contains the mapping information about the elements we need to check for a move.
Throws:
FactoryException - Thrown if one of the checks fails.

checkContainmentUpdate

protected void checkContainmentUpdate(DiffGroup current,
                                      Match2Elements matchElement)
This will check whether the left and right element are contained in the same containment reference and create a difference if need be.

Parameters:
current - DiffGroup under which the new differences will be added.
matchElement - This contains the mapping information about the elements we need to check for a containment reference update.

checkContainmentUpdate

protected void checkContainmentUpdate(DiffGroup root,
                                      Match3Elements matchElement)
This will check whether the left and right element are contained in the same containment reference and create a difference if need be.

Parameters:
root - DiffGroup under which the new differences will be added.
matchElement - This contains the mapping information about the elements we need to check for a containment reference update.

checkForDiffs

protected void checkForDiffs(DiffGroup current,
                             Match2Elements match)
                      throws FactoryException
This will call all the different checks we need to call for when computing the diff. Clients can override this to alter the checks or add others.

Parameters:
current - current DiffGroup under which the new differences will be added.
match - This contains the mapping information about the elements we need to check for a move.
Throws:
FactoryException - Thrown if one of the checks fails somehow.

checkForDiffs

protected void checkForDiffs(DiffGroup current,
                             Match3Elements match)
                      throws FactoryException
This will call all the different checks we need to call for when computing the diff. Clients can override this to alter the checks or add others.

Parameters:
current - current DiffGroup under which the new differences will be added.
match - This contains the mapping information about the elements we need to check for a move.
Throws:
FactoryException - Thrown if one of the checks fails somehow.

checkMoves

protected void checkMoves(DiffGroup root,
                          Match2Elements matchElement)
This will check if the elements matched by a given Match2Elements have been moved.

Parameters:
root - root of the DiffElement to create if the elements have actually been moved.
matchElement - This contains the mapping information about the elements we need to check for a move.

checkMoves

protected void checkMoves(DiffGroup root,
                          Match3Elements matchElement)
This will check if the elements matched by a given Match3Element have been moved since the models common ancestor.

Parameters:
root - root of the DiffElement to create if the elements have actually been moved.
matchElement - This contains the mapping information about the elements we need to check for a move.

checkReferenceOrderChange

@Deprecated
protected void checkReferenceOrderChange(DiffGroup root,
                                                    org.eclipse.emf.ecore.EReference reference,
                                                    org.eclipse.emf.ecore.EObject leftElement,
                                                    org.eclipse.emf.ecore.EObject rightElement,
                                                    java.util.List<ReferenceChangeLeftTarget> addedReferences,
                                                    java.util.List<ReferenceChangeRightTarget> removedReferences)
                                  throws FactoryException
Deprecated. Replaced by ReferencesCheck.

This will be called to check for changes on a given reference values. Note that we know reference.isMany() and reference.isOrdered() always return true here for the generic diff engine and the tests won't be made.

Parameters:
root - Root of the DiffElements to create.
reference - EReference to check for modifications.
leftElement - Element corresponding to the final value for the given reference.
rightElement - Element corresponding to the initial value for the given reference.
addedReferences - Contains the created differences for added reference values.
removedReferences - Contains the created differences for removed reference values.
Throws:
FactoryException - Thrown if we cannot fetch the references' values.

checkReferencesUpdates

@Deprecated
protected void checkReferencesUpdates(DiffGroup root,
                                                 Match2Elements mapping)
                               throws FactoryException
Deprecated. Override ReferencesCheck.checkReferencesUpdates(DiffGroup, Match2Elements) and return your overriden implementation through getReferencesChecker().

Checks if there's been references updates in the model.

A reference is considered updated if its value(s) has been changed (either removal or addition of an element if the reference is multi-valued or update of a single-valued reference) between the left and the right model.

Parameters:
root - root of the DiffElement to create.
mapping - Contains informations about the left and right model elements we have to compare.
Throws:
FactoryException - Thrown if we cannot fetch the references' values.

checkReferencesUpdates

@Deprecated
protected void checkReferencesUpdates(DiffGroup root,
                                                 Match3Elements mapping)
                               throws FactoryException
Deprecated. Override ReferencesCheck.checkReferencesUpdates(DiffGroup, Match3Elements) and return your overriden implementation through getReferencesChecker().

Checks if there's been references updates in the model.

A reference is considered updated if its value(s) has been changed (either removal or addition of an element if the reference is multi-valued or update of a single-valued reference) between the left and the ancestor model, the right and the ancestor or between the left and the right model.

Parameters:
root - root of the DiffElement to create.
mapping - Contains informations about the left, right and origin model elements we have to compare.
Throws:
FactoryException - Thrown if we cannot fetch the references' values.

doDiffThreeWay

protected DiffGroup doDiffThreeWay(MatchModel match)
The diff computing for three way comparisons is handled here. We'll compute the diff model from the given match model.

Parameters:
match - match model we'll be using to compute the differences.
Returns:
root of the DiffModel computed from the given MatchModel.

doDiffTwoWay

protected DiffGroup doDiffTwoWay(MatchModel match)
The diff computing for two way comparisons is handled here. We'll compute the diff model from the given match model.

Parameters:
match - match model we'll be using to compute the differences.
Returns:
root of the DiffModel computed from the given MatchModel.

getMatchedEObject

protected final org.eclipse.emf.ecore.EObject getMatchedEObject(org.eclipse.emf.ecore.EObject from)
Return the left or right matched EObject from the one given. More specifically, this will return the left matched element if the given EObject is the right one, or the right matched element if the given EObject is either the left or the origin one.

Parameters:
from - The original EObject.
Returns:
The matched EObject.

getMatchedEObject

protected final org.eclipse.emf.ecore.EObject getMatchedEObject(org.eclipse.emf.ecore.EObject from,
                                                                int side)
                                                         throws java.lang.IllegalArgumentException
Return the specified matched EObject from the one given.

Parameters:
from - The original EObject.
side - side of the object we seek. Must be one of .
Returns:
The matched EObject.
Throws:
java.lang.IllegalArgumentException - Thrown if side is invalid.

processUnmatchedElements

protected void processUnmatchedElements(DiffGroup diffRoot,
                                        java.util.List<UnmatchElement> unmatched)
This will process the unmatched elements list and create the appropriate DiffElements.

Parameters:
diffRoot - DiffGroup under which to create the DiffElements.
unmatched - The MatchModel's UnmatchElements.

shouldBeIgnored

@Deprecated
protected boolean shouldBeIgnored(org.eclipse.emf.ecore.EAttribute attribute)
Deprecated. Replaced by AttributesCheck.

Determines if we should ignore an attribute for diff detection.

Default is to ignore attributes marked either

Clients should override this if they wish to ignore other attributes.

Parameters:
attribute - Attribute to determine whether it should be ignored.
Returns:
True if attribute has to be ignored, False otherwise.

shouldBeIgnored

@Deprecated
protected boolean shouldBeIgnored(org.eclipse.emf.ecore.EReference reference)
Deprecated. Replaced by ReferencesCheck.

Determines if we should ignore a reference for diff detection.

Default is to ignore references marked either

Clients should override this if they wish to ignore other references.

Parameters:
reference - Reference to determine whether it should be ignored.
Returns:
True if reference has to be ignored, False otherwise.

log

protected void log(java.lang.Exception e)
Log an error. Clients may override this to perform custom logging.

Parameters:
e - any Exception.
Since:
1.1

Copyright 2006 IBM Corporation and others.
All Rights Reserved.