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

    Copyright 2004 The Apache Software Foundation

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<xs:schema
        targetNamespace="http://geronimo.apache.org/xml/ns/plugins/quartz-0.2"
        xmlns:job="http://geronimo.apache.org/xml/ns/plugins/quartz-0.2"
        xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        elementFormDefault="qualified"
        attributeFormDefault="unqualified"
        >

    <xs:annotation>
        <xs:documentation>
            Schema for a Quartz scheduled job.
        </xs:documentation>
    </xs:annotation>

    <xs:import namespace="http://geronimo.apache.org/xml/ns/deployment-1.1" schemaLocation="geronimo-module-1.1.xsd"/>

    <!--   Top-level elements   -->

    <xs:element name="jobs" type="job:jobsType">
        <xs:annotation>
            <xs:documentation>
                A list of jobs to schedule with Quartz
            </xs:documentation>
        </xs:annotation>
    </xs:element>

    <xs:complexType name="jobsType">
        <xs:sequence>
            <xs:element ref="sys:environment"/>
            <xs:element name="job" type="job:jobType" minOccurs="1" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>
                        A job to schedule with Quartz
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="jobType">
        <xs:sequence>
            <xs:element name="job-name" type="xs:string">
                <xs:annotation>
                    <xs:documentation>
                        A unique name used to identify the Quartz job
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="job-class" type="xs:string">
                <xs:annotation>
                    <xs:documentation>
                        The fully-qualified class name of the Quartz job
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:choice>
                <xs:element name="cron-expression" type="xs:string">
                    <xs:annotation>
                        <xs:documentation>
                            A CRON-formatted expression for when the job should run
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
            </xs:choice>
            <xs:element name="ejb-ref" type="job:ejbRefType" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>
                        Configures an EJB reference that will be set on the job instance
                        via dependency injection.  That is, you specify a property name
                        and an EJB, and the setter for that property will be called with
                        the EJB Local Home interface (and must take a parameter of the
                        same type as the EJB Local Home interface).

                        WARNING: Does not work in Geronimo 1.1: wait until 1.1.1
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="resource-ref" type="job:resourceRefType" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>
                        Configures a resource reference that will be set on the job instance
                        via dependency injection.  That is, you specify a property name
                        and a database pool or JMS connection factory, and the setter for that
                        property will be called with the resource's interface (and must take a
                        parameter of the same type as the res-type interface).
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="gbean-ref" type="job:gbeanRefType" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>
                        Configures a GBean reference that will be set on the job instance
                        via dependency injection.  That is, you specify a property name
                        and a GBean interface and name pattern, and the setter for that
                        property will be called with the GBean's interface (and must take a
                        parameter of the same type as at least one of the GBean interfaces).
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="ejbRefType">
        <xs:sequence>
            <xs:element name="property" type="xs:string">
                <xs:annotation>
                    <xs:documentation>
                        The name of the property on the job that this EJB
                        reference should be injected into.  There must be a
                        setter with the right name for the property (e.g.
                        if the property is foo or Foo, there must be a setter
                        setFoo that takes an argument whose type is the local
                        home interface of the EJB).
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="ejb-type" type="xs:string">
                <xs:annotation>
                    <xs:documentation>
                        Should be set to "Session" or "Entity".
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="local-home" type="xs:string">
                <xs:annotation>
                    <xs:documentation>
                        The fully-qualified Java class name of the EJB's local
                        home interface.  The property that this will be injected
                        into should have this type.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="local" type="xs:string">
                <xs:annotation>
                    <xs:documentation>
                        The fully-qualified Java class name of the EJB's local
                        interface.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="pattern" type="job:patternType">
                <xs:annotation>
                    <xs:documentation>
                        Identifies the EJB within the server that this reference
                        points to.  Normally only the "name" child element is
                        necessary.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="resourceRefType">
        <xs:sequence>
            <xs:element name="property" type="xs:string">
                <xs:annotation>
                    <xs:documentation>
                        The name of the property on the job that this resource
                        reference should be injected into.  There must be a
                        setter with the right name for the property (e.g.
                        if the property is foo or Foo, there must be a setter
                        setFoo that takes an argument of the correct type).
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="res-type" type="xs:string">
                <xs:annotation>
                    <xs:documentation>
                        The fully-qualified Java class name of the interface that
                        the resource implements.  Normally this is one of:
                              javax.sql.DataSource
                              javax.jms.ConnectionFactory
                              javax.jms.QueueConnectionFactory
                              javax.jms.TopicConnectionFactory
                              javax.mail.Session
                        It may also be the type of a custom J2EE Connector's
                        connection factory interface, etc.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="res-auth" type="xs:string" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Can be set to "Application" or "Container" per the J2EE
                        definition of resource references (default is Application).

                        This is normally not pertinent unless you are using a
                        custom J2EE Connector -- JDBC, JMS, and JavaMail resources
                        normally have any necessary authentication information
                        configured into them at deployment time and ignore this
                        option.

                        The default is "Application".
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="res-sharing-scope" type="xs:string" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Can be set to "Shareable" or "Unshareable" per the J2EE
                        definition of resource references (default is Shareable).
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="pattern" type="job:patternType">
                <xs:annotation>
                    <xs:documentation>
                        Identifies the resource within the server that this reference
                        points to.  Normally only the "name" child element is
                        necessary.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="gbeanRefType">
        <xs:sequence>
            <xs:element name="property" type="xs:string">
                <xs:annotation>
                    <xs:documentation>
                        The name of the property on the job that this GBean
                        reference should be injected into.  There must be a
                        setter with the right name for the property (e.g.
                        if the property is foo or Foo, there must be a setter
                        setFoo that takes an argument of the correct type,
                        which is normally one of the interfaces listed in
                        the ref-type element).
                    </xs:documentation>
                </xs:annotation>

            </xs:element>
            <xs:element name="ref-type" type="xs:string" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>
                        The fully-qualified class name of a Java interface that the
                        GBean implements.  Multiple interfaces may be listed (assuming
                        the GBean in question implements them all), in which case the
                        resulting reference can be cast to any of the specified
                        interfaces.

                        For example, to create a reference to the Quartz Scheduler GBean,
                        you would set this to:  org.gplugins.quartz.QuartzScheduler
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="pattern" type="job:patternType">
                    <xs:annotation>
                        <xs:documentation>
                            Identifies the GBean within the server that this reference
                            points to.  Normally only the "name" child element is
                            necessary.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
            </xs:choice>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="patternType">
        <xs:sequence>
            <xs:element name="groupId" type="xs:string" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        If the resource name and type are not enough to uniquely
                        identify the resource, then the groupId, artifactId, and
                        version can be used to identify the module that the
                        target resource is in.  The values specified should match
                        the components of the moduleId for the target module.
                        The version may be omitted to select any available version.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="artifactId" type="xs:string" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        If the resource name and type are not enough to uniquely
                        identify the resource, then the groupId, artifactId, and
                        version can be used to identify the module that the
                        target resource is in.  The values specified should match
                        the components of the moduleId for the target module.
                        The version may be omitted to select any available version.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="version" type="xs:string" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        If the resource name and type are not enough to uniquely
                        identify the resource, then the groupId, artifactId, and
                        version can be used to identify the module that the
                        target resource is in.  The values specified should match
                        the components of the moduleId for the target module.
                        The version may be omitted to select any available version.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="module" type="xs:string" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Should only be used when the resource is in a child module
                        within an EAR, and must be distinguished from other resources
                        in different modules in the same EAR.  This value should be
                        the file name of the module within the EAR.  It is rarely
                        necessary.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="name" type="xs:string">
                <xs:annotation>
                    <xs:documentation>
                        The name of the component that this reference is referring to.
                        For a database pool or JMS connection factory, this matches the
                        pool name or connection factory name specified when creating the
                        resource in the console, or the connectiondefinition-instance/name
                        specified in the deployment plan.  For an EJB this is the EJB
                        name, and for a GBean it is the name specified in the "gbean"
                        element where the GBean was declared.

                        If the name and type are not enough to uniquely identify the
                        resource in question, the other elements in the pattern can be
                        used to specify the module that the resource is in, potentially
                        including the module name within an EAR.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

