<!--

    DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.

    Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved.

    The contents of this file are subject to the terms of either the GNU
    General Public License Version 2 only ("GPL") or the Common Development
    and Distribution License("CDDL") (collectively, the "License").  You
    may not use this file except in compliance with the License.  You can
    obtain a copy of the License at
    https://oss.oracle.com/licenses/CDDL+GPL-1.1
    or LICENSE.txt.  See the License for the specific
    language governing permissions and limitations under the License.

    When distributing the software, include this License Header Notice in each
    file and include the License file at LICENSE.txt.

    GPL Classpath Exception:
    Oracle designates this particular file as subject to the "Classpath"
    exception as provided by Oracle in the GPL Version 2 section of the License
    file that accompanied this code.

    Modifications:
    If applicable, add the following below the License Header, with the fields
    enclosed by brackets [] replaced by your own identifying information:
    "Portions Copyright [year] [name of copyright owner]"

    Contributor(s):
    If you wish your version of this file to be governed by only the CDDL or
    only the GPL Version 2, indicate your decision by adding "[Contributor]
    elects to include this software in this distribution under the [CDDL or GPL
    Version 2] license."  If you don't indicate a single choice of license, a
    recipient has the option to distribute your version of this file under
    either the CDDL, the GPL Version 2 or to extend the choice of license to
    its licensees as provided above.  However, if you add GPL Version 2 code
    and therefore, elected the GPL Version 2 license, then the option applies
    only if the new code is made subject to such option by the copyright
    holder.

-->

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
            jxb:version="2.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="javax.xml.bind.DatatypeConverter.parseShort"
                                  printMethod="javax.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="javax.xml.bind.DatatypeConverter.parseInt"
                      printMethod="javax.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>
