org.eclipse.emf.validation.service
Class AbstractTraversalStrategy

java.lang.Object
  extended by org.eclipse.emf.validation.service.AbstractTraversalStrategy
All Implemented Interfaces:
ITraversalStrategy
Direct Known Subclasses:
ITraversalStrategy.Flat, ITraversalStrategy.Recursive

public abstract class AbstractTraversalStrategy
extends Object
implements ITraversalStrategy

An iterator-based partial implementation of the ITraversalStrategy interface. Subclasses need only compute how many elements are covered by the set of traversal roots, and an iterator that provides them all.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.eclipse.emf.validation.service.ITraversalStrategy
ITraversalStrategy.Flat, ITraversalStrategy.Recursive
 
Constructor Summary
AbstractTraversalStrategy()
          Initializes me.
 
Method Summary
protected abstract  int countElements(Collection<? extends EObject> traversalRoots)
          Implemented by subclasses to compute the number of elements that will be validated within the scope of the specified root elements.
protected abstract  Iterator<? extends EObject> createIterator(Collection<? extends EObject> traversalRoots)
          Implemented by subclasses to return an iterator that provides all of the elements to be validated, within the scope of the specified root elements.
 void elementValidated(EObject element, IStatus status)
          Implements the interface method by advancing the progress monitor by a single work unit.
protected  IProgressMonitor getProgressMonitor()
          Provides subclasses with access to the progress monitor, if they want it (for example, to set sub-task labels)
protected  String getTaskLabel()
          Can be redefined by subclasses to provide the task label for the progress monitor.
 boolean hasNext()
          Just determines whether the subclass-provided iterator has a next element.
 boolean isClientContextChanged()
          This implementation is pessimistic, always returning true to indicate that the client context should be recomputed for each object traversed.
 EObject next()
          Returns the subclass-provided iterator's next element.
 void startTraversal(Collection<? extends EObject> traversalRoots, IProgressMonitor progressMonitor)
          Initializes the traversal by asking the subclass to count the number of elements that will be validated and to create an iterator that will provide them all.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractTraversalStrategy

public AbstractTraversalStrategy()
Initializes me.

Method Detail

startTraversal

public void startTraversal(Collection<? extends EObject> traversalRoots,
                           IProgressMonitor progressMonitor)
Initializes the traversal by asking the subclass to count the number of elements that will be validated and to create an iterator that will provide them all. The progress monitor is initialized with a work unit per element (scaled to a reasonable maximum to avoid too many GUI updates).

Specified by:
startTraversal in interface ITraversalStrategy
Parameters:
traversalRoots - a collection of one or more EObjects. It is never empty, but neither is it modifiable
progressMonitor - the progress monitor used to track progress. The receiver may retain this progress monitor for the duration of the traversal

getTaskLabel

protected String getTaskLabel()
Can be redefined by subclasses to provide the task label for the progress monitor.

Returns:
the task label

countElements

protected abstract int countElements(Collection<? extends EObject> traversalRoots)
Implemented by subclasses to compute the number of elements that will be validated within the scope of the specified root elements.

Parameters:
traversalRoots - the roots of the traversal sub-trees
Returns:
the total number of elements to be validated within these sub-trees

createIterator

protected abstract Iterator<? extends EObject> createIterator(Collection<? extends EObject> traversalRoots)
Implemented by subclasses to return an iterator that provides all of the elements to be validated, within the scope of the specified root elements.

Parameters:
traversalRoots - the roots of the traversal sub-trees
Returns:
an iterator that covers all of the elements to be validated

getProgressMonitor

protected IProgressMonitor getProgressMonitor()
Provides subclasses with access to the progress monitor, if they want it (for example, to set sub-task labels)

Returns:
the progress monitor

hasNext

public boolean hasNext()
Just determines whether the subclass-provided iterator has a next element.

Specified by:
hasNext in interface ITraversalStrategy
Returns:
true if another element can be obtained from the ITraversalStrategy.next() method; false, otherwise
See Also:
createIterator(java.util.Collection)

next

public EObject next()
Returns the subclass-provided iterator's next element.

Specified by:
next in interface ITraversalStrategy
Returns:
the next element in the traversal
See Also:
createIterator(java.util.Collection)

isClientContextChanged

public boolean isClientContextChanged()
This implementation is pessimistic, always returning true to indicate that the client context should be recomputed for each object traversed.

Specified by:
isClientContextChanged in interface ITraversalStrategy
Returns:
true if the next object to be returned by the ITraversalStrategy.next() method is potentially in a different client context than the previous (thereby requiring the validation framework to recompute the context); false if the object can be assumed to be in the same context as the previous

elementValidated

public void elementValidated(EObject element,
                             IStatus status)
Implements the interface method by advancing the progress monitor by a single work unit.

Specified by:
elementValidated in interface ITraversalStrategy
Parameters:
element - the element that was validated
status - the element's validation status, indicating success or failure of its constraints. The receiver may with use this information to exclude or include portions of the model based on the status of the element

Copyright 2002, 2007 IBM Corporation and others.
All Rights Reserved.