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
To ensure that a component's configuration data is added to the domain.xml file when the component is first instantiated, you must initialize the component's configuration data.
Initializing a component's configuration data involves the following tasks:
Ensure that each XML element accurately represents the interface that is defined for the element.
Ensure that any subelements that you are initializing are correctly nested.
Set attributes of the elements to their required initial values.
Example 6-7 XML Data Fragment
This example shows the XML data fragment for adding the wombat-container-config element to the domain.xml file. The wombat-container-config element contains the subelement wombat-element. The attributes of wombat-element are initialized as follows:
The foo attribute is set to something.
The bar attribute is set to anything.
<wombat-container-config> <wombat-element foo="something" bar="anything"/> </wombat-container-config>
Add code to write the component's initial configuration data in the class that represents your add-on component. If your add-on component is a container, add this code to the sniffer class. For more information about adding a container, see Chapter 7, Adding Container Capabilities.
If the element is not present in the domain.xml file when the add-on component is initialized, the instance variable remains null.
If your add-on component is a container, invoke this method within the implementation of the setup method the sniffer class. When the container is first instantiated, GlassFish Server invokes the setup method.
The test that the instance is null is required to ensure that the configuration data is added only if the data is not already present in the domain.xml file.
In the invocation of the parseContainerConfig method, pass the following items as parameters:
The Habitat object on which you set a dependency
The URL to the file that contains the XML fragment that represents the configuration data
Example 6-8 Writing a Component's Initial Configuration Data to the domain.xml File
This example writes the XML fragment in the file init.xml to the domain.xml file. The fragment is written only if the domain.xml file does not contain the wombat-container-config-element.
The wombat-container-config element is represented by the WombatContainerConfig interface. An optional dependency is set on an instance of a class that implements WombatContainerConfig.
... import org.glassfish.api.admin.config.ConfigParser; import org.glassfish.examples.extension.config.WombatContainerConfig; ... import org.jvnet.hk2.annotations.Inject; import org.jvnet.hk2.component.Habitat; import com.sun.enterprise.module.Module; import java.util.logging.Logger; ... import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.reflect.Array; import java.net.URL; ... @Inject(optional=true) WombatContainerConfig config=null; ... @Inject ConfigParser configParser; @Inject Habitat habitat; public Module[] setup(String containerHome, Logger logger) throws IOException { if (config==null) { URL url = this.getClass().getClassLoader().getResource("init.xml"); if (url!=null) { configParser.parseContainerConfig(habitat, url, WombatContainerConfig.class); } } return null; } ...
Example 6-9 domain.xml File After Initialization
This example shows the domain.xml file after the setup method was invoked to add the wombat-container-config element under the config element.
<domain...> ... <configs> <config name="server-config"> <wombat-container-config number-of-instances="5"> <wombat-element foo="something" bar="anything" /> </wombat-container-config> <http-service> ... </domain>