<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns="http://www.mulesource.org/schema/mule/file/2.0"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:mule="http://www.mulesource.org/schema/mule/core/2.0"
            targetNamespace="http://www.mulesource.org/schema/mule/file/2.0"
            elementFormDefault="qualified"
            attributeFormDefault="unqualified">

    <xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
    <xsd:import namespace="http://www.mulesource.org/schema/mule/core/2.0"
                schemaLocation="http://www.mulesource.org/schema/mule/core/2.0/mule.xsd"/>

    <xsd:complexType name="filenameParserType">
        <xsd:annotation>
            <xsd:documentation>
                This controls the mapping from filename patterns to filenames.
                Is requires an implementation of the FilenameParser interface,
                which is used to control how filename patterns are used to generate file names.
            </xsd:documentation>
        </xsd:annotation>
    </xsd:complexType>

    <xsd:element name="connector" type="fileConnectorType" substitutionGroup="mule:abstract-connector"/>
    <xsd:complexType name="fileConnectorType">
        <xsd:complexContent>
            <xsd:extension base="mule:connectorType">
                <xsd:sequence minOccurs="0" maxOccurs="1">
                    <xsd:element ref="abstract-filenameParser"/>
                </xsd:sequence>
                <xsd:attributeGroup ref="inboundAttributes"/>
                <xsd:attributeGroup ref="outboundAttributes"/>
                <xsd:attribute name="writeToDirectory" type="xsd:string">
                    <xsd:annotation>
                        <xsd:documentation>
                            The directory path where the file should be written on dispatch.
                            This path is usually set as the endpoint of the dispatch event,
                            however this allows you to explicitly force a single directory for the connector.
                        </xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>
                <xsd:attribute name="readFromDirectory" type="xsd:string">
                    <xsd:annotation>
                        <xsd:documentation>
                            The directory path where the file should be read from.
                            This path is usually set as the inbound endpoint,
                            however this allows you to explicitly force a single directory for the connector.
                        </xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>
                <xsd:attribute name="autoDelete" type="mule:substitutableBoolean">
                    <xsd:annotation>
                        <xsd:documentation>
                            By default, when a file is received it is read into a String or byte[].
                            The file is moved if the moveToDirectory is set, otherwise it is deleted.
                            To access the File object set this property to false and specify a
                            NoActionTransformer transformer for the connector.
                            Mule will not delete the file, so it's up to the component to delete it
                            when it's done.
                            If the moveToDirectory is set, the file is first moved, then the
                            File object of the moved file is passed to the component.
                            It is recommended that a moveToDirectory is specified when turning autoDelete off.
                        </xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>
                <xsd:attribute name="outputAppend" type="mule:substitutableBoolean">
                    <xsd:annotation>
                        <xsd:documentation>
                            Should output append to existing file?
                        </xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>
                <xsd:attribute name="serialiseObjects" type="mule:substitutableBoolean">
                    <xsd:annotation>
                        <xsd:documentation>
                            Determines whether objects should be serialized to the file or not.
                            If not the raw bytes or text is written.
                        </xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>
                <xsd:attribute name="streaming" type="mule:substitutableBoolean">
                    <xsd:annotation>
                        <xsd:documentation>
                            Should a FileInputStream be sent as the message payload or a File?
                        </xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:element name="file-to-byte-array-transformer" type="mule:abstractTransformerType"
                 substitutionGroup="mule:abstract-transformer"/>
    <xsd:element name="file-to-string-transformer" type="mule:abstractTransformerType"
                 substitutionGroup="mule:abstract-transformer"/>

    <xsd:element name="filename-wildcard-filter" type="mule:wildcardFilterType"
                 substitutionGroup="mule:abstract-filter"/>

    <xsd:element name="filename-regex-filter" type="mule:wildcardFilterType"
                 substitutionGroup="mule:abstract-filter"/>

    <xsd:element name="inbound-endpoint" type="inboundEndpointType" substitutionGroup="mule:abstract-inbound-endpoint"/>
    <xsd:complexType name="inboundEndpointType">
        <xsd:complexContent>
            <xsd:extension base="mule:inboundEndpointType">
                <xsd:attributeGroup ref="addressAttributes"/>
                <xsd:attributeGroup ref="inboundAttributes"/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:element name="outbound-endpoint" type="outboundEndpointType"
                 substitutionGroup="mule:abstract-outbound-endpoint"/>
    <xsd:complexType name="outboundEndpointType">
        <xsd:complexContent>
            <xsd:extension base="mule:outboundEndpointType">
                <xsd:attributeGroup ref="addressAttributes"/>
                <xsd:attributeGroup ref="outboundAttributes"/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:element name="endpoint" type="globalEndpointType" substitutionGroup="mule:abstract-global-endpoint"/>
    <xsd:complexType name="globalEndpointType">
        <xsd:complexContent>
            <xsd:extension base="mule:globalEndpointType">
                <xsd:attributeGroup ref="addressAttributes"/>
                <xsd:attributeGroup ref="inboundAttributes"/>
                <xsd:attributeGroup ref="outboundAttributes"/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:attributeGroup name="inboundAttributes">
        <xsd:attribute name="pollingFrequency" type="mule:substitutableLong">
            <xsd:annotation>
                <xsd:documentation>
                    The frequency in milliseconds that the read directory should be checked.
                    Note that the read directory is specified by the endpoint of the listening component.
                </xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
        <xsd:attribute name="fileAge" type="mule:substitutableLong">
            <xsd:annotation>
                <xsd:documentation>
                    Miniumum age (ms) for a file to be processed.
                </xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
        <xsd:attribute name="moveToPattern" type="xsd:string">
            <xsd:annotation>
                <xsd:documentation>
                    The pattern to use when moving a read file to an new location determined by the
                    moveToDirectory property.
                    This can use the patterns supported by the filename-parser configured for this connector
                </xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
        <xsd:attribute name="moveToDirectory" type="xsd:string">
            <xsd:annotation>
                <xsd:documentation>
                    The directory path where the file should be written once it has been read.
                    If this is not set the file read is deleted.
                </xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
        <xsd:attribute name="comparator" type="mule:substitutableClass">
            <xsd:annotation>
                <xsd:documentation>
                    Sort incoming files using this comparator.
                    The class must implement java.util.Comparator interface.
                </xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
        <xsd:attribute name="reverseOrder" type="mule:substitutableBoolean">
            <xsd:annotation>
                <xsd:documentation>
                    Should comparator order be reversed?
                </xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
    </xsd:attributeGroup>

    <xsd:attributeGroup name="outboundAttributes">
        <xsd:attribute name="outputPattern" type="xsd:string">
            <xsd:annotation>
                <xsd:documentation>
                    The pattern to use when writing a file to disk.
                    This can use the patterns supported by the filename-parser configured for this connector
                </xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
    </xsd:attributeGroup>

    <xsd:attributeGroup name="addressAttributes">
        <xsd:attribute name="path" type="xsd:string">
            <xsd:annotation>
                <xsd:documentation>
                    A file location.
                </xsd:documentation>
            </xsd:annotation>
        </xsd:attribute>
    </xsd:attributeGroup>

    <xsd:element name="legacy-filename-parser" type="legacyFilenameParserType" substitutionGroup="abstract-filenameParser"/>
    <xsd:complexType name="legacyFilenameParserType">
        <xsd:annotation>
            <xsd:documentation>
                The file connector uses this as a default implementation, it understands the following patterns:
                <ul>
                    <li>${DATE} - the current date in the format dd-MM-yy_HH-mm-ss.SS;</li>
                    <li>${DATE:yy-MM-dd} - the current date using the specified format;</li>
                    <li>${SYSTIME} - The current system time milliseconds;</li>
                    <li>${UUID} - A generated Universally unique id;</li>
                    <li>${ORIGINALNAME} - The original file name if the file being written was read from another
                        location;
                    </li>
                    <li>${COUNT} - An incremental counter.</li>
                </ul>
            </xsd:documentation>
        </xsd:annotation>
        <xsd:complexContent>
            <xsd:extension base="filenameParserType"/>
        </xsd:complexContent>
    </xsd:complexType>
    
    <xsd:element name="expression-filename-parser" type="expressionFilenameParserType" substitutionGroup="abstract-filenameParser"/>
     <xsd:complexType name="expressionFilenameParserType">
        <xsd:annotation>
            <xsd:documentation>
                ExpressionFilenameParser can use any expression language supported by Mule
                to construct a file name for the current message. Expressions can be xpath, xquery, ognl, mvel, header,
                function
                and more. For more information see http://muledocs.org/v2/Expressions.

                For example an xpath expression can be defined to pull a message id out of an xml message and use that
                as the file name -

                ${xpath:/message/header/@id}

                This parser superseeds the legacy-filename-parser which has been kept in
                Mule 2 for
                compatibility. The following demonstrates how to achieve the same results when using the
                expression-filename-parser over the legacy-filename-parser.
                <ul>
                    <li>${DATE} : ${function:dateStamp}</li>
                    <li>${DATE:yy-MM-dd} : ${function:dateStamp(yy-MM-dd)}</li>
                    <li>${SYSTIME} : ${function:systime}</li>
                    <li>${UUID} : ${function:uuid}</li>
                    <li>${ORIGINALNAME} : ${header:originalFilename}</li>
                    <li>${COUNT} : ${function:counter} - note that this is a global counter. If you want a local counter
                        per file connector then you should use the legacy-filename-parser.
                    </li>
                    <li>${[Message Property Name]} : ${header:[Message Property Name]}</li>
                </ul>
            </xsd:documentation>
        </xsd:annotation>
        <xsd:complexContent>
            <xsd:extension base="filenameParserType"/>
        </xsd:complexContent>                
    </xsd:complexType>
    
    <xsd:element name="custom-filename-parser" type="customFilenameParserType"
                 substitutionGroup="abstract-filenameParser">
        <xsd:annotation>
            <xsd:documentation>
                Allows the user to specify custom filename parser. The implementation has to implement
                org.mule.transports.file.FilenameParser.
            </xsd:documentation>
        </xsd:annotation>
    </xsd:element>
    <xsd:complexType name="customFilenameParserType">
        <xsd:complexContent>
            <xsd:extension base="filenameParserType">
                <xsd:attribute name="class" type="xsd:NMTOKEN" use="required">
                    <xsd:annotation>
                        <xsd:documentation>
                            The implementation class name that implement s
                            org.mule.transports.file.FilenameParser.
                        </xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

    <xsd:element name="abstract-filenameParser" abstract="true" type="filenameParserType">
        <xsd:annotation>
            <xsd:documentation>
                A placeholder for flename parser elements.
            </xsd:documentation>
        </xsd:annotation>
    </xsd:element>
</xsd:schema>
