<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2008-2016 Haulmont.
  ~
  ~ 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://schemas.haulmont.com/cuba/metadata.xsd"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns="http://schemas.haulmont.com/cuba/metadata.xsd"
        elementFormDefault="qualified"
        attributeFormDefault="unqualified">

    <xs:element name="metadata">
        <xs:complexType mixed="true">
            <xs:sequence>
                <xs:element type="metadataModelType" name="metadata-model" minOccurs="0" maxOccurs="1"/>
                <xs:element type="annotationsType" name="annotations" minOccurs="0" maxOccurs="1"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:complexType name="metadataType">
        <xs:sequence>
            <xs:element type="metadataModelType" name="metadata-model"/>
            <xs:element type="annotationsType" name="annotations"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="metadataModelType">
        <xs:sequence>
            <xs:element type="xs:string" name="class" maxOccurs="unbounded" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute type="xs:string" name="root-package" use="required"/>
        <xs:attribute type="xs:string" name="namespace"/>
    </xs:complexType>

    <xs:complexType name="annotationsType">
        <xs:sequence>
            <xs:element type="entityType" name="entity" maxOccurs="unbounded" minOccurs="1"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="entityType">
        <xs:sequence>
            <xs:element type="annotationType" name="annotation" maxOccurs="unbounded" minOccurs="1"/>
            <xs:element type="propertyType" name="property" maxOccurs="unbounded" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute type="xs:string" name="class" use="required"/>
    </xs:complexType>

    <xs:complexType name="propertyType">
        <xs:sequence>
            <xs:element type="annotationType" name="annotation" maxOccurs="unbounded" minOccurs="1"/>
        </xs:sequence>
        <xs:attribute type="xs:string" name="name" use="required"/>
    </xs:complexType>

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

</xs:schema>