<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/webflow 
  http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">

	<input name="myOrder" required="true" />

	<view-state id="welcome" view="flows/cake1/customer/welcome">
		<transition on="phoneEntered" to="lookupCustomer" />
	</view-state>

	<action-state id="lookupCustomer">
		<evaluate result="myOrder.customer" expression="cakeFlowActions.lookupCustomer(requestParameters.phoneNumber)" />
		<transition on-exception="com.rwd.springFlow4B.cake.service.CustomerNotFoundException" to="registrationForm"/>
		<transition to="customerReady" />
	</action-state>

	<view-state id="registrationForm" model="myOrder" view="flows/cake1/customer/registrationForm">
		<on-entry>
			<evaluate expression="myOrder.customer.phoneNumber = requestParameters.phoneNumber" />
		</on-entry>
		<transition on="submit" to="checkDeliveryArea" />
		<transition on="cancel" to="cancel" />
	</view-state>

	<decision-state id="checkDeliveryArea">
		<if test="cakeFlowActions.checkDeliveryArea(myOrder.customer.zipCode)"
			then="addCustomer" else="deliveryWarning" />
	</decision-state>

	<view-state id="deliveryWarning" view="flows/cake1/customer/deliveryWarning">
		<transition on="accept" to="addCustomer" />
		<transition on="cancel" to="cancel" />
	</view-state>

	<action-state id="addCustomer">
		<evaluate expression="cakeFlowActions.addCustomer(myOrder.customer)" />
		<transition to="customerReady" />
	</action-state>

	<end-state id="cancel" />
	<end-state id="customerReady" />
</flow>
