Sun GlassFish Enterprise Server v3 Add-On Component Development Guide

Defining an Attribute of an Element

The attributes of an element describe the characteristics of the element. For example, the port attribute of the network-listener element identifies the port number on which the listener listens. For a description of all the attributes of the network-listener element, see network-listener in Sun GlassFish Enterprise Server v3 Domain File Format Reference.

Representing an Attribute of an Element

Represent each attribute of an element as the property of a pair of JavaBeansTM specification getter and setter methods of the interface that defines the element. The component for which the configuration data is being defined can then access the attribute through the getter method. The setter method enables the attribute to be updated.

Specifying the Data Type of an Attribute

The data type of an attribute is the return type of the getter method that is associated with the attribute. To enable the attribute take properties in the form ${property-name} as values, specify the data type as String.

Identifying an Attribute of an Element

To identify an attribute of an element, annotate the declaration of the getter method that is associated with the attribute with the org.jvnet.hk2.config.Attribute annotation.

To specify the properties of the attribute, use the elements of the @Attribute annotation as explained in the sections that follow.

Specifying the Name of an Attribute

To specify the name of an attribute, set the value element of the @Attribute annotation to a string that specifies the name. If you do not set this element, the name is derived from the name of the property as follows:

For example, if the getter method getNumberOfInstances is defined for the property NumberOfInstances to represent an attribute, the name of the attribute is number-of-instances.

Specifying the Default Value of an Attribute

The default value of an attribute is the value that is applied if the attribute is omitted when the element is written to the domain configuration file.

To specify the default value of an attribute, set the defaultValue element of the @Attribute annotation to a string that contains the default value. If you do not set this element, the parameter has no default value.

Specifying Whether an Attribute Is Required or Optional

Whether an attribute is required or optional determines how Enterprise Server responds if the parameter is omitted when the element is written to the domain configuration file:

To specify whether an attribute is required or optional, set the required element of the @Attribute annotation as follows:

Example of Defining an Attribute of an Element


Example 6–2 Defining an Attribute of an Element

This example defines the attribute number-of-instances. To enable the attribute take properties in the form ${property-name} as values, the data type of this attribute is String.

import org.jvnet.hk2.config.Attribute;
...
    @Attribute
    public String getNumberOfInstances();
    public void setNumberOfInstances(String instances) throws PropertyVetoException;
...