users@jaxb.java.net

Re: Support for collapsing element hierachy?

From: Sekhar Vajjhala <sekhar.vajjhala_at_sun.com>
Date: Thu, 23 Jan 2003 10:19:08 -0500

> Vishy Kasar wrote:
>
> Hi,
>
> Given the following schema, is there anyway we can instruct jaxb such that it generates code that follows schema?

There is no way to customize JAXB to generate the code.
The reason is that a complex type has a content model as
well as attributes. Therefore a complex type is always
bound to an interface and the its content model and
attribtues are bound to properties within the interface.

In your example, servlet-nameType is a complexType and
will therefore will always be bound to an interface.

>
> 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);
>
> }
>

--
Sekhar - Sun Microsystems