<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:envelope_1_0="http://agavi.org/agavi/config/global/envelope/1.0"
    xmlns:types_1_0="http://agavi.org/agavi/config/global/types/1.0"
    xmlns="http://icinga.org/appkit/config/parts/routing/1.0"
    targetNamespace="http://icinga.org/appkit/config/parts/routing/1.0"
    elementFormDefault="qualified"
    version="$Id: routing.xsd 4502 2010-04-23 13:39:31Z david $">

    <xs:import namespace="http://agavi.org/agavi/config/global/types/1.0"
               schemaLocation="../../../../../../../lib/agavi/src/config/xsd/_types.xsd" />
    <xs:import namespace="http://agavi.org/agavi/config/global/envelope/1.0"
               schemaLocation="../../../../../../../lib/agavi/src/config/xsd/_envelope.xsd" />

    <xs:simpleType name="route_name">
        <xs:restriction base="xs:string">
            <xs:pattern value="[^\+\-]+" />
        </xs:restriction>
    </xs:simpleType>

    <xs:group name="ignores">
        <xs:choice>
            <xs:element name="ignores" minOccurs="0">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="ignore" type="xs:string"
                                    maxOccurs="unbounded" />
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="ignore" type="xs:string"
                        maxOccurs="unbounded" />
        </xs:choice>
    </xs:group>

    <xs:element name="default">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string">
                    <xs:attribute name="for" type="xs:string" use="required" />
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>

    <xs:group name="defaults">
        <xs:choice>
            <xs:element name="defaults" minOccurs="0">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element ref="default"
                                    maxOccurs="unbounded" />
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element ref="default"
                        minOccurs="0" maxOccurs="unbounded" />
        </xs:choice>
    </xs:group>

    <xs:complexType name="callback">
        <xs:sequence>
            <xs:group ref="envelope_1_0:parameters" />
        </xs:sequence>
        <xs:attribute name="class" type="types_1_0:php_class" />
    </xs:complexType>
    
    <xs:complexType name="callbacks">
        <xs:sequence>
            <xs:element name="callback" type="callback" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>

    <xs:group name="callbacks">
        <xs:choice>
            <xs:element name="callbacks" type="callbacks"
                        minOccurs="0" />
            <xs:element name="callback" type="callback"
                        minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
    </xs:group>

    <!-- Routes -->

    <xs:complexType name="route">
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <!-- Parameters should be explicitly allowed in routes, but if we include
                 them in the schema it becomes non-deterministic according to libxml.
                 They are queried by the internal handler, though. -->
            <xs:any namespace="##other" processContents="lax"
                    minOccurs="0" maxOccurs="unbounded" />
            <xs:group ref="ignores" />
            <xs:group ref="defaults" />
            <xs:group ref="routes" />
            <xs:group ref="callbacks" />
        </xs:sequence>
        <xs:attribute name="name" type="route_name" />
        <xs:attribute name="pattern" type="xs:string" use="required" />
        <xs:attribute name="imply" type="xs:string" />
        <xs:attribute name="cut" type="xs:string" />
        <xs:attribute name="stop" type="xs:string" />
        <xs:attribute name="source" type="xs:string" />
        <xs:attribute name="constraint" type="xs:string" />

        <!-- Values to be set on match -->
        <xs:attribute name="action" type="xs:string" />
        <xs:attribute name="locale" type="xs:string" />
        <xs:attribute name="method" type="xs:string" />
        <xs:attribute name="module" type="xs:string" />
        <xs:attribute name="output_type" type="xs:string" />
        <xs:attribute name="api_provider" type="xs:boolean" />
    </xs:complexType>

    <xs:complexType name="routes">
        <xs:sequence>
            <xs:element name="route" type="route" maxOccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>

    <xs:group name="routes">
        <xs:choice>
            <xs:element name="routes" type="routes"
                        minOccurs="0" />
            <xs:element name="route" type="route"
                        minOccurs="0" maxOccurs="unbounded"/>
        </xs:choice>
    </xs:group>

    <xs:group name="configuration">
        <xs:sequence>
            <xs:any namespace="##other" processContents="lax"
                    minOccurs="0" maxOccurs="unbounded" />
            <xs:group ref="routes" />
        </xs:sequence>
    </xs:group>

</xs:schema>
