简体   繁体   中英

inline binding specification in jaxb

What is the inline option for something like this

xjc -d . -b bindings.xjb Derived.xsd

where my bindings.xsd will have

 <bindings scd="~tns:NameType">
      <class ref="com.bcbsmt.eie.pojo.commontypes.NameType"/>
 </bindings>

All i want to do is to prevent duplication of NameType everywhere.The requirement though is strictly internal binding.

I tried in Derived.xsd something like

<xs:element name="Name">
                <xs:annotation>
                    <xs:appinfo>
                        <jaxb:class implClass="com.bcbsmt.eie.pojo.commontypes.NameType"></jaxb:class>
                    </xs:appinfo>
                </xs:annotation>
            </xs:element>

But this didnt work out.Any ideas

I'm not sure I fully understand your question, but below is an example of how the jaxb:class schema annotation can be used to point to an existing class.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    jaxb:version="2.1">

    <xs:element name="foo">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="bar"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:element name="bar">
        <xs:complexType>
            <xs:annotation>
                <xs:appinfo>
                    <jaxb:class ref="example.BarImpl"></jaxb:class>
                </xs:appinfo>
            </xs:annotation>
            <xs:sequence>
                <xs:element name="name" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

If you want to reuse all the types generated from an XML schema, then you may find episode files useful:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM