axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "R J Scheuerle Jr" <sc...@us.ibm.com>
Subject complexType extending a simpleType
Date Thu, 21 Feb 2002 21:12:03 GMT
According to XML Schema Primer 0 Chapter 2.5.1, a complexType can be
derived from a simple type to add attribute information.


Lets say you had the following schema:

<complexType name="purchaseItem">
     <complexContent>
          <sequence>
              <element name="itemName" type="xsd:string" />
              <element name="price" type="xsd:string" />
          </sequence>
     </complexContent>
</complexType>

The above could be sent over the wire as:

<purchaseItem>
  <itemName>
    Widget
  </item>
  <price>
   1.00
  </price>
<purchaseItem>

And the above would be modeled as a java bean named PurchaseItem with two
String properties.


Now let's say you extend this for an international market, thus the price
needs to know the
currency.  Since it is closely tied to the price, you want to represent
currency as an
attribute on price.   Here's how to represent this in xml schema.

<complexType name="internationalPrice">
    <complexContent>
        <simpleContent>
            <extension base="xsd:string"/>
                <attribute name="currency" type="xsd:string">
            </extension>
        </simpleContent>
    <complexContent>
</complexType>

<complexType name="purchaseItem">
     <complexContent>
          <sequence>
              <element name="itemName" type="xsd:string" />
              <element name="price" type="tns:internationalPrice" />
          </sequence>
     </complexContent>
</complexType>

So this means that price is an element whose value is a string and has a
currency attribute.

Here is an example over the wire:

<purchaseItem>
  <itemName>
    Widget
  </item>
  <price currency="USDollars">
   1.00
  </price>
<purchaseItem>


We don't support extension of simpleTypes yet.  When we do, we need
to generate a PurchaseItem bean (as before) and a InternationalPrice bean.

However, note that the InternationalPrice has a "raw" value that is
serialized
directly...not within an element and not as an attribute value.  The
serializer and deserializer need to know about this raw value, and the bean
requires
a special property name to get to the raw value.  (I propose getValue and
setValue
accessors, which match what we do with enumeration classes...our other kind
of simpleType).

So both emitters, bean serializer, and bean deserializer will need to have
extra code to support this feature.  (Note that this is an optional JAX-RPC
feature).


Comments?






Rich Scheuerle
XML & Web Services Development
512-838-5115  (IBM TL 678-5115)


Mime
View raw message