@ConsumerType
public interface Validator<T>
Validator
is responsible for validating a single piece of information according to an internal constraint.Modifier and Type | Field and Description |
---|---|
static String |
PROPERTY_VALIDATOR_ID
|
static String |
PROPERTY_VALIDATOR_SEVERITY
|
Modifier and Type | Method and Description |
---|---|
ValidationResult |
validate(T data,
ValidatorContext context,
ValueMap arguments)
Validates the
data and/or the valueMap according to the internal constraints of this validator. |
static final String PROPERTY_VALIDATOR_ID
Validator
must have a service property with name validator.id
of type String
. The validators are only addressable via the value of this property
from the validation models. If there are multiple validators registered for the same validator.id
, the one with highest service ranking is used.
It is recommended to prefix the value of the validator with the providing bundle symbolic name to prevent any name clashes.static final String PROPERTY_VALIDATOR_SEVERITY
Validator
may have a service property with name validator.severity
of type Integer
. This is taken as the severity of all
ValidationFailure
s constructed by this Validator
in case the model has not overwritten the severity.
If this property is not set the default severity is being used.@Nonnull ValidationResult validate(@Nonnull T data, @Nonnull ValidatorContext context, @Nonnull ValueMap arguments) throws SlingValidationException
data
and/or the valueMap
according to the internal constraints of this validator.
The validator can enforce the type of the given data just by setting the appropriate parameter type T
which can be any non-primitive class.
Depending on whether this type is an array or not the validate
method is called differently:
T is array type | Valuemap contains array value | validate is called... |
---|---|---|
yes | yes | once per property with data containing the full array |
yes | no | once per property with data containing a single element array |
no | yes | once per element in the property array with data containing one array element |
no | no | once per property with data containing the value of the property |
T
the validator is not called, but validation fails.data
- the data to validate (primary property), never null
.context
- the validation context contains additional information about the data to be validated, never null
.arguments
- the parameterization of the validator. Never null
but might be the empty map.SlingValidationException
- if some expected arguments are missing from the arguments mapCopyright © 2017 The Apache Software Foundation. All rights reserved.