<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="0.2"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.esgf.org/registry"
            xmlns:tns="http://www.esgf.org/registry">


    <xsd:attributeGroup name="ServiceAttributes">
        <!-- This is needed because services can have different protocol, relative URLs and port numbers
One another way to do this to enfoce that this service URL is for something that is only on that host,
is to allow configuration of scheme (http, https, gsiftp), port and relative URL as separate attributes.
That does make it more wordy, and require and reconstruction. -->
        <xsd:attribute name="endpoint" type="xsd:string" use="required"/>
        <!-- If DN is not set, it is assumed that the services uses the host certificate,
        and hence DN of the Node element is used in white listing -->
        <xsd:attribute name="dn" type="xsd:string"/>
        <xsd:attribute name="version" type="xsd:string"/>

    </xsd:attributeGroup>

    <xsd:element name="CA">
        <xsd:complexType>
            <xsd:attributeGroup ref="tns:ServiceAttributes"/>
            <xsd:attribute name="hash" type="xsd:string" use="required"/>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="OpenIDProvider">
        <xsd:complexType>
            <xsd:attributeGroup ref="tns:ServiceAttributes"/>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="IndexService">
        <xsd:complexType>
            <xsd:attributeGroup ref="tns:ServiceAttributes"/>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="AttributeService">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="tns:Group" minOccurs="0" maxOccurs="unbounded"/>
            </xsd:sequence>
            <xsd:attributeGroup ref="tns:ServiceAttributes"/>
        </xsd:complexType>
    </xsd:element>

    <!-- Describes each group, such that it can be associated with an AuthZ Service
    The group name along with the organization namespace should make the group unique.
    -->
    <xsd:element name="Group">
        <xsd:complexType>
            <xsd:attribute name="name" type="xsd:string" use="required"/>
            <xsd:attribute name="description" type="xsd:string" use="required"/>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="AuthorizationService">
        <xsd:complexType>
            <xsd:attributeGroup ref="tns:ServiceAttributes"/>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="OAIRepository">
        <xsd:complexType>
            <xsd:attributeGroup ref="tns:ServiceAttributes"/>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="ThreddsService">
        <xsd:complexType>
            <xsd:attributeGroup ref="tns:ServiceAttributes"/>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="MetricsService">
        <xsd:complexType>
            <xsd:attributeGroup ref="tns:ServiceAttributes"/>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="MyProxyService">
        <xsd:complexType>
            <xsd:attributeGroup ref="tns:ServiceAttributes"/>
        </xsd:complexType>
    </xsd:element>
    
    <xsd:simpleType name="GridFTPServiceType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="Replication"/>
            <xsd:enumeration value="Download"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:element name="Configuration">
        <xsd:complexType>
            <xsd:attribute name="serviceType" type="tns:GridFTPServiceType" use="required"/>
            <xsd:attribute name="port" type="xsd:string" use="required"/>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="GridFTPService">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element ref="tns:Configuration" minOccurs="0" maxOccurs="unbounded"/>
            </xsd:sequence>
            <xsd:attributeGroup ref="tns:ServiceAttributes"/>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="LASService">
        <xsd:complexType>
            <xsd:attributeGroup ref="tns:ServiceAttributes"/>
        </xsd:complexType>
    </xsd:element>

    <xsd:element name="PublishingService">
      <xsd:complexType>
          <xsd:attributeGroup ref="tns:ServiceAttributes"/>
      </xsd:complexType>
    </xsd:element>

    <xsd:element name="RelyingPartyService">
      <xsd:complexType>
          <xsd:attributeGroup ref="tns:ServiceAttributes"/>
      </xsd:complexType>
    </xsd:element>

    <xsd:element name="PEMCert">
      <xsd:complexType>
        <xsd:element name="Cert" type="xsd:string"/>
      </xsd:complexType>
    </xsd:element>



    <xsd:attributeGroup name="ResourceAttributes">
        <!-- Name of organization -->
        <xsd:attribute name="organization" type="xsd:string" use="required"/>
        <!-- Oragnization namespace org.esgf.badc, etc -->
        <xsd:attribute name="namespace" type="xsd:string" use="required"/>
        <!-- Address to send requests to -->
        <xsd:attribute name="supportEmail" type="xsd:string"/>
        <!-- Hostname, full domain name, and unique identifier -->
        <xsd:attribute name="hostname" type="xsd:string" use="required"/>
        <!-- Host Certificate DN, will be used as default identity for all services,
        unless overridden by the DN attribute in the service -->
        <xsd:attribute name="dn" type="xsd:string" use="required"/>

        <xsd:attribute name="shortName" type="xsd:string" use="required"/>
        <xsd:attribute name="longName" type="xsd:string"/>
        <xsd:attribute name="timeStamp" type="xsd:long" use="required"/>
        <xsd:attribute name="version" type="xsd:string" use="required"/>
        <xsd:attribute name="release" type="xsd:string"/>

    </xsd:attributeGroup>


    <xsd:complexType name="Node">
        <xsd:all>
            <xsd:element ref="tns:CA" minOccurs="0" maxOccurs="1"/>
            <xsd:element ref="tns:OpenIDProvider" minOccurs="0" maxOccurs="1"/>
            <xsd:element ref="tns:IndexService" minOccurs="0" maxOccurs="1"/>
            <xsd:element ref="tns:AttributeService" minOccurs="0" maxOccurs="1"/>
            <xsd:element ref="tns:AuthorizationService" minOccurs="0" maxOccurs="1"/>
            <xsd:element ref="tns:OAIRepository" minOccurs="0" maxOccurs="1"/>
            <xsd:element ref="tns:ThreddsService" minOccurs="0" maxOccurs="1"/>
            <xsd:element ref="tns:GridFTPService" minOccurs="0" maxOccurs="1"/>
            <xsd:element ref="tns:MetricsService" minOccurs="0" maxOccurs="1"/>
            <xsd:element ref="tns:LASService" minOccurs="0" maxOccurs="1"/>
            <xsd:element ref="tns:MyProxyService" minOccurs="0" maxOccurs="1"/>
            <xsd:element ref="tns:PublishingService" minOccurs="0" maxOccurs="1"/>
            <xsd:element ref="tns:RelyingPartyService" minOccurs="0" maxOccurs="1"/>
            <xsd:element ref="tns:PEMCert" minOccurs="0" maxOccurs="1"/>
        </xsd:all>
        <xsd:attributeGroup ref="tns:ResourceAttributes"/>
    </xsd:complexType>

    <!-- Unsure how to express that atleast one node type must be specified. -->
    <xsd:element name="Registration">
        <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="Node" type="tns:Node" minOccurs="1" maxOccurs="unbounded"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

</xsd:schema>
