<?xml version="1.0" encoding="utf-8"?>
<!--
 ~ Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 ~
 ~ WSO2 Inc. licenses this file to you under the Apache License,
 ~ Version 2.0 (the "License"); you may not use this file except
 ~ in compliance with the License.
 ~ You may obtain a copy of the License at
 ~
 ~    http://www.apache.org/licenses/LICENSE-2.0
 ~
 ~ Unless required by applicable law or agreed to in writing,
 ~ software distributed under the License is distributed on an
 ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 ~ KIND, either express or implied.  See the License for the
 ~ specific language governing permissions and limitations
 ~ under the License.
 -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="data">

    <xs:complexType>
       	 <xs:choice maxOccurs="unbounded">
                 <xs:element name="description" type="xs:string" maxOccurs="1" minOccurs="0"/>
          	 <xs:element name="config" maxOccurs="unbounded" minOccurs="1">
               		<xs:complexType>
                  		<xs:sequence>
					<xs:element ref="property" minOccurs="1" maxOccurs="unbounded"/>
                  		</xs:sequence>
                  		<xs:attribute name="id" type="xs:string" use="optional"/>
               		</xs:complexType>               
           	</xs:element>
         	<xs:element name="query" maxOccurs="unbounded" minOccurs="0">
               		<xs:complexType>
                   		<xs:choice maxOccurs="unbounded">
                       			<xs:element ref="sql" maxOccurs="unbounded" minOccurs="0"/>
                       			<xs:element name="sparql" type="xs:string" maxOccurs="1" minOccurs="0"/>
                       			<xs:element name="properties" maxOccurs="1" minOccurs="0">
                          			<xs:complexType>
                              				<xs:sequence>
                                  				<xs:element ref="property" minOccurs="0" maxOccurs="unbounded"/>
                              				</xs:sequence>
                          			</xs:complexType>
                       			</xs:element>
                       			<xs:element name="result" maxOccurs="1" minOccurs="0">
                           			<xs:complexType>
                               				<xs:choice maxOccurs="unbounded">
                                  				<xs:element ref="element" maxOccurs="unbounded" minOccurs="0"/>
                                   				<xs:element name="attribute" maxOccurs="unbounded" minOccurs="0">
                                      					<xs:complexType>
                                          					<xs:attribute name="name" type="xs:string" use="required"/>
                                          					<xs:attribute name="column" type="xs:string" use="required"/>
                                          					<xs:attribute name="xsdType" type="xs:string" use="optional"/>
                                          					<xs:attribute name="requiredRoles" type="xs:string" use="optional"/>
                                      					</xs:complexType>
                                   				</xs:element>
                                   				<xs:element ref="call-query" maxOccurs="unbounded" minOccurs="0"/>
                               				</xs:choice>
                               				<xs:attribute name="element" type="xs:string" use="required"/>
                               				<xs:attribute name="rowName" type="xs:string" use="required"/>
                               				<xs:attribute name="defaultNamespace" type="xs:string" use="optional"/>
                               				<xs:attribute name="xsltPath" type="xs:string" use="optional"/>
                           			</xs:complexType>
                       			</xs:element>
                       			<xs:element name="excel" maxOccurs="unbounded" minOccurs="0">
                           			<xs:complexType>
                               				<xs:sequence>
                                   				<xs:element name="workbookname" type="xs:string"/>
                                   				<xs:element name="hasheader" type="xs:boolean"/>
                                   				<xs:element name="startingrow" type="xs:unsignedLong"/>
                                   				<xs:element name="maxrowcount" type="xs:unsignedLong"/>
                               				</xs:sequence>
                           			</xs:complexType>
                       			</xs:element>
                       			<xs:element name="gspread" maxOccurs="unbounded" minOccurs="0">
                           			<xs:complexType>
                               				<xs:sequence>
                                   				<xs:element name="worksheetnumber" type="xs:unsignedLong"/>
                                   				<xs:element name="startingrow" type="xs:unsignedLong"/>
                                   				<xs:element name="maxrowcount" type="xs:unsignedLong"/>
                                   				<xs:element name="hasheader" type="xs:boolean"/>
                               				</xs:sequence>
                           			</xs:complexType>
                       			</xs:element>
                       			<xs:element name="param" maxOccurs="unbounded" minOccurs="0">
                           			<xs:complexType>
                               				<xs:sequence>
                                   				<xs:element name="validateLongRange" maxOccurs="1" minOccurs="0">
                                       					<xs:complexType>
                                           					<xs:attribute name="minimum" type="xs:long" use="optional"/>
                                           					<xs:attribute name="maximum" type="xs:long" use="optional"/>
                                       					</xs:complexType>
                                   				</xs:element>
                                   				<xs:element name="validateDoubleRange" maxOccurs="1" minOccurs="0">
                                       					<xs:complexType>
                                           					<xs:attribute name="minimum" type="xs:double" use="optional"/>
                                          					<xs:attribute name="maximum" type="xs:double" use="optional"/>
                                       					</xs:complexType>
                                   				</xs:element>
                                   				<xs:element name="validateLength" maxOccurs="1" minOccurs="0">
                                       					<xs:complexType>
                                           					<xs:attribute name="minimum" type="xs:unsignedLong" use="optional"/>
                                           					<xs:attribute name="maximum" type="xs:unsignedLong" use="optional"/>
                                       					</xs:complexType>
                                   				</xs:element>
                                   				<xs:element name="validatePattern" maxOccurs="unbounded" minOccurs="0">
                                       					<xs:complexType>
                                          					 <xs:attribute name="pattern" type="xs:string" use="required"/>
                                       					</xs:complexType>
                                   				</xs:element>
                                   				<xs:element name="validateCustom" maxOccurs="unbounded" minOccurs="0">
                                       					<xs:complexType>
                                           					<xs:attribute name="class" type="xs:string" use="required"/>
                                       					</xs:complexType>
                                   				</xs:element>
                               				</xs:sequence>
                               				<xs:attribute name="name" type="xs:string" use="required"/>
                               				<xs:attribute name="paramType" type="xs:string" use="optional"/>
                               				<xs:attribute name="sqlType" type="xs:string" use="required"/>
                              				<xs:attribute name="type" type="xs:string" use="optional"/>
                               				<xs:attribute name="ordinal" type="xs:unsignedInt" use="optional"/>
                               				<xs:attribute name="defaultValue" type="xs:string" use="optional"/>
			       				<xs:attribute name="structType" type="xs:string" use="optional"/>
                           			</xs:complexType>                           
                       			</xs:element>
                   		</xs:choice>
                   		<xs:attribute name="id" type="xs:string" use="required"/>
                   		<xs:attribute name="useConfig" type="xs:string" use="optional"/>
                   		<xs:attribute name="input-event-trigger" type="xs:string" use="optional"/>
                   		<xs:attribute name="output-event-trigger" type="xs:string" use="optional"/>
				<xs:attribute name="returnGeneratedKeys" type="xs:boolean" use="optional"/>
				<xs:attribute name="keyColumns" type="xs:string" use="optional"/>
               		</xs:complexType>
           	</xs:element>
           	<xs:element name="event-trigger" maxOccurs="unbounded" minOccurs="0">
               		<xs:complexType>
                   		<xs:sequence>
                      			<xs:element name="expression" type="xs:string" maxOccurs="1" minOccurs="1"/>
                      			<xs:element name="target-topic" type="xs:string " maxOccurs="1" minOccurs="1"/>
                      			<xs:element name="subscriptions" maxOccurs="1" minOccurs="1">
                          			<xs:complexType>
                              				<xs:sequence>
                                  				<xs:element name="subscription" type="xs:string" maxOccurs="unbounded" minOccurs="1"/>
                              				</xs:sequence>
                          			</xs:complexType>
                      			</xs:element>
                   		</xs:sequence>
                   		<xs:attribute name="id" type="xs:string" use="required"/>
               		</xs:complexType>
           	</xs:element>
           		<xs:element name="operation" maxOccurs="unbounded" minOccurs="0">
               			<xs:complexType>
                            <xs:sequence>
                                <xs:element ref="call-query" maxOccurs="1" minOccurs="1"/>
                            </xs:sequence>
                   			<xs:attribute name="name" type="xs:string" use="required"/>
                            <xs:attribute name="disableStreaming" type="xs:boolean" use="optional"/>
                            <xs:attribute name="returnRequestStatus" type="xs:boolean" use="optional"/>
               			</xs:complexType>
           		</xs:element>
           		<xs:element name="resource" maxOccurs="unbounded" minOccurs="0">
               			<xs:complexType>
                   			<xs:sequence>
                       				<xs:element ref="call-query" maxOccurs="1" minOccurs="1"/>
                   			</xs:sequence>
                   			<xs:attribute name="path" type="xs:string" use="required"/>
                   			<xs:attribute name="method" type="xs:string" use="required"/>
               			</xs:complexType>
           		</xs:element>
         	</xs:choice>
         	<xs:attribute name="name" type="xs:string" use="required"/>
         	<xs:attribute name="enableBatchRequests" type="xs:boolean" use="optional"/>
         	<xs:attribute name="enableBoxcarring" type="xs:boolean" use="optional"/>
                <xs:attribute name="serviceGroup" type="xs:string" use="optional"/>
         	<xs:attribute name="serviceStatus" use="optional">
             		<xs:simpleType>
				<xs:restriction base="xs:string">
		    			<xs:enumeration value="active"/>
		    			<xs:enumeration value="inactive"/>
				</xs:restriction>
	     		</xs:simpleType>
         	</xs:attribute>
         	<xs:attribute name="baseURI" type="xs:string"  use="optional"/>
         	<xs:attribute name="enableDTP" type="xs:boolean" use="optional"/>
    	</xs:complexType>
    </xs:element>
    
    <xs:element name="call-query">
         <xs:complexType>
             <xs:sequence>
                 <xs:element name="with-param" maxOccurs="unbounded" minOccurs="0">
                     <xs:complexType>
                         <xs:attribute name="name" type="xs:string" use="required"/>
                         <xs:attribute name="query-param" type="xs:string" use="optional"/>
                         <xs:attribute name="column" type="xs:string" use="optional"/>
                     </xs:complexType>
                 </xs:element>
             </xs:sequence>
             <xs:attribute name="href" type="xs:string" use="required"/>
         </xs:complexType>
     </xs:element>

     <xs:element name="sql">
         <xs:complexType>
              <xs:simpleContent>
                   <xs:extension base="xs:string">
                        <xs:attribute name="dialect" type="xs:string" use="optional" />
                   </xs:extension>
              </xs:simpleContent>
         </xs:complexType>
     </xs:element>

     <xs:element name="property">
	<xs:complexType mixed="true">
                <xs:sequence minOccurs="0" maxOccurs="unbounded">
                        <xs:element ref="property"/>
                </xs:sequence>
		<xs:attribute name="name" type="xs:string" use="optional" />
        </xs:complexType>
     </xs:element>

     <xs:element name="element">
          <xs:complexType>
	     <xs:sequence minOccurs="0" maxOccurs="unbounded">
		<xs:element ref="element"/>
	     </xs:sequence>
             <xs:attribute name="name" type="xs:string" use="required"/>
             <xs:attribute name="column" type="xs:string" use="required"/>
             <xs:attribute name="xsdType" type="xs:string" use="optional"/>
             <xs:attribute name="requiredRoles" type="xs:string" use="optional"/>
             <xs:attribute name="export" type="xs:string" use="optional"/>
          </xs:complexType>
     </xs:element>

</xs:schema>
