Package org.apache.sling.validation.spi.support

# Class DefaultValidationFailure

java.lang.Object
org.apache.sling.validation.spi.support.DefaultValidationFailure

All Implemented Interfaces:
  `Serializable`, `ValidationFailure`

@ProviderType public final class DefaultValidationFailure extends Object implements ValidationFailure, Serializable
Wraps a message key (being looked up in a `ResourceBundle`), messageArguments (being used with `MessageFormat.format(String, Object...)` and the location where the validation failure occurred.

See Also:
  - Serialized Form

## Constructor Summary

Constructors
Constructor
Description
`DefaultValidationFailure(@NotNull String location, int severity, @NotNull ResourceBundle defaultResourceBundle, @NotNull String messageKey, Object... messageArguments)`
Constructor of a validation failure.
`DefaultValidationFailure(@NotNull ValidatorContext validationContext, @NotNull String messageKey, Object... messageArguments)`
Constructor of a validation failure.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`equals(Object obj)`
`@NotNull String`
`getLocation()`
Returns the relative location of the property/resource/value which triggered this validation failure.
`@NotNull String`
`getMessage(ResourceBundle resourceBundle)`
`int`
`getSeverity()`
`int`
`hashCode()`
`String`
`toString()`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Constructor Details

### DefaultValidationFailure

public DefaultValidationFailure(@NotNull @NotNull ValidatorContext validationContext, @NotNull @NotNull String messageKey, Object... messageArguments)
Constructor of a validation failure.

Parameters:
  `validationContext` - the context from which to extract location, severity and default resource bundle
  `messageKey` - the key to look up in the resource bundle
  `messageArguments` - the arguments to be used with the looked up value from the resource bundle (given in `getMessage(ResourceBundle)`

### DefaultValidationFailure

public DefaultValidationFailure(@NotNull @NotNull String location, int severity, @NotNull @NotNull ResourceBundle defaultResourceBundle, @NotNull @NotNull String messageKey, Object... messageArguments)
Constructor of a validation failure.

Parameters:
  `location` - the location where the validation error occurred
  `severity` - the severity of this failure (may be `null` which leads to using the validator's default severity)
  `defaultResourceBundle` - the default resourceBundle which is used to resolve the `messageKey` in `getMessage(ResourceBundle)` if `null` is provided as parameter.
  `messageKey` - the key to look up in the resource bundle
  `messageArguments` - the arguments to be used with the looked up value from the resource bundle (given in `getMessage(ResourceBundle)`

## Method Details

### getMessage

@NotNull public @NotNull String getMessage(ResourceBundle resourceBundle)

Specified by:
  `getMessage` in interface `ValidationFailure`
Parameters:
  `resourceBundle` - ResourceBundle in which to look up the according message (used for i18n), if `null` is given, the default resource bundle is used.
Returns:
  the failure message

### getLocation

@NotNull public @NotNull String getLocation()
Description copied from interface: `ValidationFailure`
Returns the relative location of the property/resource/value which triggered this validation failure. The location

- is relative to the resource given in the first parameter in case it was returned by `ValidationService.validate(org.apache.sling.api.resource.Resource, org.apache.sling.validation.model.ValidationModel)` or `ValidationService.validateResourceRecursively(org.apache.sling.api.resource.Resource, boolean, java.util.function.Predicate, boolean)` or
- contains just the value name in case it was returned by `ValidationService.validate(org.apache.sling.api.resource.ValueMap, org.apache.sling.validation.model.ValidationModel)`

Specified by:
  `getLocation` in interface `ValidationFailure`
Returns:
  the location (usually the validated resource's property path).

### getSeverity

public int getSeverity()

Specified by:
  `getSeverity` in interface `ValidationFailure`
Returns:
  the severity of this validation failure. If no explicit severity was set either in the validation model or in the validator, this returns `0`.

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`

### equals

public boolean equals(Object obj)

Overrides:
  `equals` in class `Object`