<?xml version="1.0" encoding="UTF-8"?>
<process xmlns:blue="http://www.e-marson.com/bluelemon">

  <descriptor>
    <name>com/emarson/lemonade/examples/mobank/Update</name>
    <version>1.0</version>
    <description>
      Calls the network process checking for any updates.
    </description>
    <vendor>E-MARSON</vendor>
  </descriptor>

  <path>

    <!-- ASSOCIATIONS --->

    <!-- association to MainScreen --->
    <action name="action on 'Cancel'">
      <type>general/bluelemon/code</type>
      <definition resultTo="actionForCancel">
        <blue:call node="com/emarson/lemonade/examples/mobank/MainScreen"
                         location="@com/emarson/lemonade/examples/mobank"/>

      </definition>
    </action>
    
    
    <!-- INSTRUCTION --->
    
    <action name="read data, verify and continue">
      <type>general/bluelemon/code</type>
      <definition resultTo="actionForUpdate">

        <!-- retrieve userId --->
        <blue:get node="com/emarson/lemonade/examples/mobank/UserId"
                  location="permanent" toVariable="userId"/>

                  
        <!-- retrieve update number --->
        <blue:get node="com/emarson/lemonade/examples/mobank/UpdateNo"
                  location="permanent" toVariable="updateNo"/>


        <!-- initialize the networking screen --->
        <blue:call node="com/emarson/lemonade/examples/mobank/InitializeDownloading"
                   location="@com/emarson/lemonade/examples/mobank">

          <blue:argument type="String" value="Updating"/>
          <blue:argument type="String" 
                          value="Contacting moBank for any updates..."/>

          <blue:argument type="String" value="Cancel"/>
          <blue:argument type="byteArr" contextKey="actionForCancel"/>          
        </blue:call>

        <blue:try>
        
          <!-- invoke the updating process --->
          <blue:call node="com/emarson/lemonade/examples/mobank/Update"
                     location="network">

            <blue:argument type="variable" name="userId"/>
            <blue:argument type="variable" name="updateNo"/>
          </blue:call>
          
        </blue:try>
        
        <!-- catch the IOException --->
        <blue:catch exception="com/emarson/midp/IOException">

           <!-- go to MainScreen --->
           <blue:call node="com/emarson/lemonade/examples/mobank/MainScreen"
                         location="@com/emarson/lemonade/examples/mobank"/>


           <!-- create the instance of the alert --->
           <blue:newInstance module="com/emarson/lemonade/bluelemon/midp1/Alert"
                             toVariable="alert"/>


          <!-- 
            set its title and text, mark this is a warning alert,
            don't allow it to disappear
           --->

          <blue:call object="alert" method="initialize">
            <blue:argument type="String" value="Networking Problem"/>
            <blue:argument type="String" 
                           value="Can't connect to the Internet."/>

            <blue:argument type="byte" value="AlertType.WARNING"/>
            <blue:argument type="short" value="Alert.FOREVER"/>
          </blue:call>

          <!-- show it to the screen and return --->
          <blue:call manager="GeneralManager" method="setCurrent">
            <blue:argument type="variable" name="alert"/>
          </blue:call>

        </blue:catch>
        
        <!-- finalize the networking screen --->
        <blue:call node="com/emarson/lemonade/examples/mobank/FinalizeDownloading"
                   location="@com/emarson/lemonade/examples/mobank"/>


      </definition>
    </action>

    <!-- return the result --->
    <finish name="done">
      <return>actionForUpdate</return>
    </finish>

  </path>

</process>