Skip to content

Creating JAXB beans

Ondrej Zizka edited this page Jun 4, 2013 · 5 revisions

For MBeans:

@XmlRootElement(name = "mbean")
@XmlAccessorType(XmlAccessType.NONE)
public final class ServerPeerBean extends MBeanJaxbBase<ServerPeerBean> implements IConfigFragment, Origin.Wise {
    @XmlPath("attribute[@name='StrictTck']/text()") private String StrictTck; // false
    ...
}

Fast creation of attribs properties:

Perform a regex replaces:

<attribute name="(.*)">(.*)</attribute>
@XmlPath("attribute[@name='$1']/text()") private String $1; // $2

<depends optional-attribute-name="(.*)">(.*)</depends>
@XmlPath("depends[@optional-attribute-name='$1')]/text()") private String $1;

Or with get/setters:

@XmlPath("attribute[@name='$1']/text()")
public String get$1(){ return $1; }
public Bean set$1( String $1 ){ this.$1 = $1; return this; }
private String $1; // $2