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

<!--
  ~ Copyright The WildFly Authors
  ~ SPDX-License-Identifier: Apache-2.0
  -->

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

    <xs:complexType name="deployment">
        <xs:sequence>
            <xs:element name="bean" type="bean" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="bean">
        <xs:sequence>
            <xs:element name="alias" type="alias" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="classloader" type="classloader" minOccurs="0" maxOccurs="1"/>
            <xs:element name="constructor" type="constructor" minOccurs="0" maxOccurs="1"/>
            <xs:element name="property" type="property" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="create" type="lifecycle" minOccurs="0" maxOccurs="1"/>
            <xs:element name="start" type="lifecycle" minOccurs="0" maxOccurs="1"/>
            <xs:element name="stop" type="lifecycle" minOccurs="0" maxOccurs="1"/>
            <xs:element name="destroy" type="lifecycle" minOccurs="0" maxOccurs="1"/>
            <xs:element name="install" type="install" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="uninstall" type="install" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="incallback" type="callback" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="uncallback" type="callback" minOccurs="0" maxOccurs="unbounded"/>
            <xs:element name="depends" type="depends" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="name" type="xs:string" use="required"/>
        <xs:attribute name="class" type="xs:string" use="optional"/>
        <xs:attribute name="mode" type="mode" use="optional"/>
    </xs:complexType>

    <xs:complexType name="alias" mixed="true" />

    <xs:complexType name="classloader">
        <xs:attribute name="name" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="constructor">
        <xs:sequence>
            <xs:element name="factory" type="parameter" minOccurs="0" maxOccurs="1"/>
            <xs:element name="parameter" type="parameter" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="factory-class" type="xs:string" use="optional"/>
        <xs:attribute name="factory-method" type="xs:string" use="optional"/>
    </xs:complexType>

    <xs:simpleType name="mode">
        <xs:restriction base="xs:token">
            <xs:enumeration value="active"/>
            <xs:enumeration value="passive"/>
            <xs:enumeration value="on demand"/>
            <xs:enumeration value="never"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="property">
        <xs:choice minOccurs="0" maxOccurs="1">
            <xs:element name="value" type="value"/>
            <xs:element name="inject" type="inject"/>
            <xs:element name="value-factory" type="value-factory"/>
            <xs:element name="list" type="collection"/>
            <xs:element name="set" type="collection"/>
            <xs:element name="map" type="map"/>
        </xs:choice>
        <xs:attribute name="name" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="depends">
        <xs:attribute name="state" type="xs:string" use="optional"/>
    </xs:complexType>

    <xs:complexType name="inject">
        <xs:attribute name="bean" type="xs:string" use="optional"/>
        <xs:attribute name="service" type="xs:string" use="optional"/>
        <xs:attribute name="property" type="xs:string" use="optional"/>
    </xs:complexType>

    <xs:complexType name="value-factory">
        <xs:sequence>
            <xs:element name="parameter" type="parameter" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="bean" type="xs:string" use="required"/>
        <xs:attribute name="method" type="xs:string" use="required"/>
    </xs:complexType>

    <xs:complexType name="collection">
        <xs:sequence>
            <xs:element name="value" type="value"/>
            <xs:element name="inject" type="inject"/>
            <xs:element name="value-factory" type="value-factory"/>
            <xs:element name="list" type="collection"/>
            <xs:element name="set" type="collection"/>
            <xs:element name="map" type="map"/>
        </xs:sequence>
        <xs:attribute name="class" type="xs:string" use="optional"/>
        <xs:attribute name="elementClass" type="xs:string" use="optional"/>
    </xs:complexType>

    <xs:complexType name="map">
        <xs:sequence>
            <xs:element name="entry" type="entry"/>
        </xs:sequence>
        <xs:attribute name="class" type="xs:string" use="optional"/>
        <xs:attribute name="keyClass" type="xs:string" use="optional"/>
        <xs:attribute name="valueClass" type="xs:string" use="optional"/>
    </xs:complexType>

    <xs:complexType name="entry">
        <xs:sequence>
            <xs:element name="key" type="value-value"/>
            <xs:element name="value" type="value-value"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="value-value" mixed="true">
        <xs:sequence>
            <xs:element name="value" type="value"/>
            <xs:element name="inject" type="inject"/>
            <xs:element name="value-factory" type="value-factory"/>
            <xs:element name="list" type="collection"/>
            <xs:element name="set" type="collection"/>
            <xs:element name="map" type="map"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="lifecycle">
        <xs:sequence>
            <xs:element name="parameter" type="parameter" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="method" type="xs:string" use="optional"/>
    </xs:complexType>

    <xs:complexType name="install">
        <xs:sequence>
            <xs:element name="parameter" type="parameter" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="bean" type="xs:string" use="optional"/>
        <xs:attribute name="method" type="xs:string" use="required"/>
        <xs:attribute name="whenRequired" type="xs:string" use="optional"/>
        <xs:attribute name="state" type="xs:string" use="optional"/>
    </xs:complexType>

    <xs:complexType name="callback">
        <xs:attribute name="method" type="xs:string" use="required"/>
        <xs:attribute name="whenRequired" type="xs:string" use="optional"/>
        <xs:attribute name="state" type="xs:string" use="optional"/>
        <xs:attribute name="signature" type="xs:string" use="optional"/>
    </xs:complexType>

    <xs:complexType name="value" mixed="true">
        <xs:attribute name="replace" type="xs:boolean" use="optional"/>
        <xs:attribute name="trim" type="xs:boolean" use="optional"/>
    </xs:complexType>

    <xs:complexType name="parameter" mixed="true">
        <xs:sequence>
            <xs:element name="value" type="value" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
        <xs:attribute name="class" type="xs:string" use="optional"/>
    </xs:complexType>

    <!-- Root elements -->

    <xs:element name="deployment" type="deployment"/>
</xs:schema>
