<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.springframework.org/schema/integration/mongodb"
			xmlns:xsd="http://www.w3.org/2001/XMLSchema"
			xmlns:tool="http://www.springframework.org/schema/tool"
			xmlns:integration="http://www.springframework.org/schema/integration"
			targetNamespace="http://www.springframework.org/schema/integration/mongodb"
			elementFormDefault="qualified">

	<xsd:import namespace="http://www.springframework.org/schema/beans"/>
	<xsd:import namespace="http://www.springframework.org/schema/integration"
				schemaLocation="https://www.springframework.org/schema/integration/spring-integration.xsd"/>

	<xsd:annotation>
		<xsd:documentation><![CDATA[
			Defines the configuration elements for Spring Integration mongodb Adapters.
		]]></xsd:documentation>
	</xsd:annotation>

	<xsd:element name="inbound-channel-adapter">
		<xsd:annotation>
			<xsd:documentation>
				Defines a Polling Channel Adapter for the
				'org.springframework.integration.mongodb.inbound.MongoDbMessageSource'
				that queries data from the MongoDB collection and produces messages to the channel.
			</xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:complexContent>
				<xsd:extension base="mongodbAdapterType">
					<xsd:sequence>
						<xsd:element ref="integration:poller" minOccurs="0"/>
					</xsd:sequence>
					<xsd:attribute name="query" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation>
								String representation of MongoDb Query (e.g.,
								query="{'name' : 'Bob'}").
								Please refer to MongoDb documentation for more query samples
								https://www.mongodb.org/display/DOCS/Querying
								This attribute is
								mutually exclusive with 'query-expression' attribute.
							</xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="query-expression" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation>
								SpEL expression which should resolve to a String query (please refer to the 'query'
								attribute),
								or to an instance of MongoDb Query (e.q., query-expression="new BasicQuery('{''name'' :
								''Bob''}').limit(2)").
								This attribute is mutually exclusive with 'query' attribute.
							</xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="update" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation>
								String representation of MongoDb Update (e.g., update="{$set: {'name' : 'Bob'}").
								Please refer to MongoDb documentation for more query samples
								https://www.mongodb.org/display/DOCS/Querying
								This attribute is
								mutually exclusive with 'update-expression' attribute.
							</xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="update-expression" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation>
								SpEL expression which should resolve to a String update (please refer to the 'update'
								attribute),
								or to an instance of MongoDb Update (e.q.,
								update-expression="T(Update).update('name', 'Bob')").
								This attribute is mutually exclusive with 'update' attribute.
							</xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="entity-class" type="xsd:string">
						<xsd:annotation>
							<xsd:appinfo>
								<xsd:documentation>
									The fully qualified name of the entity class to be passed to
									find(..) or findOne(..) method MongoTemplate.
									If this attribute is not provided the default value is com.mongodb.DBObject
								</xsd:documentation>
								<tool:annotation kind="direct">
									<tool:expected-type type="java.lang.Class"/>
								</tool:annotation>
							</xsd:appinfo>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="expect-single-result" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation>
								Allows you to manage find* method of MongoTemplate is used to query MongoDb. Default
								value for this
								attribute is 'false'. This means that we'll use find(..) method thus resulting in a
								Message with
								payload of type List of entities identified by 'entity-class' attribute. If you
								want/expect a single
								value set this attribute to 'true' which will result in invocation of findOne(..) method
								resulting in
								the payload of type identified by 'entity-class' attribute (default
								com.mongodb.DBObject)
							</xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
				</xsd:extension>
			</xsd:complexContent>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="outbound-channel-adapter">
		<xsd:annotation>
			<xsd:documentation>
				Configures a Consumer Endpoint for the
				'org.springframework.integration.mongodb.outbound.MongoDbStoringMessageHandler' that
				stores a data from incoming messages to the MongoDB collection.
			</xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:complexContent>
				<xsd:extension base="mongodbAdapterType">
					<xsd:choice minOccurs="0" maxOccurs="2">
						<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
						<xsd:element name="request-handler-advice-chain" type="integration:handlerAdviceChainType"
									 minOccurs="0" maxOccurs="1"/>
					</xsd:choice>
					<xsd:attribute name="order" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation>
								Specifies the order for invocation when this adapter is connected as a
								subscriber to a SubscribableChannel.
							</xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
				</xsd:extension>
			</xsd:complexContent>
		</xsd:complexType>
	</xsd:element>

	<xsd:element name="outbound-gateway">
		<xsd:annotation>
			<xsd:documentation>
				Configures a Consumer Endpoint for the
				'org.springframework.integration.mongodb.outbound.MongoDbOutboundGateway' for
				querying a MongoDb database in response to a message on the request channel.

				The response received from the database will be used to create the response
				Message on the reply channel.
			</xsd:documentation>
		</xsd:annotation>
		<xsd:complexType>
			<xsd:complexContent>
				<xsd:extension base="mongodbAdapterType">
					<xsd:choice minOccurs="0" maxOccurs="2">
						<xsd:element ref="integration:poller" minOccurs="0"/>
						<xsd:element name="request-handler-advice-chain" type="integration:handlerAdviceChainType"
									 minOccurs="0"/>
					</xsd:choice>
					<xsd:attribute name="request-channel" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation>
								The Message Channel where messages will be sent in order
								to query the database.
							</xsd:documentation>
							<xsd:appinfo>
								<tool:annotation kind="ref">
									<tool:expected-type type="org.springframework.messaging.MessageChannel"/>
								</tool:annotation>
							</xsd:appinfo>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="reply-channel" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation>
								The Message Channel to which the database response will be sent.
							</xsd:documentation>
							<xsd:appinfo>
								<tool:annotation kind="ref">
									<tool:expected-type type="org.springframework.messaging.MessageChannel"/>
								</tool:annotation>
							</xsd:appinfo>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="reply-timeout" type="xsd:string" default="30000">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
								Allows you to specify how long this gateway will wait for
								the reply message to be sent successfully to the reply channel
								before throwing an exception. This attribute only applies when the
								channel might block, for example when using a bounded queue channel that
								is currently full.

								Also, keep in mind that when sending to a DirectChannel, the
								invocation will occur in the sender's thread. Therefore,
								the failing of the send operation may be caused by other
								components further downstream.

								The "reply-timeout" attribute maps to the "sendTimeout" property of the
								underlying 'MessagingTemplate' instance (org.springframework.integration.core.MessagingTemplate).

								The value is specified in milliseconds.
							]]></xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="requires-reply" use="optional" default="true">
						<xsd:annotation>
							<xsd:documentation>
								Specify whether this outbound gateway must return a non-null value. This value is
								'true' by default, and a ReplyRequiredException will be thrown when
								the underlying service returns a null value.
							</xsd:documentation>
						</xsd:annotation>
						<xsd:simpleType>
							<xsd:union memberTypes="xsd:boolean xsd:string"/>
						</xsd:simpleType>
					</xsd:attribute>
					<xsd:attribute name="order">
						<xsd:annotation>
							<xsd:documentation>
								Specifies the order for invocation when this endpoint is connected as a
								subscriber to a SubscribableChannel.
							</xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="expect-single-result">
						<xsd:annotation>
							<xsd:documentation><![CDATA[
							This parameter indicates that only one result object will be
							returned from the database by using a findOne query.

							If set to 'false', the complete result list is returned
							as the payload.
							]]>
							</xsd:documentation>
						</xsd:annotation>
						<xsd:simpleType>
							<xsd:union memberTypes="xsd:boolean xsd:string"/>
						</xsd:simpleType>
					</xsd:attribute>
					<xsd:attribute name="query" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation>
								String representation of a MongoDb Query (e.g.,
								query="{'name' : 'Bob'}").
								Please refer to MongoDb documentation for more query samples
								https://www.mongodb.org/display/DOCS/Querying
								This attribute is
								mutually exclusive with 'query-expression' attribute.
							</xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="query-expression" type="xsd:string">
						<xsd:annotation>
							<xsd:documentation>
								SpEL expression which should resolve to a String query (please refer to the 'query'
								attribute), or to an instance of MongoDb Query (e.q.,
								query-expression="new BasicQuery('{''name'' : ''Bob''}').limit(2)").
							</xsd:documentation>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="entity-class" type="xsd:string">
						<xsd:annotation>
							<xsd:appinfo>
								<xsd:documentation>
									The fully qualified name of the entity class to be passed to
									find(..) or findOne(..) method MongoTemplate.
									If this attribute is not provided the default value is org.bson.Document
								</xsd:documentation>
								<tool:annotation kind="direct">
									<tool:expected-type type="java.lang.Class"/>
								</tool:annotation>
							</xsd:appinfo>
						</xsd:annotation>
					</xsd:attribute>
					<xsd:attribute name="collection-callback" type="xsd:string">
						<xsd:annotation>
							<xsd:appinfo>
								<xsd:documentation>
									Reference to an instance of
									org.springframework.integration.mongodb.outbound.MessageCollectionCallback
									with the request message context.
								</xsd:documentation>
								<tool:annotation kind="ref">
									<tool:expected-type
											type="org.springframework.data.mongodb.core.CollectionCallback"/>
								</tool:annotation>
							</xsd:appinfo>
						</xsd:annotation>
					</xsd:attribute>
				</xsd:extension>
			</xsd:complexContent>
		</xsd:complexType>
	</xsd:element>

	<xsd:complexType name="mongodbAdapterType">
		<xsd:annotation>
			<xsd:documentation>
				Common configuration for mongodb adapters.
			</xsd:documentation>
		</xsd:annotation>
		<xsd:attributeGroup ref="integration:channelAdapterAttributes"/>
		<xsd:attribute name="mongodb-factory" type="xsd:string">
			<xsd:annotation>
				<xsd:appinfo>
					<xsd:documentation>
						Reference to an instance of
						org.springframework.data.mongodb.MongoDbFactory
					</xsd:documentation>
					<tool:annotation kind="ref">
						<tool:expected-type type="org.springframework.data.mongodb.MongoDbFactory"/>
					</tool:annotation>
				</xsd:appinfo>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="mongo-template" type="xsd:string">
			<xsd:annotation>
				<xsd:appinfo>
					<xsd:documentation>
						Reference to an instance of
						org.springframework.data.mongodb.core.MongoTemplate
					</xsd:documentation>
					<tool:annotation kind="ref">
						<tool:expected-type type="org.springframework.data.mongodb.core.MongoTemplate"/>
					</tool:annotation>
				</xsd:appinfo>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="collection-name" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation>
					Identifies the name of the MongoDb collection to
					use.
					This attribute is mutually exclusive with
					'collection-name-expression'
					attribute.
				</xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="collection-name-expression" type="xsd:string">
			<xsd:annotation>
				<xsd:documentation>
					SpEL expression which should resolve to a String
					value identifying the
					name of the MongoDb collection to use.
					This
					attribute is mutually exclusive with 'collection-name' attribute.
				</xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
		<xsd:attribute name="mongo-converter" type="xsd:string">
			<xsd:annotation>
				<xsd:appinfo>
					<tool:annotation kind="ref">
						<tool:expected-type
								type="org.springframework.data.mongodb.core.convert.MongoConverter"/>
					</tool:annotation>
				</xsd:appinfo>
				<xsd:documentation>
					Reference to an instance of
					org.springframework.data.mongodb.core.convert.MongoConverter
				</xsd:documentation>
			</xsd:annotation>
		</xsd:attribute>
	</xsd:complexType>

</xsd:schema>
