<drafts>

   <!-- Coordination choreography -->
    <!-- THIS IS NOT SELF CONSISTENT - cut and paste from credit check not sorted -->
    <choreography name="Coordination" root="false" coordinated="true">
        <relationship type="tns:CoordinatorParticipant"/>
        <variableDefinition>
            <variable name="state" silentAction="true"/>
        </variableDefinition>
        
        <!-- the normal work - receive the request and decide whether to approve -->
        <sequence>
            <interaction channelVariable="tns:coordination" operation="propagate" initiateChoreography="true">
                <participate relationship="supinf" fromRole="tns:Superior" toRole="Inferior"/>
            </interaction>
            <choice>
                <sequence>
                    <interaction channelVariable="tns:coordination" operation="prepared" initiateChoreography="false">
                	    <participate relationship="supinf" fromRole="tns:Inferior" toRole="Superior"/>
            	    </interaction>
            	</sequence>
           		<throwException name="refused/>
            </choice>
        </sequence>
        
        <!-- catch the exception - as an exception it will abort the choreography and the 
             finalizers are not accessible -->
        <exception>
       		<interaction channelVariable="tns:coordination" operation="refused" initiateChoreography="false">
           		<participate relationship="supinf" fromRole="tns:Inferior" toRole="Superior"/>
       		</interaction>
        </exception>
        
        <!-- what to do if the decision is to confirm -->
        <finalizer case="confirm">
            <interaction channelVariable="tns:coordination" operation="confirm" initiateChoreography="false">
                <participate relationship="supinf" fromRole="tns:Superior" toRole="Inferior"/>
            </interaction>
        </finalizer>
        
        <!-- what to do if the decision is to cancel -->
        <finalizer case="cancel" default="true">
            <interaction channelVariable="tns:coordination" operation="cancel" initiateChoreography="false">
                <participate relationship="supinf" fromRole="tns:Superior" toRole="Inferior"/>
            </interaction>
        </finalizer>
    </choreography>




    <!-- CreditCheck choreography -->
    <choreography name="CreditCheck" root="false" coordinated="true">
        <relationship type="tns:CreditReqCreditResp"/>
        <variableDefinition>
            <variable name="CreditExtended" informationType="xsd:int" silentAction="true" roleType="tns:CreditResponder" />
            
            <!-- these two were in S R-T's August draft, but I don't know why -->
            <variable name="Requestor" informationType="tns:channelType" silentAction="true"/>
            <variable name="Responder" informationType="tns:channelType" silentAction="true"/>
        </variableDefinition>
        
        <!-- the normal work - receive the request and decide whether to approve -->
        <sequence>
            <interaction channelVariable="tns:CreditRequestor" operation="creditRequest" initiateChoreography="true">
                <participate relationship="xyz" fromRole="tns:Requestor" toRole="Responder"/>
            </interaction>
            <choice>
                <!-- the credit checker determines whether credit is allowed by means invisible -->
                <sequence>
                    <!-- it is good - remember that -->
            	    <interaction channelVariable="tns:CreditResponder" operation="creditAuthorized" initiateChoreography="false">
                	    <participate relationship="xyz" fromRole="tns:Responder" toRole="Requestor"/>
                	    <record when="before">
                	        <source value="offered"/>
                	        <target variable="CreditExtended"/>
                	    </record>
            	    </interaction>
            	</sequence>
           		<throwException name="badCredit"/>
            </choice>
        </sequence>
        
        <!-- catch the (application) exception - as an exception it will abort the choreography and the 
             finalizers are not accessible -->
        <exception>
       		<interaction channelVariable="tns:CreditResponder" operation="creditDenied" initiateChoreography="false">
           		<participate relationship="xyz" fromRole="tns:Responder" toRole="Requestor"/>
       		</interaction>
        </exception>
        
        <!-- what to do if the credit is drawn down -->
        <finalizer case="confirm">
            <!-- if there is no application content to send, this could just be an 
                 assignment to the statecapturevariable creditExtended -->
            <interaction channelVariable="tns:CreditRequestor" operation="drawDown" initiateChoreography="false">
                <participate relationship="xyz" fromRole="tns:Requestor" toRole="Responder"/>
        	    <record when="before">
        	        <source value="drawnDown"/>
        	        <target variable="CreditExtended"/>
        	    </record>
            </interaction>
        </finalizer>
        
        <!-- what to do if the credit is not used -->
        <finalizer case="cancel" default="true">
            <!-- if there is no application content to send, this could just be an 
                 assignment to the statecapturevariable creditExtended -->
            <interaction channelVariable="tns:CreditRequestor" operation="replenish" initiateChoreography="false">
                <participate relationship="xyz" fromRole="tns:Requestor" toRole="Responder"/>
        	    <record when="before">
        	        <source value="released"/>
        	        <target variable="CreditExtended"/>
        	    </record>
            </interaction>
        </finalizer>
    </choreography>





 <!-- ====================================================== -->

<choreography name="CoordinatedCreditCheck" root="false">
    <parallel>
        <!-- declare roles, messages and variables -->
        <perform choreographyName="Coordination">
        <bind>
            <!-- bind the roles -->
            <!-- bind the operations -->
            <!-- bind the variables -->
        </bind>
        </perform>
        <perform choreographyName="CreditCheck">
            <!-- bind the roles -->
            <!-- bind the operations -->
            <!-- bind the variables -->
        </perform>
    </parallel>
</choreography>

<choreography name="Enclosing" root="true">

    <!-- only a snippet shown -->
    <sequence>
    
        <!--  other stuff here -->
        <parallel>
            <perform name="checkCreditForA" choreographyName="CoordinatedCreditCheck">
                <!-- bind such that this does the business for A -->
            </perform>
            <perform name="checkCreditForA" choreographyName="CoordinatedCreditCheck">
                <!-- bind such that this does the business for A -->
            </perform>
        </parallel>
        
        <!--  other stuff here -->
    
        <choice>
            <!--  events have occurred such that A is chosen -->
            <parallel>
                <finalize name="checkCreditForA" case="confirm"/>
                <finalize name="checkCreditForB" case="cancel"/>
            </parallel>
            
            
            <!--  events have occurred such that B  is chosen  -->
            <parallel>
                <finalize name="checkCreditForA" case="cancel"/>
                <finalize name="checkCreditForA" case="confirm"/>
            </parallel>

            <!--  events have occurred such that neither is chosen -->
            <parallel>
                <finalize name="checkCreditForA" case="cancel"/>
                <finalize name="checkCreditForA" case="cancel"/>
            </parallel>
        </choice>
    
        <!-- if the number of sellers is determined by the data, the name attribute in the
             perform's and finalize's will have to be capable of being set from a variable
             with some kind of loop, perhaps -->
     
    </sequence>

</choreography>

</drafts>