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.
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.
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.
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.
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:
A change from lowercase to uppercase in the interface name is transformed to the hyphen (-) separator character.
The element name is all lowercase.
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.
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.
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:
If the attribute is required, an error occurs.
If the attribute is optional, the element is written successfully to the domain configuration file.
To specify whether an attribute is required or optional, set the required element of the @Attribute annotation as follows:
If the attribute is required, set the required element to true.
If the attribute is optional, set the required element to false. This value is the default.
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; ...