|
Lines 15-20
Link Here
|
| 15 |
import java.util.List; |
15 |
import java.util.List; |
| 16 |
|
16 |
|
| 17 |
import org.eclipse.core.resources.IProject; |
17 |
import org.eclipse.core.resources.IProject; |
|
|
18 |
import org.eclipse.core.runtime.IStatus; |
| 19 |
import org.eclipse.core.runtime.jobs.ISchedulingRule; |
| 18 |
import org.eclipse.wst.validation.internal.ConfigurationManager; |
20 |
import org.eclipse.wst.validation.internal.ConfigurationManager; |
| 19 |
import org.eclipse.wst.validation.internal.ProjectConfiguration; |
21 |
import org.eclipse.wst.validation.internal.ProjectConfiguration; |
| 20 |
import org.eclipse.wst.validation.internal.ResourceConstants; |
22 |
import org.eclipse.wst.validation.internal.ResourceConstants; |
|
Lines 28-33
Link Here
|
| 28 |
import org.eclipse.wst.validation.internal.provisional.core.IReporter; |
30 |
import org.eclipse.wst.validation.internal.provisional.core.IReporter; |
| 29 |
import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; |
31 |
import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; |
| 30 |
import org.eclipse.wst.validation.internal.provisional.core.IValidator; |
32 |
import org.eclipse.wst.validation.internal.provisional.core.IValidator; |
|
|
33 |
import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob; |
| 31 |
|
34 |
|
| 32 |
/** |
35 |
/** |
| 33 |
* This class is to be used as a base class by clients who want to provide |
36 |
* This class is to be used as a base class by clients who want to provide |
|
Lines 75-130
Link Here
|
| 75 |
*/ |
78 |
*/ |
| 76 |
public void validate(IValidationContext helper, IReporter reporter) throws ValidationException |
79 |
public void validate(IValidationContext helper, IReporter reporter) throws ValidationException |
| 77 |
{ |
80 |
{ |
| 78 |
ValidatorMetaData vmd = ValidationRegistryReader.getReader().getValidatorMetaData(this); |
81 |
// Apparently this method will not be called on an IValidatorJob. |
| 79 |
String validatorName = vmd.getValidatorDisplayName(); |
|
|
| 80 |
|
| 81 |
// We need to ensure that the context is an IProjectValidationContext. The |
| 82 |
// limitation of using an IValidationContext is that it does not readily |
| 83 |
// provide the project the validator is being invoked upon. |
| 84 |
|
| 85 |
if (!(helper instanceof IProjectValidationContext)) |
| 86 |
{ |
| 87 |
throw new ValidationException(new LocalizedMessage(IMessage.HIGH_SEVERITY, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_WRONG_CONTEXT_FOR_DELEGATE, new String[] { validatorName }))); |
| 88 |
} |
| 89 |
|
| 90 |
IProjectValidationContext projectContext = (IProjectValidationContext) helper; |
| 91 |
IProject project = projectContext.getProject(); |
| 92 |
|
| 93 |
ValidatorDelegateDescriptor delegateDescriptor = null; |
| 94 |
|
| 95 |
try |
| 96 |
{ |
| 97 |
ProjectConfiguration projectConfig = ConfigurationManager.getManager().getProjectConfiguration(project); |
| 98 |
|
| 99 |
delegateDescriptor = projectConfig.getDelegateDescriptor(vmd); |
| 100 |
} |
| 101 |
catch (InvocationTargetException e) |
| 102 |
{ |
| 103 |
// Already dealt with by the framework. |
| 104 |
} |
| 105 |
finally |
| 106 |
{ |
| 107 |
if (delegateDescriptor == null) |
| 108 |
{ |
| 109 |
throw new ValidationException(new LocalizedMessage(IMessage.HIGH_SEVERITY, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_NO_DELEGATE, new String[] { vmd.getValidatorDisplayName() }))); |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
IValidator delegate = delegateDescriptor.getValidator(); |
| 114 |
|
| 115 |
// We need to make it look like this validator is the one generating |
| 116 |
// messages so we wrap the reporter and use this validator as the source. |
| 117 |
// The validation framework does not recognize our validators because they |
| 118 |
// are not registered directly with the framework. |
| 119 |
// We could make them work like the aggregated validators but that would |
| 120 |
// create problems with markers not being cleaned up if someone switches |
| 121 |
// validators. |
| 122 |
// TODO : Maybe we could clear all the markers generated by a delegate when |
| 123 |
// the user chooses a different delegate implementation? |
| 124 |
|
| 125 |
DelegatingReporter delegatingReporter = new DelegatingReporter(this, reporter); |
| 126 |
|
| 127 |
delegate.validate(helper, delegatingReporter); |
| 128 |
} |
82 |
} |
| 129 |
|
83 |
|
| 130 |
/** |
84 |
/** |
|
Lines 234-237
Link Here
|
| 234 |
delegatingReporter.removeMessageSubset(delegatingValidator, obj, groupName); |
188 |
delegatingReporter.removeMessageSubset(delegatingValidator, obj, groupName); |
| 235 |
} |
189 |
} |
| 236 |
} |
190 |
} |
|
|
191 |
|
| 192 |
/* |
| 193 |
* (non-Javadoc) |
| 194 |
* |
| 195 |
* @see org.eclipse.wst.validation.internal.provisional.core.IValidatorJob#validateInJob(org.eclipse.wst.validation.internal.provisional.core.IValidationContext, |
| 196 |
* org.eclipse.wst.validation.internal.provisional.core.IReporter) |
| 197 |
*/ |
| 198 |
public IStatus validateInJob(IValidationContext helper, IReporter reporter) throws ValidationException |
| 199 |
{ |
| 200 |
ValidatorMetaData vmd = ValidationRegistryReader.getReader().getValidatorMetaData(this); |
| 201 |
String validatorName = vmd.getValidatorDisplayName(); |
| 202 |
|
| 203 |
// We need to ensure that the context is an IProjectValidationContext. The |
| 204 |
// limitation of using an IValidationContext is that it does not readily |
| 205 |
// provide the project the validator is being invoked upon. |
| 206 |
|
| 207 |
if (!(helper instanceof IProjectValidationContext)) |
| 208 |
{ |
| 209 |
throw new ValidationException(new LocalizedMessage(IMessage.HIGH_SEVERITY, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_WRONG_CONTEXT_FOR_DELEGATE, new String[] { validatorName }))); |
| 210 |
} |
| 211 |
|
| 212 |
IProjectValidationContext projectContext = (IProjectValidationContext) helper; |
| 213 |
IProject project = projectContext.getProject(); |
| 214 |
|
| 215 |
ValidatorDelegateDescriptor delegateDescriptor = null; |
| 216 |
|
| 217 |
try |
| 218 |
{ |
| 219 |
ProjectConfiguration projectConfig = ConfigurationManager.getManager().getProjectConfiguration(project); |
| 220 |
|
| 221 |
delegateDescriptor = projectConfig.getDelegateDescriptor(vmd); |
| 222 |
} |
| 223 |
catch (InvocationTargetException e) |
| 224 |
{ |
| 225 |
// Already dealt with by the framework. |
| 226 |
} |
| 227 |
finally |
| 228 |
{ |
| 229 |
if (delegateDescriptor == null) |
| 230 |
{ |
| 231 |
throw new ValidationException(new LocalizedMessage(IMessage.HIGH_SEVERITY, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_NO_DELEGATE, new String[] { vmd.getValidatorDisplayName() }))); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
IValidatorJob delegate = (IValidatorJob)delegateDescriptor.getValidator(); |
| 236 |
|
| 237 |
// We need to make it look like this validator is the one generating |
| 238 |
// messages so we wrap the reporter and use this validator as the source. |
| 239 |
// The validation framework does not recognize our validators because they |
| 240 |
// are not registered directly with the framework. |
| 241 |
// We could make them work like the aggregated validators but that would |
| 242 |
// create problems with markers not being cleaned up if someone switches |
| 243 |
// validators. |
| 244 |
// TODO : Maybe we could clear all the markers generated by a delegate when |
| 245 |
// the user chooses a different delegate implementation? |
| 246 |
|
| 247 |
DelegatingReporter delegatingReporter = new DelegatingReporter(this, reporter); |
| 248 |
|
| 249 |
IStatus status = delegate.validateInJob(helper, delegatingReporter); |
| 250 |
|
| 251 |
return status; |
| 252 |
} |
| 253 |
|
| 254 |
/* |
| 255 |
* (non-Javadoc) |
| 256 |
* |
| 257 |
* @see org.eclipse.wst.validation.internal.provisional.core.IValidatorJob#getSchedulingRule(org.eclipse.wst.validation.internal.provisional.core.IValidationContext) |
| 258 |
*/ |
| 259 |
public ISchedulingRule getSchedulingRule(IValidationContext helper) |
| 260 |
{ |
| 261 |
return null; |
| 262 |
} |
| 237 |
} |
263 |
} |