<!--
  ~ JBoss, Home of Professional Open Source.
  ~ Copyright 2011, Red Hat, Inc., and individual contributors
  ~ as indicated by the @author tags. See the copyright.txt file in the
  ~ distribution for a full listing of individual contributors.
  ~
  ~ This is free software; you can redistribute it and/or modify it
  ~ under the terms of the GNU Lesser General Public License as
  ~ published by the Free Software Foundation; either version 2.1 of
  ~ the License, or (at your option) any later version.
  ~
  ~ This software 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
  ~ Lesser General Public License for more details.
  ~
  ~ You should have received a copy of the GNU Lesser General Public
  ~ License along with this software; if not, write to the Free
  ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  -->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="urn:jboss:domain:ejb3:1.2"
           xmlns="urn:jboss:domain:ejb3:1.2"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified"
           version="1.2">

    <!-- The ejb3 subsystem root element -->
    <xs:element name="subsystem" type="ejb3-subsystemType"/>

    <xs:complexType name="ejb3-subsystemType">
        <xs:annotation>
            <xs:documentation>
                EJB3 subsystem configurations
            </xs:documentation>
        </xs:annotation>
        <xs:all>
            <xs:element name="session-bean" type="session-beanType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="mdb" type="mdbType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="pools" type="poolsType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="async" type="asyncType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="timer-service" type="timerServiceType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="remote" type="remoteType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="thread-pools" type="threadPoolsType" minOccurs="0" maxOccurs="1"/>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="mdbType">
        <xs:all>
            <xs:element name="resource-adapter-ref" type="resource-adapter-refType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="bean-instance-pool-ref" type="bean-instance-pool-refType" minOccurs="0" maxOccurs="1"/>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="remoteType">
        <xs:attribute name="connector-ref" type="xs:string" use="required"/>
        <xs:attribute name="thread-pool-name" type="xs:token" use="required"/>
    </xs:complexType>

    <xs:complexType name="asyncType">
        <xs:attribute name="thread-pool-name" type="xs:token" use="required"/>
    </xs:complexType>

    <xs:complexType name="session-beanType">
        <xs:all>
            <xs:element name="stateless" type="stateless-beanType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="stateful" type="stateful-beanType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="singleton" type="singleton-beanType" minOccurs="0" maxOccurs="1"/>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="stateless-beanType">
        <xs:all>
            <xs:element name="bean-instance-pool-ref" type="bean-instance-pool-refType" minOccurs="0" maxOccurs="1"/>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="stateful-beanType">
        <xs:attribute name="default-access-timeout" type="xs:positiveInteger" default="5000" use="optional">
            <xs:annotation>
                <xs:documentation>
                    The default access timeout, for stateful session beans, in milliseconds
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="singleton-beanType">
        <xs:attribute name="default-access-timeout" type="xs:positiveInteger" default="5000" use="optional">
            <xs:annotation>
                <xs:documentation>
                    The default access timeout, for singleton beans, in milliseconds
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="resource-adapter-refType">
        <xs:attribute name="resource-adapter-name" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="bean-instance-pool-refType">
        <xs:attribute name="pool-name" use="required" type="xs:string"/>
    </xs:complexType>

    <xs:complexType name="poolsType">
        <xs:all>
            <xs:element name="bean-instance-pools" type="bean-instance-poolsType" minOccurs="0" maxOccurs="1"/>
        </xs:all>
    </xs:complexType>

    <xs:complexType name="bean-instance-poolsType">
        <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element name="strict-max-pool" type="strict-max-poolType"/>
        </xs:choice>
    </xs:complexType>

    <xs:complexType name="strict-max-poolType">
        <xs:attribute name="name" type="xs:string" use="required"/>
        <xs:attribute name="max-pool-size" type="xs:positiveInteger" default="20" use="optional"/>
        <xs:attribute name="instance-acquisition-timeout" type="xs:positiveInteger" default="5" use="optional"/>
        <xs:attribute name="instance-acquisition-timeout-unit" type="instance-acquisition-timeout-unitType"
                      default="MINUTES" use="optional"/>
    </xs:complexType>

    <xs:simpleType name="instance-acquisition-timeout-unitType">
        <xs:annotation>
            <xs:documentation>
                TimeUnit that are allowed for instance-acquisition-timeout on a pool
            </xs:documentation>
        </xs:annotation>
        <xs:restriction base="xs:token">
            <xs:enumeration value="DAYS"/>
            <xs:enumeration value="HOURS"/>
            <xs:enumeration value="MINUTES"/>
            <xs:enumeration value="SECONDS"/>
            <xs:enumeration value="MILLISECONDS"/>
            <xs:enumeration value="MICROSECONDS"/>
            <xs:enumeration value="NANOSECONDS"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="timerServiceType">
        <xs:sequence>
            <xs:element name="data-store" type="dataStoreType" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
        <xs:attribute name="thread-pool-name" type="xs:token" use="required"/>
    </xs:complexType>

    <xs:complexType name="threadPoolsType">
        <xs:sequence>
            <xs:element name="thread-pool" type="threadPoolType" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="threadPoolType">
        <xs:attribute name="name" type="xs:token" use="required">
            <xs:annotation>
                <xs:documentation>
                    The name of this thread pool
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="max-threads" type="xs:int">
            <xs:annotation>
                <xs:documentation>
                    The maximum number of threads in the thread pool. Defaults to the number of CPU cores.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="keepalive-time" type="xs:int">
            <xs:annotation>
                <xs:documentation>
                    The time in milliseconds that a thread with nothing to do will stay around for.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="dataStoreType">
        <xs:attribute name="path" type="xs:string"/>
        <xs:attribute name="relative-to" type="xs:string"/>
    </xs:complexType>

</xs:schema>
