<?xml version='1.0' encoding="UTF-8"?>
<!--
    Castor Source Generator Binding File XML Schema
    Namespace: http://castor.exolab.org/SourceGenerator/Binding
    System:    http://castor.exolab.org/binding.xsd
    Public:    -//EXOLAB/Castor Binding Schema Version 1.0//EN

    This schema is used to generate part of the
    org.exolab.castor.builder.binding package
    *Note*: This schema is under evolution and subject to change.
 	This schema is under the Exolab license
 	
 	Author: Arnaud Blandin [blandin@intalio.com]
 -->
<!-- $Id$ -->
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	    targetNamespace="http://www.castor.org/SourceGenerator/Binding"
	    xmlns="http://www.castor.org/SourceGenerator/Binding"
	    elementFormDefault="qualified">

   <!-- The root element -->
    <xsd:element name="binding">
        <xsd:annotation>
            <xsd:documentation>
                 The root element that contains the different binding elements.
                 The binding file is written from a schema point of view and follows the
                 structure of an XML Schema.
                 The root element can also be used to configure the default binding type. 
            </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="include" type="includeType" minOccurs="0" maxOccurs="unbounded"/>
                <xsd:element name="package" type="packageType" minOccurs="0" maxOccurs="unbounded"/>
                <xsd:element name="namingXML" type="namingXMLType" minOccurs="0" maxOccurs="1"/> 
               	<xsd:element name="automaticNaming" type="automaticNamingType" minOccurs="0" maxOccurs="1"/>
                <xsd:element ref="componentBinding" minOccurs="0" maxOccurs="unbounded"/>
                <xsd:element ref="elementBinding" minOccurs="0" maxOccurs="unbounded"/>
                <xsd:element ref="attributeBinding" minOccurs="0" maxOccurs="unbounded"/>
                <xsd:element ref="complexTypeBinding" minOccurs="0" maxOccurs="unbounded"/>
                <xsd:element ref="groupBinding" minOccurs= "0" maxOccurs="unbounded"/>
                <xsd:element ref="enumBinding" minOccurs="0" maxOccurs="unbounded"/>
                <xsd:element ref="simpleTypeBinding" minOccurs="0" maxOccurs="unbounded"/>
                 
            </xsd:sequence>
            <!-- the binding type: 'element' approach or 'type' approach -->
            <xsd:attribute name="defaultBindingType" type="bindingType" default="element"/>
        </xsd:complexType>
    </xsd:element>
    
    <!--global definition to allow reference-->
    <xsd:element name="componentBinding" type="componentBindingType"/>
    <xsd:element name="elementBinding" type="componentBindingType"/>
    <xsd:element name="attributeBinding" type="componentBindingType"/>
    <xsd:element name="complexTypeBinding" type="componentBindingType"/>
    <xsd:element name="groupBinding" type="componentBindingType"/>
    <xsd:element name="enumBinding" type="componentBindingType"/>
    <xsd:element name="simpleTypeBinding" type="componentBindingType"/>

    <!--ComplexTypes definitions-->
    <xsd:complexType name="includeType">
        <xsd:annotation>
            <xsd:documentation>
                 A binding file can include other binding files by specifying the location  
                 (URI) of the binding files to include.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:attribute name="URI" type="xsd:anyURI" use="required"/>
    </xsd:complexType>

    <xsd:complexType name="packageType">
        <xsd:annotation>
            <xsd:documentation>
                 Mappings between a namespace and a java package can directly 
                 be defined in the binding file. This element allows also the mapping
                 between a package and a schemaLocation.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
           <!--fully qualified name-->
           <xsd:element name="name" type="xsd:string" minOccurs="1" maxOccurs="1"/>
           <xsd:choice>
               <xsd:element name="namespace" type="xsd:string" minOccurs="1" maxOccurs="1"/>
               <xsd:element name="schemaLocation" type="xsd:string" minOccurs="1" maxOccurs="1"/>
           </xsd:choice>
        </xsd:sequence>
    </xsd:complexType>
    
    <xsd:complexType name="namingXMLType">
    <xsd:annotation>
            <xsd:documentation>
                 This element allows to define naming convention when naming a complexType, element or
                 modelGroup. Indeed the user can decide of a prefix to add to each class name as well
                 as a suffix. This naming style won't affect the names entered in the binding file but only 
                 the XML Names.
            </xsd:documentation>
        </xsd:annotation>
        <xsd:sequence>
           <xsd:element name="elementName" type="namingType" minOccurs="0" maxOccurs="1"/>
           <xsd:element name="complexTypeName" type="namingType" minOccurs="0" maxOccurs="1"/>
           <xsd:element name="modelGroupName" type="namingType" minOccurs="0" maxOccurs="1"/>
        </xsd:sequence>
    </xsd:complexType>
    
    <xsd:complexType name="namingType">
        <xsd:sequence>
            <xsd:element name="prefix" type="xsd:string" minOccurs="0" maxOccurs="1"/>
            <xsd:element name="suffix" type="xsd:string" minOccurs="0" maxOccurs="1"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="componentBindingType">
         <xsd:annotation>
            <xsd:documentation>
                A binding element is defined to express the binding between an XML Schema Component
                and Java class OR a java interface or a java member class. The XML Schema component can 
                be an element, an attribute, a complexType or a group. Attribute cannot be mapped to 
                class, the reader of a binding file will take care that class or interface are not
                used for component whose xml-type is attribute.
            </xsd:documentation>
         </xsd:annotation>
         <xsd:sequence>
             <xsd:choice>
                 <xsd:element name="java-class" type="classType"/>
                 <xsd:element name="interface">
                     <xsd:complexType>
                         <xsd:attribute name="name" type="xsd:string" use="required"/>
                     </xsd:complexType> 
                 </xsd:element>
                 <xsd:element name="member" type="fieldType"/>
                 <xsd:element name="enum-def" type="enumBindingType"/>
                 <xsd:element name="contentMember" type="contentMemberType"/>
             </xsd:choice>
             <xsd:element ref="componentBinding" minOccurs="0" maxOccurs="unbounded"/>
             <xsd:element ref="elementBinding" minOccurs="0" maxOccurs="unbounded"/>
             <xsd:element ref="attributeBinding" minOccurs="0" maxOccurs="unbounded"/>
             <xsd:element ref="complexTypeBinding" minOccurs="0" maxOccurs="unbounded"/>
             <xsd:element ref="groupBinding" minOccurs="0" maxOccurs="unbounded"/>   
             <xsd:element ref="enumBinding" minOccurs="0" maxOccurs="unbounded"/>
             <xsd:element ref="simpleTypeBinding" minOccurs="0" maxOccurs="unbounded"/>
         </xsd:sequence>
         <!--the name of the schema component or an XPath expression that identify the component-->
         <xsd:attribute name="name" type="pathType" use="required"/>
     </xsd:complexType>

     <xsd:complexType name="classType">
        <xsd:annotation>
            <xsd:documentation>
                This type gathers the needed information to generate a Java Class
                from a binding file. Options such as generating the equals method,
                using wrapper classes for primitives or using bound properties can
                be defined via that element. When defined locally the options override
                the values defined in the castor.properties file.
            </xsd:documentation>
         </xsd:annotation>
         <xsd:sequence>
             <xsd:element name="implements" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
             <xsd:element name="extends" type="xsd:string" minOccurs="0" maxOccurs="1"/>
             <!-- not yet implemented -->
             <!--<xsd:element name="javadoc" type="xsd:string" minOccurs="0" maxOccurs="1"/>-->
         </xsd:sequence>
         <!--This attribute allows the local redefinition of a package name-->
         <xsd:attribute name="package" type="xsd:string"/>
         <xsd:attribute name="name" type="xsd:string"/>
         <xsd:attribute name="final" type="xsd:boolean"/>
         <xsd:attribute name="abstract" type="xsd:boolean"/>
         <!--properties for generating specific methods-->
         <xsd:attribute name="equals" type="xsd:boolean"/>
         <xsd:attribute name="bound" type="xsd:boolean"/>
     </xsd:complexType>

     <xsd:complexType name="fieldType">
         <xsd:annotation>
            <xsd:documentation>
                This type represents the binding for class member. It allows the definition
                of its name and java type as well as an implementation of FieldHandler 
                to help the Marshalling framework in handling that member. Defining a validator is also
                possible. The names given for the validator and the fieldHandler must be fully qualified
            </xsd:documentation>  
         </xsd:annotation>
         <xsd:attribute name="name" type="xsd:string"/>
         <xsd:attribute name="java-type" type="xsd:string"/>
         <xsd:attribute name="wrapper" type="xsd:boolean"/>
         <xsd:attribute name="handler" type="xsd:string"/>
         <!-- if the java-type is a primitive, the collection type must be an array -->
         <!-- the validation of the above statement must be enforced in the generated sources -->
         <xsd:attribute name="collection">
             <xsd:simpleType>
	             <xsd:restriction base="xsd:string">
                     <xsd:enumeration value="array"/>
                     <xsd:enumeration value="vector"/>
	                 <xsd:enumeration value="arraylist"/>
               		 <xsd:enumeration value="hashtable"/>
               		 <xsd:enumeration value="collection"/>
               		 <xsd:enumeration value="odmg"/>
                     <xsd:enumeration value="set"/>
                     <xsd:enumeration value="map"/>
                     <xsd:enumeration value="sortedset"/>
                 </xsd:restriction>
	         </xsd:simpleType> 
	     </xsd:attribute>        
         <xsd:attribute name="visibility">
             <xsd:simpleType>
	             <xsd:restriction base="xsd:string">
                     <xsd:enumeration value="public"/>
                     <xsd:enumeration value="protected"/>
	                 <xsd:enumeration value="private"/>
                 </xsd:restriction>
	         </xsd:simpleType> 
	     </xsd:attribute>        
	     <xsd:attribute name="validator" type="xsd:string"/>
     </xsd:complexType>

     <xsd:complexType name="contentMemberType">
         <xsd:annotation>
            <xsd:documentation>
                This type represents the binding for the 'content' member generated
                as part of a 'mixed' complex type definition. It allows the definition
                of its name.
            </xsd:documentation>  
         </xsd:annotation>
         <xsd:attribute name="name" type="xsd:string"/>
         <xsd:attribute name="visibility" type="VisibilityType"/>
     </xsd:complexType>

     <xsd:simpleType name="VisibilityType">
        <xsd:restriction base="xsd:string">
               <xsd:enumeration value="public"/>
               <xsd:enumeration value="protected"/>
            <xsd:enumeration value="private"/>
           </xsd:restriction>
    </xsd:simpleType> 
	     
    <xsd:complexType name="enumBindingType">
         <xsd:annotation>
            <xsd:documentation>
                This type allows the mapping between an XML schema enumeration
                and a java class that follows the type-safe enumeration paradigm.
                Additionally, it allows the specify the name of the Java constant
                definition for a given enumeraton value.
            </xsd:documentation>
         </xsd:annotation>
         <xsd:sequence>
             <xsd:element name="enumClassName" minOccurs="0" maxOccurs="1">
                 <xsd:complexType>
                     <xsd:simpleContent>
                         <xsd:extension base="xsd:string">
                             <xsd:attribute name="package" type="xsd:string"/>
                         </xsd:extension>
                     </xsd:simpleContent>
                 </xsd:complexType>
             </xsd:element>
             <xsd:element name="enumMember" minOccurs="0" maxOccurs="unbounded">
                 <xsd:complexType>
                     <xsd:sequence>
                         <xsd:element name="value" type="xsd:string"/>
                         <xsd:element name="javaName" type="xsd:string"/>
                     </xsd:sequence>
                 </xsd:complexType>
             </xsd:element>
         </xsd:sequence>
     </xsd:complexType>

     <!--simpleType definitions-->
     <xsd:simpleType name="pathType">
         <xsd:annotation>
             <xsd:documentation>
                 This type represents an easy path to access an element or an attribute
                 inside a schema. It is a direct restriction of the XPath specification.
             </xsd:documentation>
         </xsd:annotation>
         <xsd:restriction base="xsd:string">
           <!--  <xsd:pattern value="//any Valid XML name(//|@)any Valid XML Name "/>-->
         </xsd:restriction>
     </xsd:simpleType>
     
     <xsd:simpleType name="bindingType">
         <xsd:annotation>
             <xsd:documentation>
                 List of the allowed values for the binding type from an XML schema
                 to a java class. The type can either be 'element' or 'complexType'.
             </xsd:documentation>
         </xsd:annotation>
         <xsd:restriction base="xsd:string">
             <xsd:enumeration value="element"/>
             <xsd:enumeration value="type"/>
         </xsd:restriction>
     </xsd:simpleType>

    <xsd:complexType name="automaticNamingType">
         <xsd:sequence>
             <xsd:element name="forces" minOccurs="0" maxOccurs="1">
                 <xsd:complexType>
                     <xsd:sequence>
                         <xsd:element name="force" type="xsd:string" minOccurs="1" maxOccurs="unbounded" />
                     </xsd:sequence>
                 </xsd:complexType>
             </xsd:element>
             <xsd:element name="excludes" minOccurs="0" maxOccurs="1">
                 <xsd:complexType>
                     <xsd:sequence>
                         <xsd:element name="exclude" minOccurs="1" maxOccurs="unbounded">
                         	<xsd:complexType>
                         		<xsd:sequence>
                         			<xsd:element name="name" type="xsd:string" />
                         			<xsd:element name="class-name" type="xsd:string" minOccurs="0"/>
                         		</xsd:sequence>
                         	</xsd:complexType>
                         </xsd:element>
                     </xsd:sequence>
                 </xsd:complexType>
             </xsd:element>
         </xsd:sequence>
     </xsd:complexType>
     
</xsd:schema>