<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="annotated-xsd.xsl"?>
<!-- edited with XMLSpy v2008 rel. 2 (http://www.altova.com) by Frank Machine (None) -->
<!--
 ScriptRunner executes heirarchies of scripts, especially SQL.
 Copyright (c) 2008 Massimo Tools Pty. Ltd.
  
 This file is part of ScriptRunner.
 ScriptRunner is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License 
 as published by the Free Software Foundation, either version 3 of the License, 
 or (at your option) any later version.
 
 ScriptRunner is distributed in the hope that it will be useful, 
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public License along with ScriptRunner; 
 if not, see <http://www.gnu.org/licenses/> or
 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
 
 The ScriptRunner home page is located at http://scriptrunner.sourceforge.net/
 The contact email address is scriptrunner@users.sourceforge.net
 -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xmlns:xi="http://www.w3.org/2001/XInclude" 
           elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.0">
	<!-- $Id: ScriptRunner.xsd,v 1.4 2008/09/27 23:06:37 pnmaher Exp $ -->
	<xs:import namespace="http://www.w3.org/2001/XInclude" schemaLocation="XInclude.xsd"/>
	<xs:complexType name="propertyType" mixed="false">
		<xs:annotation>
			<xs:documentation>Simple name-value pair</xs:documentation>
		</xs:annotation>
		<xs:simpleContent>
			<xs:extension base="xs:anySimpleType">
				<xs:attribute name="name" type="xs:string" use="required"/>
			</xs:extension>
		</xs:simpleContent>
	</xs:complexType>
	<xs:complexType name="propertiesType">
		<xs:annotation>
			<xs:documentation>List of properties</xs:documentation>
		</xs:annotation>
		<xs:sequence>
			<xs:element name="property" type="propertyType" nillable="false" minOccurs="0" maxOccurs="unbounded"/>
			<xs:element ref="xi:include" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>
	<xs:attributeGroup name="jdbc3Attributes">
		<xs:annotation>
			<xs:documentation>The standard JDBC 3 configuration properties</xs:documentation>
		</xs:annotation>
		<xs:attribute name="dataSourceName" type="xs:string" use="required">
			<xs:annotation>
				<xs:documentation>Name of a connection the parent task and any children may use. This name would usually be unique.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="databaseName" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>The name of a particular database on a server</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="description" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>A description of this data source and what it will be used for.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="networkProtocol" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>Te network protocol used to communicate with the server</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="password" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>The user's database password</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="portNumber" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>The port number where a server is listening for requests</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="roleName" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>Tthe initial SQL role name</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="serverName" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>The database server name</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="user" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>The user's account name.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:attributeGroup>
	<xs:simpleType name="DbmsType">
		<xs:annotation>
			<xs:documentation>An enumeration of DBMS types</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:string">
			<xs:enumeration value="ORACLE"/>
			<xs:enumeration value="POSTGRES"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:complexType name="connectionType" mixed="false">
		<xs:annotation>
			<xs:documentation>General connection properties, with attributes for the standard JDBC3 connections. If a setter cannot be found by reflection, an error will be reported and processing will stop.</xs:documentation>
		</xs:annotation>
		<xs:sequence minOccurs="0" maxOccurs="unbounded">
			<xs:element name="properties" type="propertiesType" minOccurs="0">
				<xs:annotation>
					<xs:documentation>Individual JDBC DataSource implementations usually have their own set of non-standard configuration properties, which should be added here. If a setter cannot be found by reflection, an error will be reported but processing will continue.</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element ref="xi:include" minOccurs="0"/>
			<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded">
				<xs:annotation>
					<xs:documentation>Allow for the possibility of extension</xs:documentation>
				</xs:annotation>
			</xs:any>
		</xs:sequence>
		<xs:attribute name="dataSourceClass" type="xs:string" use="required">
			<xs:annotation>
				<xs:documentation>Class implementing javax.sql.ConnectionPoolDataSource or, in the worst case, simply javax.sql.DataSource.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="dataSourceType" type="DbmsType" use="optional">
			<xs:annotation>
				<xs:documentation>If provided, sets the DBMS type definitively for this connection.
Otherwise, the DBMS type is guessed form the dataSource class name or the Connection class name.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attributeGroup ref="jdbc3Attributes"/>
		<xs:anyAttribute namespace="##any" processContents="lax">
			<xs:annotation>
				<xs:documentation>Allow for the possibility of extension. </xs:documentation>
			</xs:annotation>
		</xs:anyAttribute>
	</xs:complexType>
	<xs:complexType name="connectionsType" mixed="false">
		<xs:annotation>
			<xs:documentation>List of connections</xs:documentation>
		</xs:annotation>
		<xs:sequence>
			<xs:element name="connection" type="connectionType" minOccurs="0" maxOccurs="unbounded">
				<xs:annotation>
					<xs:documentation>The standard JDBC 3 DataSource configuration properties are attributes. If a setter cannot be found by reflection, an error will be reported and processing stopped.</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:element ref="xi:include" minOccurs="0" maxOccurs="unbounded"/>
		</xs:sequence>
	</xs:complexType>
	<xs:attributeGroup name="ifAttributes">
		<xs:annotation>
			<xs:documentation>Documentation only: attributes for type=If tasks</xs:documentation>
		</xs:annotation>
		<xs:attribute name="ifname" type="xs:string" use="required">
			<xs:annotation>
				<xs:documentation>The name of a property. 
If the value of the property matches one of the values in the ifvalue list, the contained task will be executed. 
If ifvalue is not set, the contained task will be executed if the ifname property is set to any value. 
If the ifname property is not in the ifvalue list, this Task will return successfully without processing the child task.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="ifvalue" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>A list of values the ifname property must take if the child is to be executed.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:attributeGroup>
	<xs:attributeGroup name="pollAttributes">
		<xs:annotation>
			<xs:documentation>Documentation only: attributes for type=Poll tasks</xs:documentation>
		</xs:annotation>
		<xs:attribute name="duration" type="xs:int" use="optional" default="7200">
			<xs:annotation>
				<xs:documentation>The PollTask polls the child Task every poll seconds for up to duration seconds. It succeeds if the child Task succeeds within the given duration.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="poll" type="xs:int" use="optional" default="60">
			<xs:annotation>
				<xs:documentation>The PollTask polls the child Task every poll seconds for up to duration seconds. It succeeds if the child Task succeeds within the given duration.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:attributeGroup>
	<xs:attributeGroup name="processAttributes">
		<xs:annotation>
			<xs:documentation>Documentation only: attributes for type=Process tasks</xs:documentation>
		</xs:annotation>
		<xs:attribute name="show-error" type="xs:boolean" use="optional" default="true">
			<xs:annotation>
				<xs:documentation>If true, echo the process error stream to stderr.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="show-output" type="xs:boolean" use="optional" default="true">
			<xs:annotation>
				<xs:documentation>If true, echo the process output stream to stdout.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:attributeGroup>
	<xs:attributeGroup name="sqlAttributes">
		<xs:annotation>
			<xs:documentation>Documentation only: attributes for type=SQL tasks</xs:documentation>
		</xs:annotation>
		<xs:attribute name="binds" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>A comma-separated list of bind variables. 
Within the SQL, these will be in the Oracle form 'SQL SQL :bind1 SQL :bind3 SQLSQL :bind2;' with the attribute bind="bind1,bind2,bind3". Unlike parameters, bind variables are not substituted based no position but by name.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="dataSourceName" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>The name of the dataSource to be used. This must match a connection's dataSourceName attribute.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="postcheck" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>The name of a database function to be checked after the main SQL returns successfully. The result will override the script result.
The function signature must be: 
FUNCTION f(run_id IN INTEGER, task IN VARCHAR2) RETURNS INTEGER</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="precheck" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>The name of a database function to be checked before the main SQL is executed. The main SQL will only be executed on success, i.e. 0 is returned.
The function signature must be: 
FUNCTION f(run_id IN INTEGER, task IN VARCHAR2) RETURNS INTEGER</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="statement-split" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>Java regular expression for identifying individual SQL statements in full SQLTask body.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:attributeGroup>
	<xs:complexType name="taskType" mixed="true">
		<xs:annotation>
			<xs:documentation>Basic unit and super-class</xs:documentation>
		</xs:annotation>
		<xs:sequence>
			<xs:element name="connections" type="connectionsType" minOccurs="0"/>
			<xs:element ref="xi:include" minOccurs="0" maxOccurs="2"/>
			<xs:element name="properties" type="propertiesType" minOccurs="0">
				<xs:annotation>
					<xs:documentation>Arbitrary properties</xs:documentation>
				</xs:annotation>
			</xs:element>
			<xs:choice minOccurs="0" maxOccurs="unbounded">
				<xs:element name="task" type="taskType" minOccurs="0" maxOccurs="unbounded">
					<xs:annotation>
						<xs:documentation>Tasks may contain tasks</xs:documentation>
					</xs:annotation>
				</xs:element>
				<xs:element ref="xi:include" minOccurs="0" maxOccurs="unbounded"/>
				<xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded">
					<xs:annotation>
						<xs:documentation>Allow for the possibility of extension and for inclusion of tasks.</xs:documentation>
					</xs:annotation>
				</xs:any>
			</xs:choice>
		</xs:sequence>
		<xs:attribute name="name" use="required">
			<xs:annotation>
				<xs:documentation>The task's identifying name. Usually each task will have a globaly unique name as the check to see whether a task has finished successfully is by run identifier and name only. However, there can be benefits in having duplicate names, e.g. so that a setup script can be called from multiple places. Hence, this is not an ID. </xs:documentation>
			</xs:annotation>
			<xs:simpleType>
				<xs:restriction base="xs:string">
					<xs:whiteSpace value="preserve"/>
				</xs:restriction>
			</xs:simpleType>
		</xs:attribute>
		<xs:attribute name="class" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation> If present, the class value will be used to instantiate a Task object. This allows any class implementing the Task interface to be called. One of the type or the class attributes MUST be set.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="type" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>If present, the type value will imply a class name com.massimo.tools.scriptrunner.work."value"Task. Some types and classes are provided: Serial, Parallel, Pause, Print, Process and SQL. One of the type or the class attributes MUST be set.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="class-path" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>Comma-separated list of jar files to add to the classpath for this Task.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="ignore-error-codes" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>Comma-separated list of integer error codes. Tasks will attempt to ignore these codes.  </xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="log-progress" type="xs:boolean" use="optional" default="true">
			<xs:annotation>
				<xs:documentation>If false, the Task will not  maintain the audit trail log. The script itself must do this.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="parameters" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>List of property names for string substitution. Substitution is performed using the class java.text.MessageFormat, so the order of parameters is important.</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:anyAttribute namespace="##any" processContents="lax">
			<xs:annotation>
				<xs:documentation>Allow for the possibility of extension. Each Task class may have its own set of properties, which may be added here.</xs:documentation>
			</xs:annotation>
		</xs:anyAttribute>
	</xs:complexType>
	<xs:element name="property" type="propertyType">
		<xs:annotation>
			<xs:documentation>Required for validating separate property files.</xs:documentation>
		</xs:annotation>
	</xs:element>
	<xs:element name="properties" type="propertiesType">
		<xs:annotation>
			<xs:documentation>Required for validating separate properties files.</xs:documentation>
		</xs:annotation>
	</xs:element>
	<xs:element name="connection" type="connectionType">
		<xs:annotation>
			<xs:documentation>Required for validating separate connection files.</xs:documentation>
		</xs:annotation>
	</xs:element>
	<xs:element name="connections" type="connectionsType">
		<xs:annotation>
			<xs:documentation>Required for validating separate connections files.</xs:documentation>
		</xs:annotation>
	</xs:element>
	<xs:element name="task">
		<xs:annotation>
			<xs:documentation>The base element, representing what is to be executed and how. Each task element maps directly to a Task object at runtime.</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:complexContent>
				<xs:extension base="taskType"/>
			</xs:complexContent>
		</xs:complexType>
	</xs:element>
</xs:schema>
