Oracle GlassFish Server 3.0.1 Add-On Component Development Guide

Validating Configuration Data

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, GlassFish 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 GlassFish Server configuration data. For the complete list of annotations, see the javax.validation.constraints package summary.

Table 6–1 Commonly Used Annotations for Validating GlassFish Server Configuration Data



Not null 




Minimum value 


Set the value element of this annotation to the minimum allowed value.

Maximum value 


Set the value element of this annotation to the maximum allowed value.

Regular expression matching


Set the regexp element of this annotation to the regular expression that is to be matched.

Example 6–5 Specifying a Range of Valid Values for an Integer

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;
String getRotationIntervalInMinutes();

Example 6–6 Specifying Regular Expression Matching

This example specifies that the attribute classname must contain only non-whitespace characters.

import javax.validation.constraints.Pattern;
String getClassname();