<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="../schema2xhtml.xsl" type="text/xsl"?>

<!-- This schema is part of JMRI. Copyright 2009.                           -->
<!--                                                                        -->
<!-- JMRI is free software; you can redistribute it and/or modify it under  -->
<!-- the terms of version 2 of the GNU General Public License as published  -->
<!-- by the Free Software Foundation. See the "COPYING" file for a copy     -->
<!-- of this license.                                                       -->
<!--                                                                        -->
<!-- JMRI is distributed in the hope that it will be useful, but WITHOUT    -->
<!-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or  -->
<!-- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License  -->
<!-- for more details.                                                      -->


<!-- Need annotations                                                 -->
<!-- Attributes need to get types right esp. for enumerated           -->
<!-- Attributes need REQUIRED/IMPLIED                                 -->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:docbook="http://docbook.org/ns/docbook"
           xmlns:jmri="http://jmri.org/xml/schema/JMRIschema"
           xsi:schemaLocation="
                http://jmri.org/xml/schema/JMRIschema http://jmri.org/xml/schema/JMRIschema.xsd
                http://docbook.org/ns/docbook http://jmri.org/xml/schema/docbook/docbook.xsd
            "
        >
    <xs:complexType name="BlockManagerType">
      <xs:annotation>
        <xs:documentation>
          Define the XML structure for storing the contents of a BlockManager implementation.
        </xs:documentation>
        <xs:appinfo>
            <jmri:usingclass configurexml="true">jmri.configurexml.BlockManagerXml</jmri:usingclass>
        </xs:appinfo>
      </xs:annotation>
      <xs:sequence>
        <xs:element name="defaultspeed" minOccurs="0" maxOccurs="1" />
        <xs:element name="block" minOccurs="0" maxOccurs="unbounded">
          <xs:complexType>
            <!-- The following is really ugly duplication caused by writing some elements out of order, and should be fixed by
                     1) Moving to XML Schema 1.1
                     2) Then converting the "sequence" element in NamedBeanType into an "all" element
                     3) Then having this "sensor" element extend from NamedBeanType
                    The problem is that (a) XML Schema 1.0 "all" elements can't be extended, but
                    (b) we want to insert something _inside_ the order of elements in NamedBeanType.
                    So we recreate those here.  (The code in SensorManager has had the order fixed in 4.7.7
                    but old files still exist)
                    -->
            <xs:sequence maxOccurs="unbounded">
              <xs:element name="systemName" type="systemNameType" minOccurs="1" maxOccurs="1"/>
              <xs:element name="userName" type="userNameType" minOccurs="0" maxOccurs="1"/>
              <xs:element name="comment" type="commentType" minOccurs="0" maxOccurs="1" />
              <xs:element name="properties" minOccurs="0" maxOccurs="1">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="property" minOccurs="1" maxOccurs="unbounded">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="key" minOccurs="1" maxOccurs="1">
                            <xs:complexType>
                              <xs:simpleContent>
                                <xs:extension base="xs:string">
                                  <xs:attribute name="class" type="classType" use="optional" />
                                </xs:extension>
                              </xs:simpleContent>
                            </xs:complexType>
                          </xs:element>
                          <xs:element name="value" minOccurs="0" maxOccurs="1">
                            <xs:complexType>
                              <xs:simpleContent>
                                <xs:extension base="xs:string">
                                  <xs:attribute name="class" type="classType" use="required" />
                                </xs:extension>
                              </xs:simpleContent>
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <!-- end of ugly duplication -->
              <xs:element name="speed" minOccurs="0" maxOccurs="1" />
              <xs:element name="permissive" minOccurs="0" maxOccurs="1" />
              <xs:element name="occupancysensor" type="beanNameType" minOccurs="0" maxOccurs="1" />
              <xs:element name="sensor" minOccurs="0" maxOccurs="1" >
                <xs:complexType>
                  <xs:attribute name="systemName" type="beanNameType" /><!-- This will now store either a user or system name -->
                </xs:complexType>
              </xs:element>
              <xs:element name="reporter" minOccurs="0" maxOccurs="1" >
                <xs:complexType>
                <xs:attribute name="systemName" type="systemNameType" />
                <xs:attribute name="useCurrent" type="yesNoType" />
                </xs:complexType>
              </xs:element>
              <xs:element name="deniedBlocks" minOccurs="0" maxOccurs="1" >
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="block" type="beanNameType" minOccurs="1" maxOccurs="unbounded" />
                    </xs:sequence>
                </xs:complexType>
              </xs:element>
              
              <xs:element name="path" minOccurs="0" maxOccurs="unbounded" >
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="beansetting" minOccurs="0" maxOccurs="unbounded" >
                            <xs:complexType>
                                <xs:sequence>
                                     <xs:element name="turnout" minOccurs="0" maxOccurs="unbounded" >
                                        <xs:complexType>
                                           <xs:attribute name="systemName" type="beanNameType" /> <!-- This will now store either a user or system name -->
                                        </xs:complexType>
                                    </xs:element >
                               </xs:sequence>
                              <xs:attribute name="setting" type="xs:integer" />
                            </xs:complexType>
                        </xs:element >
                    </xs:sequence>
                  <xs:attribute name="todir" type="xs:integer" />
                  <xs:attribute name="fromdir" type="xs:integer" />
                  <xs:attribute name="block" type="xs:string" />
                </xs:complexType>
              </xs:element>
            </xs:sequence> <!-- secretly still part of ugly duplication due to "unbounded" -->
            <xs:attribute name="systemName" type="systemNameType">
                <xs:annotation><xs:documentation>Deprecated 2.9.6 in favor of separate element</xs:documentation></xs:annotation>
            </xs:attribute>
            <xs:attribute name="userName" type="userNameType">
                <xs:annotation><xs:documentation>Deprecated 2.9.6 in favor of separate element</xs:documentation></xs:annotation>
            </xs:attribute>
            <xs:attribute name="length" type="xs:float" />
            <xs:attribute name="curve" type="xs:integer" />
          </xs:complexType>
        </xs:element>
            
      </xs:sequence>
      <xs:attribute name="class" type="classType" use="required"/>
    </xs:complexType>

</xs:schema>
