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

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

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 static int RIGHT_OBJECT
          Allows retrieval of the right matched object.
protected  java.util.Map<UnMatchElement,java.lang.Boolean> unMatchedElements
          This map will keep track of the top level unmatched elements, as well as whether they are conflicting.
 
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)
          This will iterate through all the attributes of the mapping's two elements to check if any of them has been modified.
protected  void checkAttributesUpdates(DiffGroup root, Match3Element mapping)
          This will iterate through all the attributes of the mapping's three elements to check if any of them has been modified.
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, Match3Element 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, Match3Element matchElement)
          This will check if the elements matched by a given Match3Element have been moved since the models common ancestor.
protected  void checkReferencesUpdates(DiffGroup root, Match2Elements mapping)
          Checks if there's been references updates in the model.
protected  void checkReferencesUpdates(DiffGroup root, Match3Element mapping)
          Checks if there's been references updates in the model.
 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.
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  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  void processUnMatchedElements(DiffGroup diffRoot, org.eclipse.emf.ecore.resource.Resource leftModel, java.util.List<UnMatchElement> unMatched)
          This will process the unmatched elements list and create the appropriate DiffElements.
protected  void processUnMatchedElements(DiffGroup diffRoot, org.eclipse.emf.ecore.resource.Resource leftModel, java.util.Map<UnMatchElement,java.lang.Boolean> 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)
          Determines if we should ignore an attribute for diff detection.
protected  boolean shouldBeIgnored(org.eclipse.emf.ecore.EReference reference)
          Determines if we should ignore a reference for diff detection.
 
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

unMatchedElements

protected final java.util.Map<UnMatchElement,java.lang.Boolean> unMatchedElements
This map will keep track of the top level unmatched elements, as well as whether they are conflicting.

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)

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.

checkAttributesUpdates

protected void checkAttributesUpdates(DiffGroup root,
                                      Match2Elements mapping)
                               throws FactoryException
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 for a move.
Throws:
FactoryException - Thrown if one of the checks fails.

checkAttributesUpdates

protected void checkAttributesUpdates(DiffGroup root,
                                      Match3Element mapping)
                               throws FactoryException
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.

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,
                             Match3Element 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,
                          Match3Element 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.

checkReferencesUpdates

protected void checkReferencesUpdates(DiffGroup root,
                                      Match2Elements mapping)
                               throws FactoryException
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

protected void checkReferencesUpdates(DiffGroup root,
                                      Match3Element mapping)
                               throws FactoryException
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 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 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,
                                        org.eclipse.emf.ecore.resource.Resource leftModel,
                                        java.util.List<UnMatchElement> unMatched)
This will process the unmatched elements list and create the appropriate DiffElements.

This is called for two-way comparison. Clients can override this to alter the checks or add their own.

Parameters:
diffRoot - DiffGroup under which to create the DiffElements.
leftModel - Resource representing the left model.
unMatched - The MatchModel's UnMatchElements.

processUnMatchedElements

protected void processUnMatchedElements(DiffGroup diffRoot,
                                        org.eclipse.emf.ecore.resource.Resource leftModel,
                                        java.util.Map<UnMatchElement,java.lang.Boolean> unMatched)
This will process the unmatched elements list and create the appropriate DiffElements.

This is called for three-way comparison. Clients can override this to alter the checks or add their own.

Parameters:
diffRoot - DiffGroup under which to create the DiffElements.
leftModel - Resource representing the left model.
unMatched - The MatchModel's UnMatchElements.

shouldBeIgnored

protected boolean shouldBeIgnored(org.eclipse.emf.ecore.EAttribute attribute)
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

protected boolean shouldBeIgnored(org.eclipse.emf.ecore.EReference reference)
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.

Copyright 2006 IBM Corporation and others.
All Rights Reserved.