<?xml version="1.0"?>

<!--====================================================================-->
<!-- BAL definition                                                    -->
<!--====================================================================-->

<schema>

	<element name="rule" type="T-rule" />

	<complexType name="T-rule">
		<sequence>
			<element name="bindings" type="T-bindings" minOccurs="0"/>
      <element name="conditions" type="T-conditions" minOccurs="0"/>
			<element name="actions" type="T-actions"/>
			<element name="else-actions" type="T-actions" minOccurs="0"/>
		</sequence>
	</complexType>

	<!-- Type definitions for the bindings -->
	<complexType name="T-bindings">
		<sequence>
			<element name="binding" type="T-binding" minOccurs="1" maxOccurs="unbounded" />
		</sequence>
	</complexType>

	<complexType name="T-binding">
		<sequence>
			<element name="variable" type="T-variable"/>
			<element name="binding" type="T-binding-type"/>
		</sequence>
	</complexType>

	<complexType name="T-variable">
		<simpleContent>
			<restriction base="string"/>
		</simpleContent>
	</complexType>

	<complexType name="T-binding-type">
		<choice>
			<element name="simple" type="T-simple-binding"/>
			<element name="object" type="T-object-binding"/>
			<element name="expression" type="T-expression-binding"/>
		</choice>
	</complexType>

	<complexType name="T-simple-binding">
		<sequence>
			<element name="target" type="T-target"/>
      <element name="tests" type="T-condition-tests" minOccurs="0"/>
		</sequence>
	</complexType>

	<complexType name="T-object-binding">
		<sequence>
			<element name="target" type="T-object-path"/>
			<element name="tests" type="T-condition-tests" minOccurs="0"/>
		</sequence>
	</complexType>

	<complexType name="T-expression-binding">
		<sequence>
			<element name="value" type="T-arithmetic-expression"/>
		</sequence>
	</complexType>

	<complexType name="T-target">
    <choice>
      <element name="class" type="T-class"/>
      <element name="relation-path" type="T-relation-path"/>
    </choice>
	</complexType>

	<complexType name="T-class">
   	<simpleContent>
			<restriction base="string"/>
		</simpleContent>
	</complexType>

  <complexType name="T-relation-path">
    <sequence>
      <element name="member" type="T-relation-member"/>
      <element name="object" type="T-path" minOccurs="0"/>
      <element name="argument" type="T-argument" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
	</complexType>

  <complexType name="T-relation-member">
    <simpleContent>
      <restriction base="string"/>
    </simpleContent>
  </complexType>

	<complexType name="T-object-path">
		<sequence>
			<element name="member" type="T-object-member"/>
			<element name="object" type="T-path" minOccurs="0"/>
			<element name="argument" type="T-argument" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<complexType name="T-object-member">
		<simpleContent>
			<restriction base="string"/>
		</simpleContent>
	</complexType>


	<!-- Type definitions for the conditions -->

	<complexType name="T-exists-condition">
		<sequence>
			<element name="target" type="T-target"/>
			<element name="tests" type="T-condition-tests" minOccurs="0"/>
		</sequence>
	</complexType>

	<complexType name="T-not-condition">
		<sequence>
			<element name="target" type="T-target"/>
			<element name="tests" type="T-condition-tests" minOccurs="0"/>
		</sequence>
	</complexType>

	<complexType name="T-count-condition">
		<sequence>
			<element name="target" type="T-target"/>
			<element name="tests" type="T-condition-tests" minOccurs="0"/>
			<element name="count-test" type="T-count-test"/>
		</sequence>
	</complexType>

	<complexType name="T-count-test">
		<sequence>
			<element name="member" type="T-count-test-member"/>
			<element name="object" type="T-path" minOccurs="0"/>
			<element name="argument" type="T-argument" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<complexType name="T-count-test-member">
		<simpleContent>
			<restriction base="string"/>
		</simpleContent>
	</complexType>

	<!-- Type definitions for the tests in a condition -->

	<complexType name="T-condition-tests">
		<sequence>
			<element name="condition" type="T-condition-test"/>
			<element name="nextcondition" type="T-nextcondition-test" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<complexType name="T-nextcondition-test">
		<sequence>
			<element name="separator" type="T-boolean-separator"/>
			<element name="condition" type="T-condition-test"/>
		</sequence>
	</complexType>

	<complexType name="T-condition-test">
		<sequence>
			<element name="not" type="T-not" minOccurs="0"/>
			<element name="test" type="T-condition-test-term"/>
		</sequence>
	</complexType>

	<complexType name="T-condition-test-term">
		<choice>
			<element name="path" type="T-condition-boolean-path"/>
			<element name="subconditions" type="T-condition-tests"/>
		</choice>
	</complexType>

	<complexType name="T-condition-boolean-path">
		<sequence>
			<element name="member" type="T-condition-boolean-member"/>
			<element name="object" type="T-path" minOccurs="0"/>
			<element name="argument" type="T-argument" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<complexType name="T-condition-boolean-member">
		<simpleContent>
			<restriction base="string"/>
		</simpleContent>
	</complexType>

	<!-- Type definitions for the list of condition -->

	<complexType name="T-conditions">
		<sequence>
			<element name="condition" type="T-condition"/>
			<element name="nextcondition" type="T-nextcondition" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<complexType name="T-nextcondition">
		<sequence>
			<element name="separator" type="T-boolean-separator"/>
			<element name="condition" type="T-condition"/>
		</sequence>
	</complexType>

	<complexType name="T-condition">
		<sequence>
			<element name="not" type="T-not" minOccurs="0"/>
			<element name="test" type="T-test"/>
		</sequence>
	</complexType>

	<complexType name="T-test">
		<choice>
			<element name="test-choice" type="T-test-choice"/>
			<element name="subconditions" type="T-conditions"/>
		</choice>
	</complexType>

	<complexType name="T-test-choice">
		<choice>
			<element name="path" type="T-boolean-path"/>
			<element name="exists-condition" type="T-exists-condition"/>
			<element name="not-condition" type="T-not-condition"/>
			<element name="count-condition" type="T-count-condition"/>
		</choice>
	</complexType>

	<complexType name="T-boolean-separator">
		<choice>
			<element name="and" type="T-keyword" />
			<element name="or" type="T-keyword" />
		</choice>
	</complexType>

	<complexType name="T-not">
	</complexType>


	<!-- Type definitions for boolean tests -->

	<complexType name="T-boolean-path">
		<sequence>
			<element name="member" type="T-boolean-member"/>
			<element name="object" type="T-path" minOccurs="0"/>
			<element name="argument" type="T-argument" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<complexType name="T-path">
		<sequence>
			<element name="member" type="T-member"/>
			<element name="object" type="T-path" minOccurs="0"/>
			<element name="argument" type="T-argument" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<complexType name="T-argument">
		<choice>
			<element name="value" type="T-value"/>
			<element name="path" type="T-argument-path"/>
			<element name="expression" type="T-arithmetic-expression"/>
			<element name="argument-list" type="T-argument-list" />
		</choice>
	</complexType>

	<complexType name="T-argument-path">
		<sequence>
			<element name="member" type="T-argument-member"/>
			<element name="object" type="T-path" minOccurs="0"/>
			<element name="argument" type="T-argument" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<complexType name="T-argument-list">
		<sequence>
			<element name="argument-list-item" type="T-argument" minOccurs="1" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<complexType name="T-member">
		<simpleContent>
			<restriction base="string"/>
		</simpleContent>
	</complexType>

	<complexType name="T-argument-member">
		<simpleContent>
			<restriction base="string"/>
		</simpleContent>
	</complexType>

	<complexType name="T-boolean-member">
		<simpleContent>
			<restriction base="string"/>
		</simpleContent>
	</complexType>

	<complexType name="T-value">
		<simpleContent>
			<restriction base="string"/>
		</simpleContent>
	</complexType>

	<complexType name="T-keyword">
	</complexType>


	<!-- Type definitions for actions -->

	<complexType name="T-actions">
		<sequence>
			<element name="action" type="T-action-choice" minOccurs="1" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<complexType name="T-action-choice">
		<choice>
			<element name="path" type="T-void-path"/>
      <element name="attribute-setter" type="T-attribute-setter"/>
		</choice>
	</complexType>

	<complexType name="T-void-path">
		<sequence>
			<element name="member" type="T-void-member"/>
			<element name="object" type="T-path" minOccurs="0"/>
			<element name="argument" type="T-argument" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<complexType name="T-void-member">
		<simpleContent>
			<restriction base="string"/>
		</simpleContent>
	</complexType>


	<!-- Type definitions for arithmetic expressions -->

	<complexType name="T-arithmetic-expression">
		<sequence>
			<element name="operand" type="T-operand"/>
			<element name="exprRhs" type="T-exprRhs" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<complexType name="T-exprRhs">
		<sequence>
			<element name="operator" type="T-arithmetic-operator"/>
			<element name="operand" type="T-operand"/>
		</sequence>
	</complexType>

	<complexType name="T-operand">
		<sequence>
			<element name="unary" type="T-arithmetic-unary-operator" minOccurs="0"/>
			<element name="term" type="T-term"/>
		</sequence>
	</complexType>

	<complexType name="T-term">
		<choice>
			<element name="termValue" type="T-arithmetic-value"/>
			<element name="subExpression" type="T-arithmetic-expression"/>
		</choice>
	</complexType>

	<complexType name="T-arithmetic-operator">
		<choice>
			<element name="plus" type="T-keyword" />
			<element name="minus" type="T-keyword" />
			<element name="times" type="T-keyword" />
			<element name="divide" type="T-keyword" />
		</choice>
	</complexType>

	<complexType name="T-arithmetic-unary-operator">
	</complexType>

	<complexType name="T-arithmetic-value">
		<choice>
			<element name="value" type="T-numeric-value"/>
			<element name="path" type="T-numeric-path"/>
		</choice>
	</complexType>

	<complexType name="T-numeric-path">
		<sequence>
			<element name="member" type="T-numeric-member"/>
			<element name="object" type="T-path" minOccurs="0"/>
			<element name="argument" type="T-argument" minOccurs="0" maxOccurs="unbounded"/>
		</sequence>
	</complexType>

	<complexType name="T-numeric-member">
		<simpleContent>
			<restriction base="string"/>
		</simpleContent>
	</complexType>

	<complexType name="T-numeric-value">
		<simpleContent>
			<restriction base="string"/>
		</simpleContent>
	</complexType>

  <complexType name="T-attribute-setter">
    <sequence>
      <element name="target" type="T-attribute-path"/>
      <element name="value" type="T-attribute-value-choice"/>
    </sequence>
  </complexType>

  <complexType name="T-attribute-path">
    <sequence>
        <element name="member" type="T-attribute"/>
        <element name="object" type="T-path" minOccurs="0"/>
    </sequence>
  </complexType>

  <complexType name="T-attribute">
      <simpleContent>
        <restriction base="string"/>
      </simpleContent>
  </complexType>

  <complexType name="T-attribute-value-choice">
    <choice>
      <element name="value" type="T-value"/>
      <element name="path" type="T-path"/>
      <element name="expression" type="T-arithmetic-expression"/>
    </choice>
  </complexType>

</schema>