<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.nordugrid.org/schemas/request-arc"
 xmlns:request-arc="http://www.nordugrid.org/schemas/request-arc"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">

 <!-- This schema defines a request to be fed into ArcPDP for
   evaluation against policy. Below is a tree of specified elements.
     Request (1)
       RequestItem (1-)
         Subject (1-)
           SubjectAttribute (1-)
         Resource (0-)
         Action (0-)
         Context (0-)
           ContextAttribute (1-)  
   
 -->
 
 <!-- Top-level element of request is <Request/>. Request is made
   of multiple <RequestItem/> elements which are evaluated separately.
  -->
 <xsd:element name="Request" type="request-arc:RequestType"/>
 <xsd:complexType name="RequestType">
  <xsd:sequence>
   <xsd:element ref="request-arc:RequestItem"  maxOccurs="unbounded"/>
  </xsd:sequence>
 </xsd:complexType>

 <!-- RequestItem resembles Rule in ARC Policy and provides information 
   to be matched against Rule. The difference is that it provides Context 
   instead of Condition. 
   There could be a few elements for each type under <RequestItem/>. Those 
   elements with the same type under a <RequestItem/> are not relevant. The 
   reason why put them together is just for the convenience of expression.
   For example, one <Subject/> could need to have two different <Action>s, then 
   we can put the two <Action>s together, and don't need to specify two <RequestItem/>   
   When doing policy evaluation, multiple elements with the same type under <RequestItem/>
   will be splitted and processed sepreatedly, e.g.,
   <RequestItem>
    <Subject>
    <Action>
    <Action>
   <RequestItem>
   will be splitted into two:
   <RequestItem>
    <Subject>
    <Action>
   <RequestItem>

  For each type of element under <RequestItem/>, there could be one or more <Attribute/>.
  This means the request can process a few <Attribute>. Realisticly, this situation applies
  to <Subject/> and <Context/>. For <Subject/>, it means the request can provide all of these 
  <Attribute>s, e.g. X509 DN, VOMS Attribute. For <Context/>, it means the request can
  satisfy all of these <Attribute>s, e.g. time, period.
  During policy evaluation, the element under <RequestItem> will need to exactly match the 
  policy side. If there is a few <Attribute>s for <Subject> on the policy side, like:   
     <Subject>
      <Attribute Type="string">/O=Grid/OU=KnowARC/CN=XYZ</Attribute>
      <Attribute Type="string">urn:mace:shibboleth:examples</Attribute>
     </Subject>
  Then on the request side, if and only if there are at least these above two <Attribute>s 
  exist:
     <Subject>
      <Attribute Type="string">/O=Grid/OU=KnowARC/CN=XYZ</Attribute>
      <Attribute Type="string">urn:mace:shibboleth:examples</Attribute>
      <Attribute Type="idaddress">129.240.86.1</Attribute> 
    </Subject>
  we can say the <Subject> on the request side can satisfy the <Subject> on the policy side.
  The above definition applies for the other types of element.
  -->

 <xsd:element name="RequestItem" type="request-arc:RequestItemType"/>
 <xsd:complexType name="RequestItemType">
  <xsd:sequence>
   <xsd:element ref="request-arc:Subject"  maxOccurs="unbounded"/>
   <xsd:element ref="request-arc:Resource" minOccurs="0" maxOccurs="unbounded"/>
   <xsd:element ref="request-arc:Action" minOccurs="0" maxOccurs="unbounded"/>
   <xsd:element ref="request-arc:Context" minOccurs="0" maxOccurs="unbounded"/>
  </xsd:sequence>
 </xsd:complexType>

 <!-- SubjectAttribute corresponds to Attribute element of Subject in 
    ARC Policy. While matching there must be proper SubjectAttribute
    for every Attribute in Policy's Subject. Data type may be defined
    at this level through 'Type' attribute. --> 
 <xsd:element name="SubjectAttribute" type="request-arc:SubjectAttributeType"/>
 <xsd:complexType name="SubjectAttributeType">
  <xsd:simpleContent>
   <xsd:extension base="xsd:string">
    <xsd:attribute name="AttributeId" type="xsd:anyURI" use="optional"/>
    <xsd:attribute name="Type" type="xsd:anyURI" use="optional"/>
    <xsd:attribute name="Issuer" type="xsd:string" use="optional"/>
   </xsd:extension>
  </xsd:simpleContent>
 </xsd:complexType>

 <!-- Each Subject is built of element called SubjectAttribute.
   The data type is specified either at this or lower level (SubjectAttribute) by 
   attribute Type. -->
 <xsd:element name="Subject" type="request-arc:SubjectType"/>
 <xsd:complexType name="SubjectType">
  <xsd:sequence>
   <xsd:element ref="request-arc:SubjectAttribute" maxOccurs="unbounded"/>
  </xsd:sequence>
  <xsd:attribute name="AttributeId" type="xsd:anyURI" use="optional"/>
  <xsd:attribute name="Type" type="xsd:anyURI" use="optional"/>
  <xsd:attribute name="Issuer" type="xsd:string" use="optional"/>
 </xsd:complexType>

 <!-- Resource element corresponds to Resource element in Policy. -->
 <xsd:element name="Resource" type="request-arc:ResourceType"/>
 <xsd:complexType name="ResourceType">
  <xsd:simpleContent>
   <xsd:extension base="xsd:string">
    <xsd:attribute name="AttributeId" type="xsd:string" use="optional"/>
    <xsd:attribute name="Type" type="xsd:anyURI"/>
   </xsd:extension>
  </xsd:simpleContent>
 </xsd:complexType>

 <!-- Action element corresponds to Action element in Policy. -->
 <xsd:element name="Action" type="request-arc:ActionType"/>
 <xsd:complexType name="ActionType">
  <xsd:simpleContent>
   <xsd:extension base="xsd:string">
    <xsd:attribute name="AttributeId" type="xsd:anyURI" use="optional"/>
    <xsd:attribute name="Type" type="xsd:string"/>
   </xsd:extension>
  </xsd:simpleContent>
 </xsd:complexType>

 <!-- Context element will be evaluted against Condition element in Policy -->
 <xsd:element name="ContextAttribute" type="request-arc:ContextAttributeType"/>
 <xsd:complexType name="ContextAttributeType">
  <xsd:simpleContent>
   <xsd:extension base="xsd:string">
    <xsd:attribute name="AttributeId" type="xsd:anyURI" use="optional"/>
    <xsd:attribute name="Type" type="xsd:string" use="optional"/>
   </xsd:extension>
  </xsd:simpleContent>
 </xsd:complexType>

 <xsd:element name="Context" type="request-arc:ContextType"/>
 <xsd:complexType name="ContextType">
  <xsd:sequence>
   <xsd:element ref="request-arc:ContextAttribute" maxOccurs="unbounded"/>
  </xsd:sequence>
  <xsd:attribute name="AttributeId" type="xsd:anyURI" use="optional"/>
  <xsd:attribute name="Type" type="xsd:string" use="optional"/>
 </xsd:complexType>

</xsd:schema>
