<?xml version="1.0" encoding="UTF-8"?>

<xs:schema version="2.0"
	targetNamespace="http://futurs.inria.fr/gemo/axml/service/Query"
	xmlns="http://futurs.inria.fr/gemo/axml/service/Query"
	xmlns:axml="http://futurs.inria.fr/gemo/axml/"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	elementFormDefault="qualified">

	<xs:annotation><xs:documentation>
		Defines types and elements needed for the query service of a peer.
	</xs:documentation></xs:annotation>

	<xs:import namespace="http://futurs.inria.fr/gemo/axml/"
		schemaLocation="axml_related.xsd">
	</xs:import>

	<xs:element name="query">
		<xs:annotation><xs:documentation>
			This tag allows to declare a query. Some tool may simply transform it into a Web service
			because with Axis2 it is wuite straightforward.
		</xs:documentation></xs:annotation>
		<xs:complexType>
			<xs:sequence>
				<xs:element name="comment" type="xs:string">
					<xs:annotation><xs:documentation>
						Some comments on the Web service. When the Web service is deployed this comment should become
						a comment for the Web service
					</xs:documentation></xs:annotation>
				</xs:element>			
				<xs:element ref="declaration"></xs:element>
			</xs:sequence>
			<xs:attribute name="name" type="xs:string" use="required">
				<xs:annotation><xs:documentation>
					Normally this name should become a Web service name
				</xs:documentation></xs:annotation>
			</xs:attribute>
		</xs:complexType>
	</xs:element>
	
	<xs:element name="declaration" type="DeclarationType">
		<xs:annotation><xs:documentation>
		If one needs to declare a parameter and use it multiple
		times, normally "let" clause of XQuery should be used.
		
		This element should contain a valid XQuery. The 'param' elements
		will be replaced by the query with actual incoming parameter values
		</xs:documentation></xs:annotation>
		<xs:unique name="uniqueParameterForTheQuery">
			<xs:selector xpath="param"></xs:selector>
			<xs:field xpath="@name"></xs:field>
		</xs:unique>
	</xs:element>
	<xs:complexType name="DeclarationType" mixed="true">
		<xs:sequence maxOccurs="unbounded">
			<xs:any minOccurs="0" processContents="lax"></xs:any>
		</xs:sequence>
	</xs:complexType>
	
	<xs:element name="param" type="ParameterType">
	</xs:element>
	<xs:complexType name="ParameterType" mixed="true">
		<xs:annotation>
			<xs:documentation>
				The content of the element is the actual/default parameter
				value
			</xs:documentation>
		</xs:annotation>
		<xs:sequence maxOccurs="unbounded">
			<xs:any minOccurs="0" processContents="lax" namespace="##any"></xs:any>
		</xs:sequence>
		<xs:attribute name="name" type="xs:NCName" use="required">
			<xs:annotation>
				<xs:documentation>
					The name given for the parameter
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:complexType>

	<!-- WSDL -->
	<xs:element name="continuousQuery">
		<xs:annotation><xs:documentation>
			This element used in sc/ws-soap/continuousQuery declares the QUERY service call
		</xs:documentation></xs:annotation>
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="declaration">
					<xs:annotation><xs:documentation>
						The (parametrized) query declaration. The Web service will possibly install buffers 
						for every parameter and will start waiting for the END_OF_STREAM
					</xs:documentation></xs:annotation>
				</xs:element>
				<xs:element ref="param" minOccurs="1"
					maxOccurs="unbounded">
					<xs:annotation><xs:documentation>
						The actual parameters that should be filled the formal ones specified in the 'declaration'.
					</xs:documentation></xs:annotation>	
				</xs:element>
			</xs:sequence>
			<xs:attribute ref="axml:marker" use="optional" default="STREAM">
				<xs:annotation><xs:documentation>
					Whenever there is nothing more to send to the Web service the materializer of the QUERY service call
					marks END_OF_STREAM and this way the streaming channel stops.
				</xs:documentation></xs:annotation>
			</xs:attribute>
			<xs:attribute ref="axml:streamSize" use="optional" default="0">
				<xs:annotation><xs:documentation>
					The size of stream.
				</xs:documentation></xs:annotation>
			</xs:attribute>
		</xs:complexType>
		<xs:unique name="uniqueParameterForTheContinuousRequest">
			<xs:selector xpath="param"></xs:selector>
			<xs:field xpath="@name"></xs:field>
		</xs:unique>
	</xs:element>

	<!-- WSDL -->
	<xs:element name="executeGenericQuery">
		<xs:annotation><xs:documentation>
			This element used in sc/ws-soap/executeGenericQuery declares the GENERIC_QUERY service call
		</xs:documentation></xs:annotation>
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="declaration">
					<xs:annotation><xs:documentation>
						Any valid (non-parameterized) XQuery expression. The Web service will pass it to the 
						XML database for execution
					</xs:documentation></xs:annotation>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	
	<!-- WSDL -->
	<xs:element name="executeQuery">
		<xs:annotation><xs:documentation>
			When there is a specific query service installed on the server, e.g. the (parameterized) query is defined in query.xml,
			then calling this method will fill formal parameters with actual values, evaluate the query and return the results.
		</xs:documentation></xs:annotation>
		<xs:complexType>
			<xs:choice minOccurs="0">
				<xs:sequence maxOccurs="unbounded">
					<xs:element ref="param">
						<xs:annotation><xs:documentation>
							Actual parameters for the declared query
						</xs:documentation></xs:annotation>
					</xs:element>
				</xs:sequence>
				<xs:sequence maxOccurs="unbounded">
					<xs:any processContents="lax" namespace="##local">
						<xs:annotation><xs:documentation>
							Instead of strict parameters we allow any element to be a parameter.
							The name of the parameter corresponds to the element name, the contents 
							of the element are the parameter value
						</xs:documentation></xs:annotation>
					</xs:any>
				</xs:sequence>
			</xs:choice>
		</xs:complexType>
		<xs:unique name="uniqueParameterForTheSimpleRequest">
			<xs:selector xpath="param"></xs:selector>
			<xs:field xpath="@name"></xs:field>
		</xs:unique>
	</xs:element>
</xs:schema>