public abstract class ConfigurationValidator
extends java.lang.Object
ConfigurationValidator can be specified in a
ConfigurationDescription and (if specified) is used to validate a
configuration at application startup without having to wait until the
component (for which the configuration was intended) is instantiated. This
can be important since components are usually instantiated on-demand.
Implementations must have a public default (i.e. parameterless)
constructor.| Constructor and Description |
|---|
ConfigurationValidator() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
rebuke(java.lang.String description)
Constructs a
ConfigurationException and throws it. |
protected void |
rebukeIllegalValue(Configuration configuration,
java.lang.String propertyName,
java.lang.String shortDescription)
Constructs a
ConfigurationException and throws it. |
protected void |
rebukeMissingValue(java.lang.String propertyName)
Constructs a
PropertyNotSetException and throws it. |
protected abstract void |
validate(Configuration configuration)
Validates the configuration in the given
Configuration object. |
protected abstract void validate(Configuration configuration) throws ConfigurationException
Configuration object. The
configuration was already validated against the property
descriptions of the ConfigurationDescription, i.e. if the type was
Property.Type.BOOLEAN you can expect the value to be a valid string
representation of a boolean (valid in the sense of
Property.Type.BOOLEAN).
To report errors (i.e. throw ConfigurationExceptions) the method
rebukeIllegalValue(Configuration, String, String) should be used.
configuration - the configuration to be validatedConfigurationException - if the configuration contains errorsprotected final void rebuke(java.lang.String description)
throws ConfigurationException
ConfigurationException and throws it. This is a
convenience method that only requires implementors to specify a problem
description. This information (plus some other data) is then formed into a
meaningful error message. This is a generic version of the rebuke-methods
in case the problem isn't related to a single property.description - the description of the problem (full sentence(s)
preferred)ConfigurationException - the constructed exceptionprotected final void rebukeIllegalValue(Configuration configuration, java.lang.String propertyName, java.lang.String shortDescription) throws ConfigurationException
ConfigurationException and throws it. This is a
convenience method that only requires implementors to specify the
configuration, a property name and a very short description of the error.
This information (plus some other data) is then formed into a meaningful
error message.
The short error description should be something like "value of type boolean expected" or "value must be positive".
configuration - the instance configuration provided in
validate(Configuration)propertyName - the name of the property containing the illegal valueshortDescription - the short error descriptionConfigurationException - the constructed exceptionprotected final void rebukeMissingValue(java.lang.String propertyName)
throws PropertyNotSetException
PropertyNotSetException and throws it. This is a
convenience method that only requires implementors to specify the
configuration and a property name. This information (plus some other data)
is then formed into a meaningful error message.propertyName - the property name of the missing valuePropertyNotSetException - the constructed exception