This example shows the interfaces that define the configuration data for the Greeter Container component. The data is comprised of the following elements:
A parent element, which is shown in Example 6–11
A subelement that is contained by the parent element, which is shown in Example 6–12
This example also shows an XML data fragment for initializing an element. See Example 6–13.
Code for the Greeter Container component is shown in Example of Adding Container Capabilities.
Code for an asadmin subcommand that updates the configuration data in this example is shown in Example 4–7.
This example shows the definition of the greeter-container-config element. The attributes of the greeter-container-config element are as follows:
number-of-instances, which must be in the range 1–10.
language, which must contain only non-whitespace characters.
style, which must contain only non-whitespace characters.
The greeter-element element is identified as a subelement of the greeter-container-config element. The definition of the greeter-element element is shown in Example 6–12.
package org.glassfish.examples.extension.greeter.config; import org.jvnet.hk2.config.Configured; import org.jvnet.hk2.config.Attribute; import org.jvnet.hk2.config.Element; import org.glassfish.api.admin.config.Container; import javax.validation.constraints.Pattern; import javax.validation.constraints.Min; import javax.validation.constraints.Max; import java.beans.PropertyVetoException; @Configured public interface GreeterContainerConfig extends Container { @Attribute @Min(value=1) @Max (value=10) public String getNumberOfInstances(); public void setNumberOfInstances(String instances) throws PropertyVetoException; @Attribute @Pattern(regexp = "^[\\S]*$") public String getLanguage(); public void setLanguage(String language) throws PropertyVetoException; @Attribute @Pattern(regexp = "^[\\S]*$") public String getStyle(); public void setStyle(String style) throws PropertyVetoException; @Element public GreeterElement getElement(); public void setElement(GreeterElement element) throws PropertyVetoException; }
This example shows the definition of the greeter-element element, which is identified as a subelement of the greeter-container-config element in Example 6–11. The only attribute of the greeter-element element is greeter-port, which must be in the range 1030–1050.
package org.glassfish.examples.extension.greeter.config; import org.jvnet.hk2.config.ConfigBeanProxy; import org.jvnet.hk2.config.Configured; import org.jvnet.hk2.config.Attribute; import javax.validation.constraints.Min; import javax.validation.constraints.Max; import java.beans.PropertyVetoException; @Configured public interface GreeterElement extends ConfigBeanProxy { @Attribute @Min(value=1030) @Max (value=1050) public String getGreeterPort(); public void setGreeterPort(String greeterport) throws PropertyVetoException; }
This example shows the XML data fragment for adding the greeter-container-config element to the domain.xml file. The greeter-container-config element contains the subelement greeter-element.
The attributes of greeter-container-config are initialized as follows:
The number-of-instances attribute is set to 5.
The language attribute is set to norsk.
The style element is set to formal.
The greeter-port attribute of the greeter-element element is set to 1040.
<greeter-container-config number-of-instances="5" language="norsk" style="formal"> <greeter-element greeter-port="1040"/> </greeter-container-config>
The definition of the greeter-container-config element is shown in Example 6–11. The definition of the greeter-element element is shown in Example 6–12.