public final class ValidationError extends Object implements IValidationError
IValidationError
that supports message resolution from
IErrorMessageSource
, default message (if none of the keys matched), and variable
substitution.
The final error message is constructed via the following process:
addKey(String)
via the provided
IErrorMessageSource
.setMessage(String)
, if
any.Constructor and Description |
---|
ValidationError()
Constructs an empty error
|
ValidationError(IValidator<?> validator)
Constructs a validation error with the validator's standard key.
|
ValidationError(IValidator<?> validator,
String variation)
Constructs a validation error with a variation of validator's standard key.
|
ValidationError(String message)
Constructs a validation error with the specified message.
|
Modifier and Type | Method and Description |
---|---|
ValidationError |
addKey(IValidator<?> validator)
Shortcut for adding a standard message key which is the simple name of the validator' class
|
ValidationError |
addKey(IValidator<?> validator,
String variation)
Shortcut for adding a standard message key variation which is the simple name of the
validator class followed by a dot and the variation
|
ValidationError |
addKey(String key)
Adds a key to the list of keys that will be tried against
IErrorMessageSource to
locate the error message string. |
Serializable |
getErrorMessage(IErrorMessageSource messageSource)
Retrieves the error message (usually user-facing).
|
List<String> |
getKeys()
Gets error keys
|
String |
getMessage()
Gets the default message that will be used when no message could be located via message keys.
|
Map<String,Object> |
getVariables()
Retrieves the variables map for this error.
|
void |
setKeys(List<String> keys)
Sets error keys
|
ValidationError |
setMessage(String message)
Sets message that will be used when no message could be located via message keys.
|
ValidationError |
setVariable(String name,
Object value)
Sets a key and value in the variables map for use in substitution.
|
ValidationError |
setVariables(Map<String,Object> vars)
Sets the variables map for this error.
|
String |
toString() |
public ValidationError()
public ValidationError(IValidator<?> validator)
addKey(IValidator)
validator
- validatorpublic ValidationError(IValidator<?> validator, String variation)
addKey(IValidator, String)
validator
- validatorvariation
- key variationpublic ValidationError(String message)
setMessage(String)
message
- messagepublic ValidationError addKey(String key)
IErrorMessageSource
to
locate the error message string.key
- a message key to be addedValidationError
for chaining purposespublic ValidationError addKey(IValidator<?> validator)
validator
- validatorthis
public ValidationError addKey(IValidator<?> validator, String variation)
If the variation is empty only the validator's simple class name is used
validator
- validatorvariation
- key variationthis
public ValidationError setVariable(String name, Object value)
name
- a variable namevalue
- a variable valueValidationError
for chaining purposespublic final Map<String,Object> getVariables()
Map
of variables for this errorpublic final ValidationError setVariables(Map<String,Object> vars)
vars
- a variables mapValidationError
for chaining purposespublic final Serializable getErrorMessage(IErrorMessageSource messageSource)
IValidationError
getErrorMessage
in interface IValidationError
messageSource
- the message sourceIValidationError.getErrorMessage(IErrorMessageSource)
public final String getMessage()
public final ValidationError setMessage(String message)
Note: No variable substitution is performed on the given message!
message
- a default message to be used when all keys yield no messageValidationError
for chaining purposespublic String toString()
toString
in class Object
Object.toString()
Copyright © 2006–2022 Apache Software Foundation. All rights reserved.