<?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-1.0.xsd">

  <start-state idref="init"/>

  <action-state id="init">
    <action bean="account.mailAddrChangeAction" method="init"/>
    <transition to="form"/>
  </action-state>

  <view-state id="form" view="account.MailAddrChangeForm">
    <render-actions>
      <action bean="account.mailAddrChangeAction" method="setupForm"/>
    </render-actions>
    <transition on="submit" to="authenticate">
      <action bean="account.mailAddrChangeAction" method="bindAndValidate"/>
    </transition>
  </view-state>

  <subflow-state id="authenticate" flow="account/authentication-sub-flow">
    <transition on="finish" to="mailSendOrNot"/>
  </subflow-state>

  <decision-state id="mailSendOrNot">
    <if test="${flowScope.sendMail}" then="mailSend" else="mailNotSend"/>
  </decision-state>

  <action-state id="mailSend">
    <action bean="account.mailAddrChangeAction" method="changeMailAddrAndReissuePassword"/>
    <transition on="success" to="mailSendFinish"/>
    <transition on-exception="org.unitedfront2.domain.MailAddrUsedByOtherException" to="form"/>
  </action-state>

  <action-state id="mailNotSend">
    <action bean="account.mailAddrChangeAction" method="changeMailAddr"/>
    <transition on="success" to="mailNotSendFinish"/>
    <transition on-exception="org.unitedfront2.domain.MailAddrUsedByOtherException" to="form"/>
  </action-state>

  <end-state id="mailSendFinish" view="account.MailAddrChangeSuccess"/>

  <end-state id="mailNotSendFinish" view="account.MailAddrChangeSuccessNotSendMail"/>

</flow>
