Skip Navigation Links | |
Exit Print View | |
Oracle GlassFish Server 3.1 Add-On Component Development Guide |
1. Introduction to the Development Environment for GlassFish Server Add-On Components
3. Extending the Administration Console
4. Extending the asadmin Utility
5. Adding Monitoring Capabilities
6. Adding Configuration Data for a Component
How GlassFish Server Stores Configuration Data
Defining an Attribute of an Element
Representing an Attribute of an Element
Specifying the Data Type of an Attribute
Identifying an Attribute of an Element
Specifying the Name of an Attribute
Specifying the Default Value of an Attribute
Specifying Whether an Attribute Is Required or Optional
Example of Defining an Attribute of an Element
Initializing a Component's Configuration Data
To Define a Component's Initial Configuration Data
To Write a Component's Initial Configuration Data to the domain.xml File
Creating a Transaction to Update Configuration Data
To Create a Transaction to Update Configuration Data
Dotted Names and REST URLs of Configuration Attributes
Examples of Adding Configuration Data for a Component
7. Adding Container Capabilities
8. Creating a Session Persistence Module
9. Packaging, Integrating, and Delivering an Add-On Component
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
|
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; ... @Min(value=1) @Max(value=Integer.MAX_VALUE) 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; ... @Pattern(regexp="^[\\S]*$") String getClassname(); ...