How can I initialize XMBean attributes?
XMBean declared attributes can be initialized using the "value" descriptor.
For example:
<attribute access="read-write" getMethod="getSomeString" setMethod="setSomeString"> <name>SomeString</name> <type>java.lang.String</type> <descriptors> <default value="Initial value"></default> </descriptors> </attribute>
The XMBean machinery after instantiating the POJO wrapped by the XMBean
will set any initial values specified in the XMBean descriptor. So, in
the above example setSomeString("Initial value") will be called
on the POJO.
The above syntax is defined in jboss_xmbean_1_0.dtd and jboss_xmbean_1_1.dtd,
but is somewhat restricted, compared to the syntax supported by the
standard service mbean descriptor.
jboss_xmbean_1_2.dtd introduced in the 4.0 series defines an additional
and more flexible syntax for setting attribute "value" and "default" XMBean
descriptors that resembles the way attributes can be set in the "standard"
service mbean descriptor. The new syntax is supported as of JBoss v3.2.6/4.0.1
(Note, in jboss 3.2.6+ you cannot specify the jboss_xmbean_1_2.dtd
to make use of the new syntax. However, the functionality is internally
available using the 1_0 and 1_1 dtds.)
The new syntax allows the specification of complex org.w3c.dom.Element
types, substitution of environment variables and control of the trimming
behaviour. To activate the new syntax the "value" attribute must be absent
from the "value" descriptor. Otherwise the old syntax is used, thus retaining
backwards compatibility.
Example "value" descriptors:
<value> String with whitespace removed </value> ... <value trim="false"> String with whitespace retained </value> ... <value>${jboss.server.data.dir}</value> <!-- substituted value --> ... <value replace="false"> <!-- don't substitute ${x} --> <some-element> <!-- embedded arbitrary XML element --> <nested-element> ${jboss.server.data.dir} will NOT be substituted </nested-element> </some-element> </value>
"trim" and "replace" are by default set to "true". The exact same syntax
is supported for the "default" descriptor, too.
Referenced by:
Comments