<!--

    Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.

    This program and the accompanying materials are made available under the
    terms of the Eclipse Distribution License v. 1.0, which is available at
    http://www.eclipse.org/org/documents/edl-v10.php.

    SPDX-License-Identifier: BSD-3-Clause

-->

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://example.org"
            xmlns:e="http://example.org"
            xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
            jxb:version="3.0">
  <xsd:annotation>
    <xsd:appinfo>
      <jxb:globalBindings generateIsSetMethod="true"/>
    </xsd:appinfo>
  </xsd:annotation>

  <!-- type derivation hierarchy

               TravelType
               /     |    \
       PlaneType AutoType  TrainType
  -->

  <xsd:complexType name="TravelType">
    <xsd:annotation>
      <xsd:appinfo>
        <jxb:class implClass="extend.TravelTypeExtend"/>
      </xsd:appinfo>
    </xsd:annotation>
    <xsd:sequence>
      <xsd:element name="origin" type="xsd:string"/>
      <xsd:element name="destination" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="PlaneType">
    <xsd:annotation>
      <xsd:appinfo>
        <jxb:class implClass="extend.PlaneTypeExtend"/>
      </xsd:appinfo>
    </xsd:annotation>
    <xsd:complexContent>
      <xsd:extension base="e:TravelType">
        <xsd:sequence>
          <xsd:element name="flightNumber" type="xsd:int"/>
          <xsd:element name="meal" type="xsd:string"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:complexType name="AutoType">
    <xsd:annotation>
      <xsd:appinfo>
        <jxb:class implClass="extend.AutoTypeExtend"/>
      </xsd:appinfo>
    </xsd:annotation>
    <xsd:complexContent>
      <xsd:extension base="e:TravelType">
        <xsd:sequence>
          <xsd:element name="rentalAgency" type="e:RentalCompany"/>
          <xsd:element name="ratePerHour" type="xsd:int"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType name="TrainType">
    <xsd:annotation>
      <xsd:appinfo>
        <jxb:class implClass="extend.TrainTypeExtend"/>
      </xsd:appinfo>
    </xsd:annotation>
    <xsd:complexContent>
      <xsd:extension base="e:TravelType">
        <xsd:sequence>
          <xsd:element name="track" type="xsd:int"/>
          <xsd:element name="dailyScheduleNumber" type="xsd:int"/>
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:simpleType name="RentalCompany">
    <xsd:restriction base="xsd:NCName">
      <xsd:enumeration value="Avis"/>
      <xsd:enumeration value="Hertz"/>
      <xsd:enumeration value="RentAWreck"/>
    </xsd:restriction>
  </xsd:simpleType>

  <!-- Create the substitution group with head element "e:travel". -->
  <xsd:element name="travel" type="e:TravelType"/>
  <xsd:element name="plane" type="e:PlaneType"
               substitutionGroup="e:travel"/>
  <xsd:element name="auto" type="e:AutoType"
               substitutionGroup="e:travel"/>
  <xsd:element name="train" type="e:TrainType"
               substitutionGroup="e:travel"/>

  <xsd:element name="itinerary">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="e:travel" maxOccurs="unbounded"/>
        <!-- much other stuff -->
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>
