<!--
  Copyright (c) 2010, DropboxMQ, http://dropboxmq.sf.net & Dwayne Schultz
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are
  met:

     * Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.
     * Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.
     * Neither the name of DropboxMQ nor the names of its contributors may
       be used to endorse or promote products derived from this software
       without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -->
<!--
 Workflow Schema.

 Created: 13 Aug 2010
 @author <a href="mailto:dwayne@schultz.net">Dwayne Schultz</a>
 @version $Revision: 201 $, $Date: 2009-11-06 15:12:29 -0700 (Fri, 06 Nov 2009) $
-->
<xs:schema targetNamespace="http://net.sf.dropboxmq/xsd/dropboxmq-workflow.xsd"
        xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"
        xmlns="http://net.sf.dropboxmq/xsd/dropboxmq-workflow.xsd"
        xmlns:dwf="http://net.sf.dropboxmq/xsd/dropboxmq-workflow.xsd">

    <xs:simpleType name="name-type">
        <xs:restriction base="xs:token">
            <xs:minLength value="1"/>
            <xs:maxLength value="256"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="nc-name-type">
        <xs:restriction base="xs:NCName">
            <xs:minLength value="1"/>
            <xs:maxLength value="256"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="xpath-type">
        <xs:restriction base="xs:token">
            <xs:minLength value="1"/>
            <xs:maxLength value="4000"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="file-path-type">
        <xs:restriction base="xs:token">
            <xs:minLength value="1"/>
            <xs:maxLength value="4000"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:complexType name="transition-type">
        <xs:attribute name="name" type="name-type"/>
        <xs:attribute name="test" type="xpath-type" use="required"/>
        <xs:attribute name="to-state" type="name-type"/>
        <xs:attribute name="terminate" type="xs:boolean" default="false"/>
        <xs:attribute name="transformer-file-path" type="file-path-type"/>
    </xs:complexType>

    <xs:element name="processor">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="namespace" minOccurs="0" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:attribute name="prefix" type="nc-name-type"/>
                        <xs:attribute name="uri">
                            <xs:simpleType>
                                <xs:restriction base="xs:anyURI">
                                    <xs:minLength value="1"/>
                                    <xs:maxLength value="4000"/>
                                </xs:restriction>
                            </xs:simpleType>
                        </xs:attribute>
                    </xs:complexType>
                </xs:element>
                <xs:element name="process-type" minOccurs="0" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="event-type" maxOccurs="unbounded">
                                <xs:complexType>
                                    <xs:attribute name="name" type="nc-name-type" use="required"/>
                                    <xs:attribute name="test" type="xpath-type" use="required"/>
                                    <xs:attribute name="key" type="xpath-type" use="required"/>
                                    <xs:attribute name="context" type="xpath-type"/>
                                    <xs:attribute name="starting">
                                        <xs:simpleType>
                                            <xs:restriction base="xs:string">
                                                <xs:enumeration value="CanStartNewRun"/>
                                                <xs:enumeration value="MustStartNewRun"/>
                                                <xs:enumeration value="WillNotStartNewRun"/>
                                            </xs:restriction>
                                        </xs:simpleType>
                                    </xs:attribute>
                                    <xs:attribute name="is-broadcast" type="xs:boolean" default="false"/>
                                    <xs:attribute name="will-keep-only-last-broadcast"
                                        type="xs:boolean" default="true"/>
                                    <xs:attribute name="will-ignore-late-message-to-terminated-run"
                                            type="xs:boolean" default="true"/>
                                    <xs:attribute name="error-transformer-file-path" type="file-path-type"/>
                                    <xs:attribute name="parent-key" type="xpath-type"/>
                                    <xs:attribute name="parent-process-type" type="name-type"/>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="initial-state">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="transition" type="transition-type" maxOccurs="unbounded"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="state" minOccurs="0" maxOccurs="unbounded">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="deferred-event-type" minOccurs="0" maxOccurs="unbounded">
                                            <xs:complexType>
                                                <xs:attribute name="name" type="nc-name-type" use="required"/>
                                            </xs:complexType>
                                        </xs:element>
                                        <xs:element name="transition" type="transition-type" maxOccurs="unbounded"/>
                                    </xs:sequence>
                                    <xs:attribute name="name" type="name-type" use="required"/>
                                </xs:complexType>
                                <xs:unique name="deferred-event-type-name">
                                    <xs:selector xpath="dwf:deferred-event-type"/>
                                    <xs:field xpath="@name"/>
                                </xs:unique>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute name="name" type="name-type" use="required"/>
                    </xs:complexType>
                    <xs:unique name="event-type-name">
                        <xs:selector xpath="dwf:event-type"/>
                        <xs:field xpath="@name"/>
                    </xs:unique>
                    <xs:unique name="state-name">
                        <xs:selector xpath="dwf:state"/>
                        <xs:field xpath="@name"/>
                    </xs:unique>
                </xs:element>
            </xs:sequence>
            <xs:attribute name="name" type="name-type" use="required"/>
        </xs:complexType>
        <xs:unique name="namespace-prefix">
            <xs:selector xpath="dwf:namespace"/>
            <xs:field xpath="@prefix"/>
        </xs:unique>
        <xs:unique name="process-type-name">
            <xs:selector xpath="dwf:process-type"/>
            <xs:field xpath="@name"/>
        </xs:unique>
    </xs:element>
</xs:schema>
