<?xml version="1.0" encoding="UTF-8"?>
<!--
The contents of this file are subject to the terms of the Common Development
and Distribution License (the License). You may not use this file except in
compliance with the License.

You can obtain a copy of the License at http://www.netbeans.org/cddl.html
or http://www.netbeans.org/cddl.txt.

When distributing Covered Code, include this CDDL Header Notice in each file
and include the License file at http://www.netbeans.org/cddl.txt.
If applicable, add the following below the CDDL Header, with the fields
enclosed by brackets [] replaced by your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"

The Original Software is NetBeans. The Initial Developer of the Original
Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
Microsystems, Inc. All Rights Reserved.
-->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://www.netbeans.org/ns/nb-module-project/2"
            xmlns="http://www.netbeans.org/ns/nb-module-project/2"
            elementFormDefault="qualified">
    
    <xsd:element name="data">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="code-name-base" type="javaPackageType"/>
                <xsd:choice minOccurs="0">
                    <xsd:element name="suite-component"/>
                    <xsd:element name="standalone"/>
                </xsd:choice>
                <xsd:element name="module-dependencies" type="moduleDependenciesType"/>
                <xsd:choice>
                    <xsd:element name="public-packages" type="publicPackagesType"/>
                    <xsd:element name="friend-packages" type="friendPackagesType"/>
                </xsd:choice>
                <xsd:element name="class-path-extension" minOccurs="0" maxOccurs="unbounded" type="classPathExtensionType"/>
                <xsd:element name="extra-compilation-unit" minOccurs="0" maxOccurs="unbounded" type="compilation-unit"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    
    <xsd:complexType name="moduleDependenciesType">
        <xsd:sequence>
            <xsd:element name="dependency" type="moduleDependencyType" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
    </xsd:complexType>
    
    <xsd:complexType name="moduleDependencyType">
        <xsd:sequence>
            <xsd:element name="code-name-base" type="javaPackageType"/>
            <!-- location in source tree is derived from code-name-base -->
            <!-- It is senseless to have *none* of the following. -->
            <!-- compile-dependency implies build-prerequisite. -->
            <xsd:element name="build-prerequisite" minOccurs="0"/>
            <xsd:element name="compile-dependency" minOccurs="0"/>
            <xsd:element name="run-dependency" minOccurs="0" type="runDependencyType"/>
        </xsd:sequence>
    </xsd:complexType>
    
    <xsd:complexType name="runDependencyType">
        <xsd:sequence>
            <xsd:element name="release-version" type="releaseVersionType" minOccurs="0"/>
            <xsd:choice minOccurs="0">
                <xsd:element name="specification-version" type="specificationVersionType"/>
                <!-- Empty; actual impl version to use determined during the build -->
                <xsd:element name="implementation-version"/>
            </xsd:choice>
        </xsd:sequence>
    </xsd:complexType>
    
    <xsd:simpleType name="javaPackageType">
        <xsd:restriction base="xsd:NCName">
            <!-- XXX should also handle Unicode I suppose -->
            <xsd:pattern value="[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)*"/>
        </xsd:restriction>
    </xsd:simpleType>
    
    <xsd:simpleType name="releaseVersionType">
        <xsd:union memberTypes="xsd:nonNegativeInteger">
            <xsd:simpleType>
                <xsd:restriction base="xsd:NMTOKEN">
                    <xsd:pattern value="(0|[1-9][0-9]*)-[1-9][0-9]*"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:union>
    </xsd:simpleType>
    
    <xsd:simpleType name="specificationVersionType">
        <xsd:restriction base="xsd:NMTOKEN">
            <xsd:pattern value="(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*"/>
        </xsd:restriction>
    </xsd:simpleType>
    
    <xsd:complexType name="publicPackagesType">
        <xsd:sequence>
            <xsd:choice minOccurs="0" maxOccurs="unbounded">
                <xsd:element name="package" type="javaPackageType"/>
                <xsd:element name="subpackages" type="javaPackageType"/>
            </xsd:choice>
        </xsd:sequence>
    </xsd:complexType>
    
    <xsd:complexType name="friendPackagesType">
        <xsd:sequence>
            <xsd:choice minOccurs="1" maxOccurs="unbounded">
                <xsd:element name="friend" type="javaPackageType"/>
            </xsd:choice>
            <xsd:choice minOccurs="1" maxOccurs="unbounded">
                <xsd:element name="package" type="javaPackageType"/>
            </xsd:choice>
        </xsd:sequence>
    </xsd:complexType>
    
    <!-- Loosely borrowed from ant/freeform: -->
    
    <!-- Some text that might be substituted with Ant property references. -->
    <xsd:simpleType name="substitutable-text">
        <xsd:restriction base="xsd:string">
            <!-- XXX limit by regexp, perhaps -->
        </xsd:restriction>
    </xsd:simpleType>
    
    <xsd:complexType name="compilation-unit">
        <xsd:sequence>
            <xsd:element name="package-root" type="substitutable-text"/>
            <xsd:element name="classpath" type="substitutable-text"/>
            <xsd:element name="built-to" minOccurs="0" maxOccurs="unbounded" type="substitutable-text"/>
        </xsd:sequence>
    </xsd:complexType>
    
    <xsd:complexType name="classPathExtensionType">
        <xsd:sequence>
            <xsd:element name="runtime-relative-path" type="xsd:string"/>
            <xsd:element name="binary-origin" minOccurs="0" type="substitutable-text"/>
        </xsd:sequence>
    </xsd:complexType>
    
</xsd:schema>
