Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 



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 addValidationBuilder (IProject project)
          Add the validation builder to the project, so that the project can support build time validation.
 void applyChanges ( MutableProjectSettings settings, boolean persist)
          Apply the changes that have been been to the validation settings.
 void applyChanges ( MutableWorkspaceSettings settings, boolean persist)
          Apply the changes that have been been to the validation settings.
 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 persisted global validation settings.
  MutableProjectSettings getProjectSettings (IProject project)
          Answer the validation settings that have been defined on the project.
  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[] getValidators ()
          Answer copies of all the registered validators.
  Validator[] getValidatorsConfiguredForProject (IProject project)
          Validators can use project level settings (Project natures and facets) to determine if they are applicable to the project or not.
  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.
  MutableWorkspaceSettings getWorkspaceSettings ()
          Answer the validation settings that have been defined at the workspace level.
 boolean hasValidators (IResource resource, boolean isManual, boolean isBuild)
          Answer true if the resource has any enabled validators.
 boolean isLoaded ( Validator validator)
          Answer whether or not the validator has been activated, i.e. has the bundle that defines the validator been loaded.
 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 saveValidators ( Validator[] validators)
          Save the validators settings into the persistent store, there by making their settings the active settings.
 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 (IFile file, IProgressMonitor monitor)
          Validate a specific file resource.
  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.


addValidationBuilder

public void addValidationBuilder(IProject project)
Add the validation builder to the project, so that the project can support build time validation. It is safe to call this method, if the builder was previously added to the project. It will not be added more than once.

Parameters:
project - The project that the builder is added to.

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 persisted 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

getValidators

public 
Validator[] getValidators()
Answer copies of all the registered validators.

Returns:
Answer an empty array if there are no validators.

getProjectSettings

public 
MutableProjectSettings getProjectSettings(IProject project)
Answer the validation settings that have been defined on the project. To "activate" any changes to these settings, the applyChanges(MutableProjectSettings, boolean) method needs to be called.

Parameters:
project - The project who's settings you wish to examine or change.
Returns:
Validation settings that apply to the given project.

getWorkspaceSettings

public 
MutableWorkspaceSettings getWorkspaceSettings()
                                              throws java.lang.reflect.InvocationTargetException
Answer the validation settings that have been defined at the workspace level. To "activate" any changes to these settings, the applyChanges(MutableWorkspaceSettings, boolean) method needs to be called.

Returns:
Validation settings that apply to the entire workspace.
Throws:
java.lang.reflect.InvocationTargetException

applyChanges

public void applyChanges(
MutableProjectSettings settings,
                         boolean persist)
Apply the changes that have been been to the validation settings.

Parameters:
settings - The project settings.
persist - If true then the changes are persisted to the property files. If false the changes are applied to the validators, but are not persisted.

applyChanges

public void applyChanges(
MutableWorkspaceSettings settings,
                         boolean persist)
Apply the changes that have been been to the validation settings.

Parameters:
settings - The workspace settings.
persist - If true then the changes are persisted to the property files. If false the changes are applied to the validators, but are not persisted.

getValidatorsConfiguredForProject

public 
Validator[] getValidatorsConfiguredForProject(IProject project)
                                              throws org.eclipse.wst.validation.internal.ProjectUnavailableError
Validators can use project level settings (Project natures and facets) to determine if they are applicable to the project or not.

Parameters:
project - The project that the configuration is based on.
Returns:
The copies of the validators that are configured to run on this project based on the project level settings.
Throws:
org.eclipse.wst.validation.internal.ProjectUnavailableError

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.

isLoaded

public boolean isLoaded(
Validator validator)
Answer whether or not the validator has been activated, i.e. has the bundle that defines the validator been loaded. We do not want to cause unnecessary bundle loading, so this check can be performed by third party callers, to prevent making other calls that will force the validator to be loaded.

Parameters:
validator - The validator that is being tested.
Returns:
true if the validator has already been loaded.

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.

saveValidators

public void saveValidators(
Validator[] validators)
                    throws java.lang.reflect.InvocationTargetException
Save the validators settings into the persistent store, there by making their settings the active settings.

A common use of this method would be to change whether particular validators are enabled or not. For example if you only wanted the JSP validator enabled, you could use code similar to this:

 ValidationFramework vf = ValidationFramework.getDefault();
 Validator[] vals = vf.getValidators();
 for (Validator v : vals){
   boolean enabled = false;
   if (v.getValidatorClassname().equals("org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator"))enabled = true;
     v.setBuildValidation(enabled);
     v.setManualValidation(enabled);
  }
 vf.saveValidators(vals);
 

Parameters:
validators - The validators that you are saving.
Throws:
java.lang.reflect.InvocationTargetException

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

validate

public 
ValidationResults validate(IFile file,
                                  IProgressMonitor monitor)
                           throws CoreException
Validate a specific file resource.

Parameters:
file - The file to be validated.
monitor - Progress monitor.
Returns:
the result of validating the file.
Throws:
CoreException



 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire