<?xml version="1.0" encoding="UTF-8"?>
<!--
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You 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
    xmlns:geronimo="http://geronimo.apache.org/xml/ns/j2ee/application-2.0"
    targetNamespace="http://geronimo.apache.org/xml/ns/j2ee/application-2.0"
    xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
    attributeFormDefault="unqualified" version="1.0">

    <xs:annotation>
        <xs:documentation>
            This is an XML Schema Definition for Geronimo enterprise application
            deployment plan. In case the enterprise application deployment plan
            is provided internally in the enterprise archive, it should be
            located under META-INF/geronimo-application.xml. In case the
            enterprise application deployment plan is provided externally, the
            deployment descriptor can be named anything and provided as an
            argument to the deploy tool. All the enterprise application
            deployment plan must specify the top level element as application
            with namespace specified as xmlns =
            "http://geronimo.apache.org/xml/ns/j2ee/application-2.0". The
            default location for this document is
            http://geronimo.apache.org/xml/ns/j2ee/application-2.0
        </xs:documentation>
    </xs:annotation>

    <xs:import namespace="http://geronimo.apache.org/xml/ns/deployment-1.2"
        schemaLocation="geronimo-module-1.2.xsd">
        <xs:annotation>
            <xs:documentation>
                Import Geronimo Services deployment plans. The imported plan
                includes complex types like moduleType, environmentType,
                dependenciesType, etc. required by this plan schema.
            </xs:documentation>
        </xs:annotation>
    </xs:import>

    <xs:element name="application" type="geronimo:applicationType">
        <xs:annotation>
            <xs:documentation>
                The root element for Geronimo web application deployment plan.
                This element should always exist in instance documents. Note
                that the sub-elements of this element should be as in the given
                order in the sequence.
            </xs:documentation>
        </xs:annotation>
    </xs:element>
    <xs:complexType name="applicationType">
        <xs:annotation>
            <xs:documentation>
                The complex type for root element, it defines the elements of
                root element for Geronimo enterprise application deployment
                plan. Basically it is a sequence of elements environment,
                module, ext-module, security, and services.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element ref="sys:environment">
                <xs:annotation>
                    <xs:documentation>
                        Reference to environment element defined in imported
                        "geronimo-module-1.2.xsd"
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="module" type="geronimo:moduleType" minOccurs="0"
                maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>
                        An optional module element which defines various
                        modules included in the enterprise application archive.
                        It mirrors the moduleType defined by application_1_4.xsd
                        and adds an optional alt-dd element defining a Geronimo
                        specific deployment descriptor.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="ext-module" type="geronimo:ext-moduleType"
                minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>
                        It is used to define modules included in this
                        application externally and these module could be
                        included in the archive, or they may reside in Geronimo
                        repository. It defines optional internal-path or
                        external-path to module/repository element being
                        referenced.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>

            <xs:element ref="geronimo:security" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Reference to security element defined in this schema. If
                        this optional element is present, all web and EJB
                        modules must make the appropriate access checks as
                        outlined in the JACC spec. This element groups the
                        security role mapping settings for the application.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element ref="sys:service" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>
                        Reference to service element defined in imported
                        "geronimo-module-1.2.xsd".
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>

        <!--TODO application name should be settable using name-key in the environment.  Does this work? -->
        <xs:attribute name="application-name" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation>
                    An optional attribute used to define the application name
                    for main parent enterprise application defined in ear
                    module.
                </xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>

    <xs:complexType name="moduleType">
        <xs:annotation>
            <xs:documentation>
                Mirrors the moduleType defined by application_1_4.xsd and adds
                an optional alt-dd element defining a Geronimo specific
                deployment descriptor for J2EE connector, ejb, web, or java
                client modules.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:choice>
                <xs:element name="connector" type="geronimo:pathType">
                    <xs:annotation>
                        <xs:documentation>
                            The presence of this element is indicative of J2EE
                            module type to be resource adapter module, and the
                            value of this element provides URI of resource
                            adapter archive file path relative to the enterprise
                            application package main directory.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="ejb" type="geronimo:pathType">
                    <xs:annotation>
                        <xs:documentation>
                            The presence of this element is indicative of J2EE
                            module type to be EJB module, and the value of this
                            element provides URI of EJB archive file path
                            relative to the enterprise application package main
                            directory.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="java" type="geronimo:pathType">
                    <xs:annotation>
                        <xs:documentation>
                            The presence of this element is indicative of J2EE
                            module type to be Java Application client module,
                            and the value of this element provides URI of
                            application client java archive file path relative
                            to the enterprise application package main
                            directory.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="web" type="geronimo:pathType">
                    <xs:annotation>
                        <xs:documentation>
                            The presence of this element is indicative of Web
                            module type to be EJB module, and the value of this
                            element provides URI of Web archive file path
                            relative to the enterprise application package main
                            directory.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
            </xs:choice>
            <xs:choice>
                <xs:element name="alt-dd" type="geronimo:pathType">
                    <xs:annotation>
                        <xs:documentation>
                            Specifies an optional URI to the post-assembly
                            version of the Geronimo specific deployment
                            descriptor file for a particular J2EE module
                            relative to the enterprise application package main
                            directory.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:any namespace="##other" processContents="lax">
                    <xs:annotation>
                        <xs:documentation>
                            This option element contains the alternate geronimo
                            deployment plan for included modules.
                        </xs:documentation>
                    </xs:annotation>
                </xs:any>
            </xs:choice>
        </xs:sequence>
    </xs:complexType>

    <xs:element name="security" type="geronimo:abstract-securityType">
        <xs:annotation>
            <xs:documentation>
                If this optional element is present, all web and EJB modules
                must make the appropriate access checks as outlined in the JACC
                spec. This element groups the security role mapping settings for
                the application.
            </xs:documentation>
        </xs:annotation>
    </xs:element>

    <xs:complexType name="abstract-securityType" abstract="true">
        <xs:annotation>
            <xs:documentation>
                An abstract abstract-securityType used to indicate, all web and
                EJB modules must make the appropriate access checks as outlined
                in the JACC spec. This type will be extended and implemented by
                geronimo-security-2.0.xsd file.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence></xs:sequence>
    </xs:complexType>

    <xs:element name="clustering" type="geronimo:abstract-clusteringType">
        <xs:annotation>
            <xs:documentation>
                An abstract clustering used to provide clustering informtation
                for this application.
            </xs:documentation>
        </xs:annotation>
    </xs:element>

    <xs:complexType name="abstract-clusteringType" abstract="true">
        <xs:sequence></xs:sequence>
    </xs:complexType>

    <xs:complexType name="ext-moduleType">
        <xs:annotation>
            <xs:documentation>
                It is used to define modules included in this application
                externally and is not a part of the archive. It defines optional
                internal-path or external-path to module/repository element
                being referenced.
            </xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:choice>
                <xs:element name="connector" type="geronimo:pathType">
                    <xs:annotation>
                        <xs:documentation>
                            The presence of this element is indicative of J2EE
                            module type to be resource adapter module, and the
                            value of this element provides URI of resource
                            adapter archive file path relative to the enterprise
                            application package main directory.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="ejb" type="geronimo:pathType">
                    <xs:annotation>
                        <xs:documentation>
                            The presence of this element is indicative of J2EE
                            module type to be EJB module, and the value of this
                            element provides URI of EJB archive file path
                            relative to the enterprise application package main
                            directory.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="java" type="geronimo:pathType">
                    <xs:annotation>
                        <xs:documentation>
                            The presence of this element is indicative of J2EE
                            module type to be Java Application client module,
                            and the value of this element provides URI of
                            application client java archive file path relative
                            to the enterprise application package main
                            directory.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="web" type="geronimo:pathType">
                    <xs:annotation>
                        <xs:documentation>
                            The presence of this element is indicative of Web
                            module type to be EJB module, and the value of this
                            element provides URI of Web archive file path
                            relative to the enterprise application package main
                            directory.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
            </xs:choice>
            <xs:choice>
                <xs:element name="internal-path" type="xs:token">
                    <xs:annotation>
                        <xs:documentation>
                            The element indicates that the module is a part of
                            this enterprise application. The value of this
                            element specifies the path of module relative to
                            internal path indicates that the module is packaged
                            in the EAR, and a path specified here is relative to
                            the enterprise application package main directory.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
                <xs:element name="external-path" type="sys:patternType">
                    <xs:annotation>
                        <xs:documentation>
                            The element indicates that the module is not a part
                            of this enterprise application, but rather located
                            matching the supplied pattern in a Geronimo repository.
                        </xs:documentation>
                    </xs:annotation>
                </xs:element>
            </xs:choice>

            <!--TODO consider an alt-spec-dd element-->
            <!--Do not allow vendor plan inside ear.  If it is in the ear, this does not need to be an external module -->
            <xs:any namespace="##other" processContents="lax">
                <xs:annotation>
                    <xs:documentation>
                        This option element contains the geronimo deployment
                        plan for included modules. The geronimo deployment plan
                        for included modules can be packaged with module.
                    </xs:documentation>
                </xs:annotation>
            </xs:any>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="pathType">
        <xs:annotation>
            <xs:documentation>Mirrors j2ee:pathType.</xs:documentation>
        </xs:annotation>
        <xs:simpleContent>
            <xs:restriction base="geronimo:string" />
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="string">
        <xs:annotation>
            <xs:documentation>Mirrors j2ee:string.</xs:documentation>
        </xs:annotation>
        <xs:simpleContent>
            <xs:extension base="xs:token">
                <xs:attribute name="id" type="xs:ID" />
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

</xs:schema>
