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

  <descriptor>
    <name>com/emarson/lemonade/examples/mobank/UpdateIsRequired</name>
    <version>1.0</version>
    <description>
      Process the code and inform the user what happened
      in the "Update info" message form.
    </description>
    <vendor>E-MARSON</vendor>
  </descriptor>
  
  <arguments>
    <!-- this is the main update instruction --->
    <argument key="mainCode" type="String"/>
    <argument key="updateNo" type="Integer"/>  
  </arguments>
  
  <path>
  
    <!-- ASSOCIATIONS --->

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

      </definition>
    </action>
    
  
    <!-- INSTRUCTION --->
    
    <!-- 
      Prepare the action which will be invoked before mainCode 
      is processed 
    --->

    <action name="before invoking the update code">
      <type>general/bluelemon/code</type>
      <definition resultTo="beforeCode">
      
        <!-- set the new update number --->
        <blue:set node="com/emarson/lemonade/examples/mobank/UpdateNo"
                  location="permanent">

          <blue:argument type="int" contextKey="updateNo"/>
        </blue:set>
        
        <!-- set the initial value of the UpdateInfo node --->
        <blue:set node="com/emarson/lemonade/examples/mobank/UpdateInfo"
                  location="session">

          <blue:argument type="String" value="Message from moBank:"/>
        </blue:set>

      </definition>
    </action>

    <!-- 
      Prepare the action which will be invoked after 
      mainCode is processed 
    --->

    <action name="after invoking the update code">
      <type>general/bluelemon/code</type>
      <definition resultTo="afterCode">
        
        <!-- get the text we need to show --->
        <blue:get node="com/emarson/lemonade/examples/mobank/UpdateInfo"
                  location="session" toVariable="text"/>

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


        <!-- initialize it --->
        <blue:call object="form" method="initialize">
          <blue:argument type="String" value="Update Info"/>
        </blue:call>

        <!-- set the text --->
        <blue:call object="form" method="appendString">
          <blue:argument type="variable" name="text"/>
        </blue:call>
        
        <!-- add the command to get back to the menu --->
        <blue:call manager="UtilsManager" method="getActionCommand"
                   toVariable="command">

          <blue:argument type="String" value="Back"/>
          <blue:argument type="byte" value="ActionCommand.BACK"/>
          <blue:argument type="byte" value="0"/>
          <blue:argument type="byteArr" contextKey="backAction"/>
        </blue:call>

        <blue:call object="form" method="addCommand">
          <blue:argument type="variable" name="command"/>
        </blue:call>

        <blue:call manager="GeneralManager" method="setCurrent">
          <blue:argument type="variable" name="form"/>
        </blue:call>

      </definition>
    </action>
    
    <!-- Merge mainCode with the rest --->
    <action name="merge the code">
      <type>general/bcl</type>
      <definition>
        result = beforeCode + mainCode + afterCode;
      </definition>
    </action>

    <finish name="done">
      <return>result</return>
    </finish>

  </path>

</process>