Class ConfigurationValidator
java.lang.Object
de.aristaflow.adept2.base.configuration.ConfigurationValidator
- Direct Known Subclasses:
DefaultEventManager.ConfigurationValidator,EmbeddedServletService.ConfigurationValidator,PluginRegistry.ConfigurationValidator
A
ConfigurationValidator can be specified in a ConfigurationDescription and
validates a configuration beyond its property descriptions. The registry runs it right before it
creates an instance of the component, on the configuration which the instance receives, and hands
it the declaration of the instance; a configuration validated
otherwise, such as that of an event source, comes without a declaration.
Implementations must have a public default (i. e. parameterless) constructor.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ComponentInstanceDeclarationThe declaration of the component instance whose configuration is validated, as the registry has read it from its own configuration, ornullif the configuration is validated outside the creation of the instance by the registry. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidConstructs aConfigurationExceptionand throws it.protected final voidrebukeIllegalValue(Configuration configuration, String propertyName, String shortDescription) Constructs aConfigurationExceptionand throws it.protected final voidrebukeMissingValue(String propertyName) Constructs aPropertyNotSetExceptionand throws it.protected abstract voidvalidate(Configuration configuration) Validates the configuration in the givenConfigurationobject.
-
Field Details
-
declaration
The declaration of the component instance whose configuration is validated, as the registry has read it from its own configuration, ornullif the configuration is validated outside the creation of the instance by the registry.
-
-
Constructor Details
-
ConfigurationValidator
public ConfigurationValidator()
-
-
Method Details
-
validate
Validates the configuration in the givenConfigurationobject. The configuration was already validated against thepropertydescriptions of theConfigurationDescription, i.e. if the type wasProperty.Type.BOOLEANyou 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
ConfigurationExceptions) the methodrebukeIllegalValue(Configuration, String, String)should be used.- Parameters:
configuration- the configuration to be validated- Throws:
ConfigurationException- if the configuration contains errors
-
rebuke
Constructs aConfigurationExceptionand 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(Configuration configuration, String propertyName, String shortDescription) throws ConfigurationException Constructs aConfigurationExceptionand 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
Constructs aPropertyNotSetExceptionand 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
-