<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.bea.com/ns/wlevs/config/application" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:base="http://www.bea.com/ns/wlevs/config" xmlns:eventstore="http://www.bea.com/ns/wlevs/config/eventstore" targetNamespace="http://www.bea.com/ns/wlevs/config/application" elementFormDefault="unqualified" attributeFormDefault="unqualified" jxb:extensionBindingPrefixes="xjc" jxb:version="2.0">
    <xs:annotation>
        <xs:appinfo>
            <jxb:schemaBindings>
                <jxb:package name="com.bea.wlevs.configuration.application"/>
            </jxb:schemaBindings>
        </xs:appinfo>
    </xs:annotation>
    <xs:import namespace="http://www.bea.com/ns/wlevs/config" schemaLocation="wlevs_base_config.xsd"/>
    <xs:import namespace="http://www.bea.com/ns/wlevs/config/eventstore" schemaLocation="wlevs_eventstore_config.xsd"/>
    <xs:element name="config">
        <xs:complexType>
            <xs:sequence>
                <xs:choice maxOccurs="unbounded">
                    <xs:element name="adapter" type="DefaultAdapterConfig"/>
                    <xs:element name="http-pub-sub-adapter" type="HttpPubSubAdapterConfig"/>
                    <xs:element name="jms-adapter" type="JMSAdapterConfig"/>
                    <xs:element name="processor" type="DefaultProcessorConfig"/>
                    <xs:element name="stream" type="DefaultStreamConfig"/>
                    <xs:element name="event-bean" type="EventBeanConfig"/>
                    <xs:element name="caching-system" type="CachingSystemConfig"/>
                </xs:choice>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="StageConfig">
        <xs:complexContent>
            <xs:extension base="base:ConfigurationObject">
                <xs:sequence>
                    <xs:element name="record-parameters" type="eventstore:RecordParameters" minOccurs="0"/>
                    <xs:element name="playback-parameters" type="eventstore:PlaybackParameters" minOccurs="0"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="AdapterConfig">
        <xs:complexContent>
            <xs:extension base="StageConfig"/>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="ProcessorConfig">
        <xs:complexContent>
            <xs:extension base="StageConfig"/>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="StreamConfig">
        <xs:complexContent>
            <xs:extension base="StageConfig"/>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="EventBeanConfig">
        <xs:complexContent>
            <xs:extension base="StageConfig"/>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="DefaultProcessorConfig">
        <xs:complexContent>
            <xs:extension base="ProcessorConfig">
                <xs:sequence>
                    <xs:element name="rules" type="Rules"/>
                    <xs:element name="database" type="DatabaseReference" minOccurs="0" maxOccurs="unbounded"/>
                    <xs:element name="bindings" type="BindingsType" minOccurs="0"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="DatabaseReference">
        <xs:attribute name="name" type="xs:string" use="required"/>
        <xs:attribute name="data-source-name" type="xs:string" use="required"/>
    </xs:complexType>
    <xs:complexType name="Rules">
        <xs:sequence>
            <xs:element name="rule" type="Rule" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Rule">
        <xs:annotation>
            <xs:documentation>Using xs:NCName instead of xs:ID for id attribute because validation fails when the same rule name is used for different processors(CR368059)</xs:documentation>
        </xs:annotation>
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="id" type="xs:NCName" use="required"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <xs:complexType name="DefaultAdapterConfig">
        <xs:complexContent>
            <xs:extension base="AdapterConfig">
                <xs:sequence>
                    <!--  symbols element is DEPRECATED in WLEVS 3.0 -->
                    <xs:element name="symbols" type="Symbols" minOccurs="0"/>
                    <xs:element name="work-manager-name" type="xs:string" minOccurs="0"/>
                    <xs:element name="netio" type="NetioType" minOccurs="0"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="HttpPubSubAdapterConfig">
        <xs:complexContent>
            <xs:extension base="DefaultAdapterConfig">
                <xs:sequence>
                    <xs:choice>
                        <xs:element name="server-context-path" type="xs:string"/>
                        <xs:element name="server-url" type="xs:string"/>
                    </xs:choice>
                    <xs:element name="channel" type="xs:string"/>
                    <xs:element name="event-type" type="xs:string" minOccurs="0"/>
                    <xs:element name="user" type="xs:string" minOccurs="0"/>
                    <xs:choice minOccurs="0">
                        <xs:element name="password" type="xs:string"/>
                        <xs:element name="encrypted-password" type="xs:string"/>
                    </xs:choice>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="JMSAdapterConfig">
        <xs:complexContent>
            <xs:extension base="AdapterConfig">
                <xs:sequence>
                    <xs:element name="event-type" type="xs:string" minOccurs="0"/>
                    <xs:element name="jndi-provider-url" type="xs:string"/>
                    <xs:element name="jndi-factory" type="xs:string" minOccurs="0"/>
                    <xs:element name="connection-jndi-name" type="xs:string" minOccurs="0"/>
                    <xs:choice>
                        <xs:element name="destination-jndi-name" type="xs:string"/>
                        <xs:element name="destination-name" type="xs:string"/>
                    </xs:choice>
                    <xs:element name="user" type="xs:string" minOccurs="0"/>
                    <xs:choice minOccurs="0">
                        <xs:element name="password" type="xs:string"/>
                        <xs:element name="encrypted-password" type="xs:string"/>
                    </xs:choice>
                    <xs:element name="work-manager" type="xs:string" minOccurs="0"/>
                    <xs:element name="concurrent-consumers" type="xs:int" minOccurs="0"/>
                    <xs:element name="message-selector" type="xs:string" minOccurs="0"/>
                    <xs:element name="session-ack-mode-name" type="xs:string" minOccurs="0"/>
                    <xs:element name="session-transacted" type="xs:boolean" minOccurs="0"/>
                    <xs:element name="delivery-mode" type="xs:string" minOccurs="0"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

        <!--  symbols element is DEPRECATED in WLEVS 3.0 -->
    <xs:complexType name="Symbols">
        <xs:sequence>
            <xs:element name="symbol" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="NetioType">
        <xs:sequence>
            <xs:element name="provider-name" type="xs:string"/>
            <xs:element name="num-threads" type="xs:int"/>
            <xs:element name="accept-backlog" type="xs:int"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="DefaultStreamConfig">
        <xs:complexContent>
            <xs:extension base="StreamConfig">
                <xs:sequence>
                    <xs:element name="max-size" type="xs:int" default="1024" minOccurs="0"/>
                    <xs:element name="max-threads" type="xs:int" default="1" minOccurs="0"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="CachingSystemConfig">
        <xs:complexContent>
            <xs:extension base="base:ConfigurationObject">
                <xs:sequence>
                    <xs:element name="cache" type="CacheConfig" minOccurs="0" maxOccurs="unbounded"/>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
        <xs:complexType name="CacheConfig">
        <xs:complexContent>
            <xs:extension base="base:ConfigurationObject">
                <xs:sequence>
                    <xs:element name="max-size" type="xs:long" minOccurs="0"
                        default="64">
                        <xs:annotation>
                            <xs:documentation><![CDATA[
    The number of cache elements in memory after which eviction/paging occurs. Currently,
    the maximum cache size is 2^31-1 entries.  This element may be changed dynamically.
                 ]]></xs:documentation>
                        </xs:annotation>
                    </xs:element>
                    <xs:element name="eviction-policy" type="xs:string"
                        minOccurs="0" default="LFU">
                        <xs:annotation>
                            <xs:documentation><![CDATA[
    The eviction policy to use when max-size is reached.  Supported values are: FIFO, LRU, 
    LFU, and NRU.  This element does not support dynamic updates.
                 ]]></xs:documentation>
                        </xs:annotation>
                    </xs:element>
                    <xs:element name="time-to-live" type="xs:long" minOccurs="0"
                        default="0">
                        <xs:annotation>
                            <xs:documentation><![CDATA[
    The maximum amount of time that an entry is cached. By default the time to live is infinite.
    This element may be changed dynamically.
                 ]]></xs:documentation>
                        </xs:annotation>
                    </xs:element>
                    <xs:element name="idle-time" type="xs:long" minOccurs="0"
                        default="0">
                        <xs:annotation>
                            <xs:documentation><![CDATA[
    Cache entries that have not been accessed for idle-time milliseconds are actively removed 
    from the cache. By default, there is no idle-time set.  This element may be changed dynamically.
                 ]]></xs:documentation>
                        </xs:annotation>
                    </xs:element>
                    <xs:choice minOccurs="0">
                        <xs:element name="write-none"
                            type="WriteNoneType">
                            <xs:annotation>
                                <xs:documentation><![CDATA[
    Specifies no writes to a cache store.  This is the default write policy.  This element may be changed dynamically.
                 ]]></xs:documentation>
                            </xs:annotation>
                        </xs:element>
                        
                        <xs:element name="write-through"
                            type="WriteThroughType">
                            <xs:annotation>
                                <xs:documentation><![CDATA[
    Specifies synchronous writes to the cache store.  As soon as an entry is created or updated the 
    write occurs. This element may be changed dynamically.
                 ]]></xs:documentation>
                            </xs:annotation>
                        </xs:element>

                        <xs:element name="write-behind"
                            type="WriteBehindType">
                            <xs:annotation>
                                <xs:documentation><![CDATA[
    Specifies asynchronous writes to the cache store. The cache store is invoked from a separate thread 
    after a create or update of a cache entry.  This element may be changed dynamically.
                 ]]></xs:documentation>
                            </xs:annotation>
                        </xs:element>
                    </xs:choice>
                    <xs:element name="work-manager-name" type="xs:string"
                        minOccurs="0">
                        <xs:annotation>
                            <xs:documentation><![CDATA[
   The work manager to be used for all asynchronous operations.  The work manager must be configured
   in the server config.xml configuration file.  This element does not support dynamic updates.
                 ]]></xs:documentation>
                        </xs:annotation>
                    </xs:element>
                    <xs:element name="listeners" type="ListenersType"
                        minOccurs="0">
                        <xs:annotation>
                            <xs:documentation><![CDATA[
    Specifies the behavior of cache listeners. 
                 ]]></xs:documentation>
                        </xs:annotation>
                    </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="ListenersType">
        <xs:sequence>
            <xs:element name="work-manager-name" type="xs:string"
                minOccurs="0">
                <xs:annotation>
                    <xs:documentation><![CDATA[
    The work manager to be used for asynchronously invoking listeners.  Ignored if synchronous 
    writes are in effect.  Overrides the cache's work manager for listener operations if a 
    cache-level work manager is also specified.  This element may be changed dynamically.
                 ]]></xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="asynchronous" type="xs:boolean" use="optional"
            default="false">
            <xs:annotation>
                <xs:documentation><![CDATA[
    Invoke listeners asynchronously.  By default, listeners are invoked synchronously. 
    This element may be changed dynamically.
                 ]]></xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="WriteNoneType"></xs:complexType>

    <xs:complexType name="WriteThroughType"></xs:complexType>

    <xs:complexType name="WriteBehindType">
        <xs:sequence>
            <xs:element name="work-manager-name" type="xs:string" minOccurs="0">
                <xs:annotation>
                    <xs:documentation><![CDATA[
    The work manager to be used for asynchronously invoking the cache store.  Overrides 
    the cache's work manager for store operations if a cache-level work manager is 
    also specified.  This element may be changed dynamically.
                 ]]></xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="batch-size" type="xs:int" minOccurs="0"
                default="1">
                <xs:annotation>
                    <xs:documentation><![CDATA[
    The number of updates that are picked up from the store buffer to write back to the backing store.
    This element may be changed dynamically.
                 ]]></xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="buffer-size" type="xs:int" minOccurs="0"
                default="100">
                <xs:annotation>
                    <xs:documentation><![CDATA[
    The size of the internal store buffer that's used to temporarily hold asynchronous updates that 
    need to be written to the store.  Does not support dynamic updates.
                 ]]></xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="buffer-write-attempts" type="xs:int" minOccurs="0"
                default="1">
                <xs:annotation>
                    <xs:documentation><![CDATA[
    The number of attempts that the user thread will make to write to the store buffer.  The user 
    thread is the thread that creates or updates a cache entry.  If the user thread cannot write
    to the store buffer (all write attempts fail), it will invoke the store synchronously.  This
    element may be changed dynamically.
                 ]]></xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="buffer-write-timeout" type="xs:long" minOccurs="0"
                default="100">
                <xs:annotation>
                    <xs:documentation><![CDATA[
    The time in milliseconds that the user thread will wait before aborting an attempt to write to the 
    store buffer. The attempt to write to the store buffer fails only in case the buffer is full. After 
    the timeout, futher attempts may be made to write to the buffer based on the value of 
    buffer-write-attempts.  This element may be changed dynamically.
                 ]]></xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="BindingsType">
        <xs:sequence>
            <xs:element name="binding" type="BindingEntryType" minOccurs="0" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="BindingEntryType">
        <xs:annotation>
            <xs:documentation>Using xs:NCName instead of xs:ID for id attribute because validation fails due to multiple occurrence of an id value for rule and binding elements (which seems wrong because they are different elements)</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="params" type="Params" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="id" type="xs:NCName" use="required"/>
    </xs:complexType>
    <xs:complexType name="Params">
        <xs:annotation>
            <xs:documentation>Using xs:NCName instead of xs:ID for id attribute because the value must only be unique across siblings as opposed to across the entire document</xs:documentation>
        </xs:annotation>
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="id" type="xs:NCName" use="optional"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
</xs:schema>

