users@jaxb.java.net

ToString plugin

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Thu, 14 Sep 2006 15:32:48 +0200

Hi.

I've written a toString plugin for JAXB 2.x.

For the XML:

<heteroSequence>
        <sa>a</sa>
        <sb>b</sb>
        <sc>c</sc>
        <sd>d</sd>
        <se>e</se>
        <sf>
                <a>0</a>
                <b>1</b>
        </sf>
</heteroSequence>

And schema:

        <xs:element name="heteroSequence" type="heteroSequenceType"/>
        <xs:complexType name="heteroSequenceType">
                <xs:sequence>
                        <xs:element name="sa" type="xs:string"/>
                        <xs:element name="sb" type="xs:string"/>
                        <xs:sequence>
                                <xs:element name="sc" type="xs:string"/>
                                <xs:element name="sd" type="xs:string"/>
                        </xs:sequence>
                        <xs:sequence maxOccurs="unbounded">
                                <xs:element name="se" type="xs:string"/>
                                <xs:element name="sf" type="sequenceType"/>
                        </xs:sequence>
                </xs:sequence>
        </xs:complexType>
        <xs:complexType name="sequenceType">
                <xs:sequence>
                        <xs:element name="a" type="xs:string"/>
                        <xs:element name="b" type="xs:long"/>
                </xs:sequence>
        </xs:complexType>

toString generates the following:

heteroSequence(HeteroSequenceType {
        sa:a
        sb:b
        sc:c
        sd:d
        seAndSf:[e,
                SequenceType {
                        a:0
                        b:1
                }]
})

The plugin is the paret of hyperjaxb3-tools module.

To build and test, check out hyperjaxb3 and mvn clean install it.
After that go to tests/one and mvn test it there.

Build-time dependencies are hyperjaxb3-tools and hyperjaxb3-runtime.
Run-time dependency is hyperjaxb3-runtime only.

This is not yet thoroughly tested. I just wanted to practise a bit with JAXB 2
APIs before I start implementing hashCode/equals plugins.

Bye.
/lexi