Validating configuration data ensures that attribute values that are being set or updated do not violate any constraints that you impose on the data. For example, you might require that an attribute that represents a name is not null, or an integer that represents a port number is within the range of available port numbers. Any attempt to set or update an attribute value that fails validation fails. Any validations that you specify for an attribute are performed when the attribute is initialized and every time the attribute is changed.
To standardize the validation of configuration data, Enterprise Server uses JSR 303: Bean Validation for validating configuration data. JSR 303 defines a metadata model and API for the validation of JavaBeans components.
To validate an attribute of an element, annotate the attribute's getter method with the annotation in the javax.validation.constraints package that performs the validation that you require. The following table lists commonly used annotations for validating Enterprise Server configuration data. For the complete list of annotations, see the javax.validation.constraints package summary.
Table 6–1 Commonly Used Annotations for Validating Enterprise Server Configuration Data
This example specifies that the attribute rotation-interval-in-minutes must be a positive integer.
... import javax.validation.constraints.Max; import javax.validation.constraints.Min; ... @Min(value=1) @Max(value=Integer.MAX_VALUE) String getRotationIntervalInMinutes(); ...
This example specifies that the attribute classname must contain only non-whitespace characters.
import javax.validation.constraints.Pattern; ... @Pattern(regexp="^[\\S]*$") String getClassname(); ...