users@jaxb.java.net

Re: JAXB Annotations Question

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Tue, 15 Jun 2010 22:39:22 +0200

Hi,

> If the release is not for some time, would you be able to give an example of nested annotations?
> I appreciate it.

Here's two example for you.
Nested annotations in bindings.xjb (you can't use "arbitrary"
customizations elements here):

                <jaxb:bindings
node="xs:complexType[@name='aType']/xs:sequence/xs:element[@name='b2']">
                        <hj:ignored/>
                        <annox:annotate>
                                <annox:annotate annox:class="javax.persistence.Embedded"/>
                        </annox:annotate>
                        <annox:annotate>
                                <annox:annotate annox:class="javax.persistence.AttributeOverrides">
                                        <annox:annotate annox:field="value">
                                                <annox:annotate
annox:class="javax.persistence.AttributeOverride" name="c">
                                                        <annox:annotate annox:field="column">
                                                                <annox:annotate annox:class="javax.persistence.Column"
name="B_TWO_C" length="998"/>
                                                        </annox:annotate>
                                                </annox:annotate>
                                                <annox:annotate
annox:class="javax.persistence.AttributeOverride" name="d">
                                                        <annox:annotate annox:field="column">
                                                                <annox:annotate annox:class="javax.persistence.Column"
name="B_TWO_D" precision="19" scale="9"/>
                                                        </annox:annotate>
                                                </annox:annotate>
                                        </annox:annotate>
                                </annox:annotate>
                        </annox:annotate>
                </jaxb:bindings>


...And schema.xsd (you can use arbitrary elements here):


                        <xs:element name="b3" type="bType" minOccurs="0">
                                <xs:annotation>
                                        <xs:appinfo xmlns:jp="http://annox.dev.java.net/javax.persistence">
                                                <hj:ignored/>
                                                <annox:annotate>
                                                        <jp:Embedded/>
                                                </annox:annotate>
                                                <annox:annotate>
                                                        <jp:AttributeOverrides>
                                                                <value>
                                                                        <jp:AttributeOverride name="c">
                                                                                <column>
                                                                                        <jp:Column name="B_THREE_C" length="997"/>
                                                                                </column>
                                                                        </jp:AttributeOverride>
                                                                        <jp:AttributeOverride name="d">
                                                                                <column>
                                                                                        <jp:Column name="B_THREE_D" precision="18" scale="8"/>
                                                                                </column>
                                                                        </jp:AttributeOverride>
                                                                </value>
                                                        </jp:AttributeOverrides>
                                                </annox:annotate>
                                        </xs:appinfo>
                                </xs:annotation>
                        </xs:element>

I've attached the files, you'll also find the in the
ejb/tests/embeddable test project:

https://hj3.dev.java.net/svn/hj3/trunk/ejb/tests/embeddable/

Bye.
/lexi