JAXB SCD change the class name generated from a complex type from schema

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

JAXB SCD change the class name generated from a complex type from schema

albert kao
I like to change the class name generated from a complex type from the following schema common.xsd. "UserType" rename to "User", "UserWithEffectiveDateType" rename to "UserWithEffectiveDate". I tried JAXB (v2.2.6) customization with "schema component designator" (SCD). However, output consists of "UserType" and "User", "UserWithEffectiveDateType" and "UserWithEffectiveDate". How to fix this problem?

common.xsd:

<xsd:complexType name="UserType">
    <xsd:sequence>
        <xsd:element name="firstname" type="xsd:string"/>
        <xsd:element name="lastname" type="xsd:string"/>
    </xsd:sequence>
</xsd:complexType>
<xsd:complexType name="UserWithEffectiveDateType">
    <xsd:complexContent>
        <xsd:extension base="xsd:UserType">
            <xsd:sequence>
                <xsd:element name="effectiveDate" type="xsd:date">
                </xsd:element>
            </xsd:sequence>
        </xsd:extension>
    </xsd:complexContent>        
</xsd:complexType>
user.xsd:

<xsd:include schemaLocation="common.xsd"/>
scd.xjb:

<?xml version="1.0" encoding="UTF-8"?>
    xmlns:tns="http://mycomp.com/xmlns/schemas" version="2.1">

    <bindings scd="x-schema::tns">
        <bindings scd="~tns:UserType">
            <class name="User" />
        </bindings>
    </bindings>
    <bindings scd="x-schema::tns">
        <bindings scd="~tns:UserWithEffectiveDateType">
            <class name="UserWithEffectiveDate" />
        </bindings>
    </bindings>
</bindings>
build.xml:

<xjc destdir="${jaxbout}"
  package="com.mycomp.webservices"
  source="2.0">
    <arg line="-extension"/>
    <arg line="-b"/>
    <arg file="${wsdl}/scd.xjb"/>
    <schema dir="${schemadir}">
        <include name="user.xsd"/>
    </schema>
    <depends dir="${schemadir}">
        <include name="common.xsd"/>
    </depends>
    <produces dir="${jaxbout}/com/mycomp/webservices">
        <include name="*.java"/>
    </produces>
</xjc>
output UserWithEffectiveDate.java:

// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.6
/*
 * <p>The following schema fragment specifies the expected content contained within this class.
 * <pre>
 * &lt;complexType name="UserWithEffectiveDateType">
 *   &lt;complexContent>
 *     &lt;extension base="{<a href="http://mycomp.com/xmlns/schemas}UserType">http://mycomp.com/xmlns/schemas}UserType">
 *       &lt;sequence>
 *         &lt;element name="effectiveDate" type="{<a href="http://www.w3.org/2001/XMLSchema}date">http://www.w3.org/2001/XMLSchema}date"/>
 *       &lt;/sequence>
 *     &lt;/extension>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "UserWithEffectiveDateType", propOrder = {
    "effectiveDate"
})
public class UserWithEffectiveDate
    extends User
{
    //....
}