org.eclipse.wst.validation
Class ValidationFramework

java.lang.Object
  extended by org.eclipse.wst.validation.ValidationFramework

public final class ValidationFramework
extends java.lang.Object

The central class of the Validation Framework.

This is a singleton class that is accessed through the getDefault() method.

Provisional API: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.


Nested Class Summary
static class ValidationFramework.ResourceAdder
           
 
Method Summary
 void clearMessages(IResource resource, java.lang.String validatorId)
          Clear any validation markers that may have been set by this validator.
 void disableValidation(IResource resource)
          Disable all validation for the given resource.
 void enableValidation(IResource resource)
          Enable validation for the given resource.
static ValidationFramework getDefault()
          Answer the singleton, default instance of this class.
 IDependencyIndex getDependencyIndex()
          Answer the dependency index.
 java.util.Set<Validator> getDisabledValidatorsFor(IResource resource)
          Answer all the validators that should not validate the resource, either because their filters don't support the resource, or the validator has been disabled for both build validation and manual validation.
 IPerformanceMonitor getPerformanceMonitor()
          Answer a performance monitor for the validators.
 IEclipsePreferences getPreferenceStore()
          Answer the preference store that holds the global validation settings.
 IReporter getReporter(IProject project, IProgressMonitor monitor)
           
 Validator getValidator(java.lang.String id)
          Deprecated. Use getValidator(String id, IProject project) with a null project instead.
 Validator getValidator(java.lang.String id, IProject project)
          Answer the validator with the given id that is in effect for the given project.
 Validator[] getValidatorsFor(IResource resource)
          Answer all the validators that are applicable for the given resource.
 Validator[] getValidatorsFor(IResource resource, boolean isManual, boolean isBuild)
          Answer all the validators that are applicable for the given resource.
 boolean hasValidators(IResource resource, boolean isManual, boolean isBuild)
          Answer true if the resource has any enabled validators.
 boolean isProjectSuspended(IProject project)
          This method should be called by any code that is preparing to suspend validation on a project.
 boolean isSuspended()
          Return true if "suspend all" is enabled, false otherwise.
 boolean isSuspended(IProject project)
          Returns true if validation will not run on the project because it's been suspended.
 void join(IProgressMonitor monitor)
          Waits until all validation jobs are finished.
 void suspendAllValidation(boolean suspend)
          Suspends, or undoes the suspension of, validation on all projects in the workbench.
 void suspendValidation(IProject project, boolean suspend)
          Suspends, or undoes the suspension of, validation on the current project.
 ValidationResults validate(IProject[] projects, boolean isManual, boolean isBuild, IProgressMonitor monitor)
          Validate the projects.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDefault

public static ValidationFramework getDefault()
Answer the singleton, default instance of this class.


clearMessages

public void clearMessages(IResource resource,
                          java.lang.String validatorId)
                   throws CoreException
Clear any validation markers that may have been set by this validator.

Parameters:
resource - The resource that may have it's markers cleared.
validatorId - The id of validator that created the marker.
Throws:
CoreException

disableValidation

public void disableValidation(IResource resource)
Disable all validation for the given resource. This method instructs the framework to not run any validators on the given resource or any of it's children. This setting is persistent. Currently this only works with version 2 validators.

Use the enableValidation method to restore validation.

Parameters:
resource - The resource that is having validation disabled. It must be an IFolder or an IFile.
See Also:
enableValidation(IResource)

enableValidation

public void enableValidation(IResource resource)
Enable validation for the given resource. If the resource was not previously disabled this method call has no effect. Currently this only works with version 2 validators.

Parameters:
resource - The resource that is having validation re-enabled.
See Also:
disableValidation(IResource)

getDependencyIndex

public IDependencyIndex getDependencyIndex()
Answer the dependency index. Validators can use this to determine which resources depend on which other resources.


getPerformanceMonitor

public IPerformanceMonitor getPerformanceMonitor()
Answer a performance monitor for the validators.


getPreferenceStore

public IEclipsePreferences getPreferenceStore()
Answer the preference store that holds the global validation settings.


getReporter

public IReporter getReporter(IProject project,
                             IProgressMonitor monitor)

getValidatorsFor

public Validator[] getValidatorsFor(IResource resource,
                                    boolean isManual,
                                    boolean isBuild)
Answer all the validators that are applicable for the given resource. A validator is still returned even if it has been turned off by the user.

The caller may still need to test if the validator has been turned off by the user, by using the isBuildValidation() and isManualValidation() methods.

Parameters:
resource - The resource that determines which validators are applicable.
isManual - If true then the validator must be turned on for manual validation. If false then the isManualValidation setting isn't used to filter out validators.
isBuild - If true then the validator must be turned on for build based validation. If false then the isBuildValidation setting isn't used to filter out validators.
See Also:
Validator.isBuildValidation(), Validator.isManualValidation()

getDisabledValidatorsFor

public java.util.Set<Validator> getDisabledValidatorsFor(IResource resource)
Answer all the validators that should not validate the resource, either because their filters don't support the resource, or the validator has been disabled for both build validation and manual validation.

Parameters:
resource - The resource this is being tested.

getValidator

public Validator getValidator(java.lang.String id)
Deprecated. Use getValidator(String id, IProject project) with a null project instead.

Answer the global validator with the given id.

Parameters:
id -
Returns:
null if the validator is not found

getValidator

public Validator getValidator(java.lang.String id,
                              IProject project)
Answer the validator with the given id that is in effect for the given project.

Individual projects may override the global validation preference settings. If this is allowed and if the project has it's own settings, then those validators are returned via this method.

The following approach is used. For version 1 validators, the validator is only returned if it is defined to operate on this project type. This is the way that the previous version of the framework did it. For version 2 validators, they are all returned.

Parameters:
id - Validator id.
project - This can be null, in which case all the registered validators are checked.
Returns:
null if the validator is not found

getValidatorsFor

public Validator[] getValidatorsFor(IResource resource)
Answer all the validators that are applicable for the given resource.

Parameters:
resource - the resource that determines which validators are applicable.

hasValidators

public boolean hasValidators(IResource resource,
                             boolean isManual,
                             boolean isBuild)
Answer true if the resource has any enabled validators.

Parameters:
resource - A file, folder or project.
isManual - If true then the validator must be turned on for manual validation. If false then the isManualValidation setting isn't used to filter out validators.
isBuild - If true then the validator must be turned on for build based validation. If false then the isBuildValidation setting isn't used to filter out validators.

join

public void join(IProgressMonitor monitor)
          throws java.lang.InterruptedException,
                 OperationCanceledException
Waits until all validation jobs are finished. This method will block the calling thread until all such jobs have finished executing, or until this thread is interrupted. If there are no validation jobs that are currently waiting, running, or sleeping, this method returns immediately. Feedback on how the join is progressing is provided to the progress monitor.

If this method is called while the job manager is suspended, only jobs that are currently running will be joined. Once there are no jobs in the family in the Job#RUNNING state, this method returns.

Note that there is a deadlock risk when using join. If the calling thread owns a lock or object monitor that the joined thread is waiting for, deadlock will occur. This method can also result in starvation of the current thread if another thread continues to add jobs of the given family, or if a job in the given family reschedules itself in an infinite loop.

Parameters:
monitor - Progress monitor for reporting progress on how the wait is progressing, or null if no progress monitoring is required.
Throws:
java.lang.InterruptedException - if this thread is interrupted while waiting
OperationCanceledException - if the progress monitor is canceled while waiting

suspendValidation

public void suspendValidation(IProject project,
                              boolean suspend)
Suspends, or undoes the suspension of, validation on the current project. If suspend is true then validation is suspended and if it's false then validation is not suspended on the project. The value of this variable is not persisted.

Be very careful when you use this method! Turn validation back on in a finally block because if the code which suspended validation crashes, the user has no way to reset the suspension. The user will have to shut down and restart the workbench to get validation to work again.

Parameters:
project - The project that is to be suspended or unsuspended.
suspend - If true, validation on the project will be suspend. If false it will not be suspended.

suspendAllValidation

public void suspendAllValidation(boolean suspend)
Suspends, or undoes the suspension of, validation on all projects in the workbench. If "suspend" is true then validation is suspended and if it's "false" then validation is not suspended. The value of this variable is not persisted.

Be very careful when you use this method! Turn validation back on in a finally block because if the code which suspended validation crashes, the user has no way to reset the suspension. The user will have to shut down and restart the workbench to get validation to work again.


isSuspended

public boolean isSuspended()
Return true if "suspend all" is enabled, false otherwise.


isSuspended

public boolean isSuspended(IProject project)
Returns true if validation will not run on the project because it's been suspended. This method checks only the suspension status; if validation cannot run for some other reason (for example, there are no enabled validators), yet the IProject is not suspended, this method will return true even though validation will not run.


isProjectSuspended

public boolean isProjectSuspended(IProject project)
This method should be called by any code that is preparing to suspend validation on a project. Rather than calling isSuspended(IProject), which will also return true if all validation has been suspended.

Parameters:
project - the project that is being tested
Returns:
boolean true if the project has been suspended

validate

public ValidationResults validate(IProject[] projects,
                                  boolean isManual,
                                  boolean isBuild,
                                  IProgressMonitor monitor)
                           throws CoreException
Validate the projects. Exactly one of isManual or isBuild needs to be true.

Parameters:
projects - The projects to be validated.
isManual - Is this being done as part of a manual validation? i.e. did the user select the Validate menu item?
isBuild - Is this being done as part of a build?
monitor -
Returns:
the validation result which is the combined result for all the resources that were validated.
Throws:
CoreException