<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
        targetNamespace="http://geronimo.apache.org/xml/ns/plugins/jasper-1.0"
        xmlns:rep="http://geronimo.apache.org/xml/ns/plugins/jasper-1.0"
        xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1"
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        elementFormDefault="qualified"
        attributeFormDefault="unqualified"
        >

    <xs:annotation>
        <xs:documentation>
            Schema for a deployment plan for one or more Jasper report definitions.
        </xs:documentation>
    </xs:annotation>

    <xs:import namespace="http://geronimo.apache.org/xml/ns/deployment-1.1" schemaLocation="geronimo-module-1.1.xsd"/>

    <xs:element name="reports" type="rep:reportsType">
        <xs:annotation>
            <xs:documentation>
                A list of report definitions to register with the report manager
                (allowing clients to run the report later).
            </xs:documentation>
        </xs:annotation>
    </xs:element>

    <xs:complexType name="reportsType">
        <xs:sequence>
            <xs:element ref="sys:environment"/>
            <xs:element name="report" type="rep:reportType" minOccurs="1" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>
                        The definition of a report that can be printed with JasperReports
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="reportType">
        <xs:sequence>
            <xs:element name="name" type="xs:string">
                <xs:annotation>
                    <xs:documentation>
                        A unique name used to identify the report definition
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="template-file" type="xs:string">
                <xs:annotation>
                    <xs:documentation>
                        The name of the Jasper XML report template file (JRXML file).  This
                        file must be provided when the report is deployed.  For standalone
                        reports, it can be passed to the deploy tool as an argument along
                        with the plan that complies with this schema.  If the plan lists
                        multiple report definitions, all the report templates can be put in
                        a JAR and the JAR passed along with the plan.  If the plan is put
                        in a J2EE application like a Web Application WAR, then the report
                        templates should be added to the class path of that module (e.g.
                        in WEB-INF/classes or a JAR in WEB-INF/lib for a WAR or in the root
                        of an EJB JAR).
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="data-source" type="xs:string" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Names a database connection pool deployed in Geronimo which this
                        report will use.  The database pool must be running when this report
                        is deployed.

                        This element is optional, but if it is not provided, then every
                        caller must manually pass a data source as an argument when
                        generating the report.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="default-criteria" type="rep:default-criteriaType" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Contains default criteria for the report.  These criteria will be
                        pre-populated and then any settings passed as arguments when
                        generating the report will override these defaults.

                        This element is optional; if not specified, no default values will
                        be used for any report criteria.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="available-output-formats" type="rep:available-output-formatsType" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Restricts the possible report output formats to the values listed
                        here.  This can be used if a particular report template was only
                        prepared to look good for certain output types.  If a caller
                        specifies an output type other than one listed here, they will
                        get an error.

                        This element is optional; if not used, all output types are valid
                        and the caller must specify one.  Otherwise, the first format
                        listed will be used as the default if the caller does not specify
                        a format.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="archiving" type="rep:archivingType" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Configures how reports should be stored after they are generated.
                        This includes how long they should be saved, the file naming
                        conventions, when a generated report should be overridden by a
                        more recently generated report, etc.

                        This element is optional; if not used, the report will default to
                        being saved as a temporary file only, and deleted when the JVM is
                        shut down (unless the caller deletes it sooner).
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="default-criteriaType">
        <xs:sequence>
            <xs:element name="property" type="rep:propertyType" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>
                        Specifies a single report property that will be used in the default
                        criteria.  This includes the property name, value, and Java data
                        type (if not String).
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="archivingType">
        <xs:sequence>
            <xs:element name="subdirectory" type="xs:string" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Every archived report is saved in a space managed by the file archive
                        service.  Normally, all reports are saved in a subdirectory of that
                        space called reports/.  This element can be used to replace that
                        with no subdirectory (an empty element) or any subdirectory path you
                        like.  Just note that any such path must be relative (and will be
                        relative to the file archive service's root directory).
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="versioning" type="rep:versioningType" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        Every time this report is generated, it is saved to disk with a version
                        number.  This may be the date or timestamp when the report was generated,
                        or it may be set to only save a single version (the most recent time the
                        report was run).

                        The available options are TIMESTAMP (the default if an archiving element
                        is present), DATE, or OVERWRITE (for more detail, see versioningType
                        below).

                        Note: criteria are ignored, so two copies of the report with different
                        criteria may still overwrite each other if the versioning strategy is
                        DATE or OVERWRITE.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="save-for" type="xs:string" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>
                        How long a generated report should be saved on disk.  This is a value
                        such as:

                          30 seconds
                          15 minutes
                          4 hours
                          2 days
                          3 weeks
                          6 months
                          5 years

                        The default is to save a report forever (that is, until it is manually
                        deleted).
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="available-output-formatsType">
        <xs:sequence>
            <xs:element name="output-format" type="rep:output-formatType" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>
                        Identifies a specific allowed output format for this report.
                    </xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="propertyType">
        <xs:annotation>
            <xs:documentation>
                One of the default criteria for this report.  The name attribute and
                content must be provided.  The type is required if the data type
                should not be String.
            </xs:documentation>
        </xs:annotation>
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="name" use="required">
                    <xs:annotation>
                        <xs:documentation>
                            The name if this property, which will be used to populate
                            the default criteria map.
                        </xs:documentation>
                    </xs:annotation>
                </xs:attribute>
                <xs:attribute name="type" use="optional">
                    <xs:annotation>
                        <xs:documentation>
                            The fully-qualified Java class name of this property.  The
                            class must have a constructor that takes a String (the
                            content of the property element).

                            The default data type is java.lang.String if this attribute
                            is not used.
                        </xs:documentation>
                    </xs:annotation>
                </xs:attribute>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:simpleType name="versioningType">
        <xs:annotation>
            <xs:documentation>
                The valid values for the versioning strategy:

                TIMESTAMP -- save every report with a timestamp in milliseconds as the version
                DATE -- save every report of this type using the date it was generated as the
                        version; if the report is run multiple times on the same day, only the
                        last will be saved.
                OVERWRITE -- only save the most recently generated report of this type.

                The default versioning strategy is TIMESTAMP
        </xs:documentation>
      </xs:annotation>
      <xs:restriction base="xs:token">
        <xs:enumeration value="TIMESTAMP"/>
        <xs:enumeration value="DATE"/>
        <xs:enumeration value="OVERWRITE"/>
      </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="output-formatType">
        <xs:annotation>
            <xs:documentation>
                The valid values for the report output format.

                Note that this plugin does not support non-file-based formats
                (Java printing, Graphics2D, etc.)
        </xs:documentation>
      </xs:annotation>
      <xs:restriction base="xs:token">
        <xs:enumeration value="PDF"/>
        <xs:enumeration value="HTML"/>
        <xs:enumeration value="XML"/>
        <xs:enumeration value="RTF"/>
        <xs:enumeration value="EXCEL"/>
        <xs:enumeration value="CSV"/>
        <xs:enumeration value="TEXT"/>
      </xs:restriction>
    </xs:simpleType>
</xs:schema>

