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

  <descriptor>
    <name>com/emarson/lemonade/examples/mobank/_deployment/DownloadingScreenMoAccount</name>
    <version>1.0</version>
    <description>
      This is the instruction used to deliver a special type
      of link when connecting to the network location
      in the moAccount service.
      
      Instead of generating the whole DownloadingScreen
      (that's what happened when moAccount was being delivered
      as a complete MIDlet), it uses two nodes available in 
      the moBank package - one  initializes the downloading 
      screen before the actual networking operation, the 
      other finalizes the downloading screen after the 
      networking operation.
    </description>
    <vendor>E-MARSON</vendor>
  </descriptor>

  <path>
    
    <!-- ASSOCIATIONS --->
    
    <!-- association to MainScreen in mobank/moaccount package --->
    <action name="go to the main screen">
      <type>general/bluelemon/code</type>
      <definition resultTo="goToMainScreen">
        <blue:call node="com/emarson/lemonade/examples/mobank/moaccount/MainScreen"
                         location="@com/emarson/lemonade/examples/mobank/moaccount"/>

      </definition>
    </action>
    
    
    <!-- INSTRUCTION --->
    
    <!-- The whole code to show the downloading screen --->
    <action name="the networking action">
      <type>general/bluelemon/code</type>
      <description>
        This is the procedure which takes two parameters:
         - ammount of money being transferred : int
         - target account number : String
      </description>
      <definition resultTo="networkingAction">

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

          <blue:argument type="String" value="Getting data..."/>
          <blue:argument type="String" value="Network connection..."/>
          <blue:argument type="String" value="Cancel"/>
          <blue:argument type="byteArr" contextKey="goToMainScreen"/>          
        </blue:call>

        <blue:try>

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

            <blue:argument type="variable" name="arg_1"/>
            <blue:argument type="variable" name="arg_2"/>
          </blue:call>
          
        </blue:try>

        <!-- catch the IOException --->
        <blue:catch exception="com/emarson/midp/IOException">

          <!-- create the form and inform the user operation failed --->
          <blue:newInstance module="com/emarson/lemonade/bluelemon/midp1/Form"
                            toVariable="form"/>

                            
          <blue:call object="form" method="initialize">
            <blue:argument type="String" value="Operation failed"/>
          </blue:call>

          <blue:call object="form" method="appendString">
            <blue:argument type="String" value="Due to some networking problems we couldn't proceed. Try again later."/>
          </blue:call>

          <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="goToMainScreen"/>
          </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>

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


      </definition>
    </action>

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

  </path>

</process>