Class ConfigurationValidator
- java.lang.Object
-
- de.aristaflow.adept2.base.configuration.ConfigurationValidator
-
- Direct Known Subclasses:
EmbeddedServletService.ConfigurationValidator
,PluginRegistry.ConfigurationValidator
public abstract class ConfigurationValidator extends Object
AConfigurationValidator
can be specified in aConfigurationDescription
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.- Author:
- Patrick Schmidt
-
-
Constructor Summary
Constructors Constructor Description ConfigurationValidator()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
rebuke(String description)
Constructs aConfigurationException
and throws it.protected void
rebukeIllegalValue(org.apache.commons.configuration2.Configuration configuration, String propertyName, String shortDescription)
Constructs aConfigurationException
and throws it.protected void
rebukeMissingValue(String propertyName)
Constructs aPropertyNotSetException
and throws it.protected abstract void
validate(org.apache.commons.configuration2.Configuration configuration)
Validates the configuration in the givenConfiguration
object.
-
-
-
Method Detail
-
validate
protected abstract void validate(org.apache.commons.configuration2.Configuration configuration) throws ConfigurationException
Validates the configuration in the givenConfiguration
object. The configuration was already validated against theproperty
descriptions of theConfigurationDescription
, i.e. if the type wasProperty.Type.BOOLEAN
you can expect the value to be a valid string representation of a boolean (valid in the sense ofProperty.Type.BOOLEAN
).To report errors (i.e. throw
ConfigurationException
s) the methodrebukeIllegalValue(Configuration, String, String)
should be used.- Parameters:
configuration
- the configuration to be validated- Throws:
ConfigurationException
- if the configuration contains errors
-
rebuke
protected final void rebuke(String description) throws ConfigurationException
Constructs aConfigurationException
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.- Parameters:
description
- the description of the problem (full sentence(s) preferred)- Throws:
ConfigurationException
- the constructed exception
-
rebukeIllegalValue
protected final void rebukeIllegalValue(org.apache.commons.configuration2.Configuration configuration, String propertyName, String shortDescription) throws ConfigurationException
Constructs aConfigurationException
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".
- Parameters:
configuration
- the instance configuration provided invalidate(Configuration)
propertyName
- the name of the property containing the illegal valueshortDescription
- the short error description- Throws:
ConfigurationException
- the constructed exception
-
rebukeMissingValue
protected final void rebukeMissingValue(String propertyName) throws PropertyNotSetException
Constructs aPropertyNotSetException
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.- Parameters:
propertyName
- the property name of the missing value- Throws:
PropertyNotSetException
- the constructed exception
-
-