users@jaxb.java.net

Support for collapsing element hierachy?

From: Vishy Kasar <vkasar_at_borland.com>
Date: Wed, 22 Jan 2003 17:17:05 -0800

Hi,

Given the following schema, is there anyway we can instruct jaxb such that it generates code that follows schema?

Essentially, if xml element is defined to be type X which is of type Y which is really a String, can JAXB collapse
the hierarchy and simply generate a method that deals with java.lang.String?

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
     targetNamespace="http://java.sun.com/xml/ns/j2ee"
     xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
     elementFormDefault="qualified"
     attributeFormDefault="unqualified"
     version="2.4">

<xsd:element name="sm" type="j2ee:servlet-mappingType"/>

<xsd:complexType name="servlet-mappingType">
    <xsd:sequence>
        <xsd:element name="servlet-name"
                     type="j2ee:servlet-nameType">
        </xsd:element>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
</xsd:complexType>

<xsd:complexType name="servlet-nameType">
    <xsd:simpleContent>
        <xsd:restriction base="j2ee:string"/>
    </xsd:simpleContent>
</xsd:complexType>

<xsd:complexType name="string">
<xsd:annotation>
<xsd:appinfo>
<jxb:class name="IdString"/>
</xsd:appinfo>
</xsd:annotation>
    <xsd:simpleContent>
        <xsd:extension base="xsd:token">
            <xsd:attribute name="id" type="xsd:ID"/>
        </xsd:extension>
    </xsd:simpleContent>
</xsd:complexType>

</xsd:schema>

-----------------------------------------------------

public interface ServletMappingType {

    // dont want: com.borland.jaxb.ServletNameType getServletName();
    java.lang.String getServletName();

    // dont want: void setServletName(com.borland.jaxb.ServletNameType value);
    void setServletName(java.lang.String value);

    String getId();

    void setId(String value);

}