<process name="ordersProcess" 
  targetNamespace="urn:echo:echoService"
  xmlns:tns="urn:echo:echoService"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
  
  <partnerLinks>
    <partnerLink name="ordering" partnerLinkType="orderLnk"
                 myRole="orderService" />      
    <partnerLink name="warehouse" partnerLinkType="warehouseLnk"
                 myRole="orderService" 
                 partnerRole="warehouseService" />      
  </partnerLinks>

  <variables>
    <variable name="order" messageType="tns:OrderMessage"/>
    <variable name="invoice" messageType="tns:InvoiceMessage"/>
  </variables>
  
  <faultHandlers>
    <catch faultName="tns:orderCancelled">
      <wait name="wait_catch" />
    </catch>
  </faultHandlers>

  <sequence name="main">
    <receive name="init" portType="tns:orderService" partnerLink="ordering"
      operation="order" variable="order" createInstance="yes" />
    <switch name="switch"> 
      <case condition="bpws:getVariableData('order', 'urgent')">
	<invoke name="urgent_req" portType="tns:warehouse"
                partnerLink="warehouseLnk"
                operation="order" inputVariable="order" 
                outputVariable="invoice" />
      </case>
      <otherwise>
	<sequence>
	  <invoke name="schedule" partnerLink="warehouse"
                  portType="tns:warehouse"
                  operation="schedule" inputVariable="order" />
          <pick>
            <onMessage portType="tns:warehouseCallback" 
                       partnerLink="warehouse"
                       operation="receive_not" variable="invoice">
              <empty />
            </onMessage>
            <onAlarm name="timeout" for="P5D">
              <invoke name="urgent_req2" portType="tns:warehouse"
                       partnerLink="warehouse"
                       operation="order" inputVariable="order" 
                       outputVariable="invoice" />
            </onAlarm>
          </pick>
        </sequence>
      </otherwise>
    </switch>
    <scope name="end">
      <reply partnerLink="ordering" portType="tns:orderService" 
             operation="order" variable="invoice" />
    </scope>
  </sequence>

</process>
