<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~ 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.1"
           xmlns="urn:jboss:domain:ejb3:1.1"
           elementFormDefault="qualified"
           attributeFormDefault="unqualified"
           version="1.1">

    <!-- 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="mdb" type="mdbType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="session-bean" type="session-beanType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="pools" type="poolsType" minOccurs="0" maxOccurs="1"/>
            <xs:element name="timer-service" type="timerServiceType" minOccurs="0" maxOccurs="1"/>
        </xs:all>
        <xs:attribute name="lite" type="xs:boolean" use="optional"/>
    </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="session-beanType">
        <xs:all>
            <xs:element name="stateless" type="stateless-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="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="HOURS"/>
            <xs:enumeration value="MINUTES"/>
            <xs:enumeration value="SECONDS"/>
            <xs:enumeration value="MILLISECONDS"/>
        </xs:restriction>
    </xs:simpleType>

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

    <xs:complexType name="threadPoolType">
        <xs:attribute name="core-threads" type="xs:int">
            <xs:annotation>
                <xs:documentation>
                    The number of threads that the the thread pool will keep alive. Defaults to 0.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="max-threads" type="xs:int">
            <xs:annotation>
                <xs:documentation>
                    The maximum number of threads that will be used to run timer service tasks. Defaults to the
                    number of processes as returned by Runtime.availableProcessors()
                </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>
