<!--

    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"
            xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
            jxb:version="3.0">
  <xsd:annotation>
    <xsd:documentation>
      jxb:globalBindings element documentation:
      To illustrate all global controllable settings, listed all
      attributes with their default values except for
      @fixedAttributeAsConstantProperty and @collectionType.

      @fixedAttributeAsConstantProperty set to true indicates that
      all fixed attributes should be bound to Java constants. By
      default, fixed attributes are just mapped to either simple
      or collection property, which ever is more appropriate.

      @collectionType set to java.util.Vector specifies that all
      lists in the generated implementation classes should be represented
      internally as vectors.

      If @typesafeEnumBase was set to"xsd:string", it is a global way to specify
      that all simple type definitions deriving directly or indirectly
      from "xsd:string" and having enumeration facets should be bound
      to a typesafe enum. The typesafeEnumClass customization in simple
      type definition of USState would be redundant with this suggested
      change. If @typesafeEnumBase was set to empty string, "", no simple
      type definitions would ever be bound to a typesafe enum class by
      default binding.

      jxb:schemaBindings documentation:
      child element jxb:package specifes a java package for the Java
      representation generated for this schema.

      child element jxb:nameXmlTransform/jxb:elementName specifies that
      all Java element interfaces generated should have "Element"
      appended to names generated by default. For this schema,
      customization results in element interfaces CommentElement and
      PurchaseOrderElement being generated. Default binding would
      generate element interface Comment and PurchaseOrderElement.
      jxb:nameXmlTransform has children elements for the symbol space
      typeName, anonymousTypeName and modelGroupName.
    </xsd:documentation>
    <xsd:appinfo>
      <jxb:globalBindings
              fixedAttributeAsConstantProperty="false"
              collectionType="java.util.Vector"
              typesafeEnumBase="xsd:NCName"
              choiceContentProperty="false"
              typesafeEnumMemberName="generateError"
              enableFailFastCheck="false"
              generateIsSetMethod="false"
              underscoreBinding="asCharInWord"/>
      <jxb:schemaBindings>
        <jxb:package name="primer.myPo">
          <jxb:javadoc><![CDATA[<body>Package level documentation for generated package primer.myPo.</body>]]>
          </jxb:javadoc>
        </jxb:package>
        <jxb:nameXmlTransform>
          <jxb:elementName suffix="Element"/>
        </jxb:nameXmlTransform>
      </jxb:schemaBindings>
    </xsd:appinfo>
  </xsd:annotation>
  <xsd:element name="purchaseOrder" type="PurchaseOrderType"/>
  <xsd:element name="comment" type="xsd:string"/>
  <xsd:complexType name="PurchaseOrderType">
    <xsd:annotation>
      <xsd:appinfo>
        <jxb:class name="POType">
          <jxb:javadoc>A &lt;b>Purchase Order&lt;/b> consists of addresses and items.</jxb:javadoc>
        </jxb:class>
      </xsd:appinfo>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:element name="shipTo" type="USAddress"/>
      <xsd:element name="billTo" type="USAddress"/>
      <xsd:element ref="comment" minOccurs="0"/>
      <xsd:element name="items" type="Items"/>
    </xsd:sequence>
    <xsd:attribute name="orderDate" type="xsd:date"/>
  </xsd:complexType>

  <xsd:complexType name="USAddress">
    <xsd:annotation>
      <xsd:appinfo>
        <jxb:class>
          <jxb:javadoc><![CDATA[First line of documentation for a <b>USAddress</b>.]]></jxb:javadoc>
        </jxb:class>
      </xsd:appinfo>
    </xsd:annotation>
    <xsd:sequence>
      <xsd:element name="name" type="xsd:string">
        <xsd:annotation>
          <xsd:appinfo>
            <jxb:property name="toName"/>
          </xsd:appinfo>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="street" type="xsd:string"/>
      <xsd:element name="city" type="xsd:string"/>
      <xsd:element name="state" type="USState"/>
      <xsd:element name="zip" type="ZipCodeType">
        <xsd:annotation>
          <xsd:appinfo>
            <jxb:property name="zipCode"/>
          </xsd:appinfo>
        </xsd:annotation>
      </xsd:element>
    </xsd:sequence>
    <xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US"/>
  </xsd:complexType>

  <xsd:complexType name="Items">
    <xsd:sequence>
      <xsd:element name="item" minOccurs="1" maxOccurs="unbounded">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element name="productName" type="xsd:string"/>
            <xsd:element name="quantity" default="10">
              <xsd:annotation>
                <xsd:documentation>
                  JAXB customization documentation:
                  jaxb:property @generateIsSetMethod results in additional property
                  methods,isSetQuantity and unsetQuantity, being generated to
                  to be able to distinguish between schema defaulted value
                  and values occuring explicitly within an instance document.
                </xsd:documentation>
                <xsd:appinfo>
                  <jxb:property generateIsSetMethod="true"/>
                </xsd:appinfo>
              </xsd:annotation>
              <xsd:simpleType>
                <xsd:annotation>
                  <xsd:documentation>
                    By default, JAXB specification maps an xsd:positiveInteger to
                    a java.math.BigInteger. Since this simpleType is constrained to
                    be a value between 0..100, it is more natural for the Java
                    program to map this to a "short" Java datatype.
                  </xsd:documentation>
                  <xsd:appinfo>
                    <jxb:javaType name="short"
                                  parseMethod="jakarta.xml.bind.DatatypeConverter.parseShort"
                                  printMethod="jakarta.xml.bind.DatatypeConverter.printShort"/>
                  </xsd:appinfo>
                </xsd:annotation>
                <xsd:restriction base="xsd:positiveInteger">
                  <xsd:maxExclusive value="100"/>
                </xsd:restriction>
              </xsd:simpleType>
            </xsd:element>
            <xsd:element name="USPrice" type="xsd:decimal">
              <xsd:annotation>
                <xsd:appinfo>
                  <jxb:property name="Price"/>
                </xsd:appinfo>
              </xsd:annotation>
            </xsd:element>
            <xsd:element ref="comment" minOccurs="0"/>
            <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/>
          </xsd:sequence>
          <xsd:attribute name="partNum" type="SKU" use="required">
            <xsd:annotation>
              <xsd:appinfo>
                <jxb:property name="partNumber"/>
              </xsd:appinfo>
            </xsd:annotation>
          </xsd:attribute>
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>
  </xsd:complexType>

  <!-- Stock Keeping Unit, a code for identifying products -->
  <xsd:simpleType name="SKU">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="\d{3}-[A-Z]{2}"/>
    </xsd:restriction>
  </xsd:simpleType>


  <xsd:simpleType name="USState">
    <xsd:annotation>
      <xsd:appinfo>
        <jxb:typesafeEnumClass/>
      </xsd:appinfo>
      <xsd:documentation>
        This is a localized way to map this simple type definition
        to a typesafe enum class. See jxb:globalBindings
        @typesafeEnumBase above for a global way to accomplish this
        for all simple type definitions similar to this one.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="AK"/>
      <xsd:enumeration value="AL"/>
      <xsd:enumeration value="AR"/>
      <xsd:enumeration value="CA"/>
      <xsd:enumeration value="MA"/>
      <!-- and so on ... -->
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="ZipCodeType">
    <xsd:annotation>
      <xsd:documentation>
        Legal zip codes are limited to 5 digits, extended Zip Code not
        supported.

        JAXB customization: jaxb:javaType binding declaration overrides
        default binding of this type to a java.lang.Integer. The
        constraint facets for this type restrict the valid values of this
        type to easily fit within Java primitive datatype int.
      </xsd:documentation>
      <xsd:documentation>
        Given the value range of an xsd:integer, it is mapped to
        java.math.BigInteger by default. When one considers the
        constaining facets for this type are between 10000..99999,
        it is safe to bind this simple type directly to the
        Java datatype "int" using the following customization.
      </xsd:documentation>
      <xsd:appinfo>
        <jxb:javaType name="int"
                      parseMethod="jakarta.xml.bind.DatatypeConverter.parseInt"
                      printMethod="jakarta.xml.bind.DatatypeConverter.printInt"/>
      </xsd:appinfo>
    </xsd:annotation>
    <xsd:restriction base="xsd:integer">
      <xsd:minInclusive value="10000"/>
      <xsd:maxInclusive value="99999"/>
    </xsd:restriction>
  </xsd:simpleType>
</xsd:schema>
