<?xml version="1.0" encoding="UTF-8"?>
<process xmlns:blue="http://www.e-marson.com/bluelemon">
<descriptor>
<name>com/emarson/lemonade/examples/mobank/pin/NewStartupInstruction</name>
<version>1.0</version>
<description>
The instruction generated by this process will
be used as a new STARTUP_INSTRUCTION if a user decides
to have a PIN number set for the application.
It asks a user to specify a 4-digits PIN number.
If the PIN is OK, user is forwarded to the moBank MainScreen.
User has three chances to make a mistake. After the third
wrong PIN the whole STARTUP_INSTRUCTION is changed to call
AuthenticationScreen in mobank package and user
has to log in specifying the userId and password.
</description>
<vendor>E-MARSON</vendor>
</descriptor>
<path>
<subprocess name="action for 'Exit'">
<source>com/emarson/lemonade/templates/ExitFromApplication</source>
<resultTo>exitAction</resultTo>
</subprocess>
<action name="go to the authentication screen">
<type>general/bluelemon/code</type>
<definition resultTo="goToAuthenticationScreen">
<blue:call node="com/emarson/lemonade/examples/mobank/AuthenticationScreen"
location="@com/emarson/lemonade/examples/mobank"/>
</definition>
</action>
<action name="action for OK">
<type>general/bluelemon/code</type>
<definition resultTo="okAction">
<blue:call manager="GeneralManager" method="getCurrent"
toVariable="form"
castTo="com/emarson/lemonade/bluelemon/midp1/Form"/>
<blue:call object="form" method="getItem"
toVariable="pinField"
castTo="com/emarson/lemonade/bluelemon/midp1/TextField">
<blue:argument type="byte" value="0"/>
</blue:call>
<blue:call object="pinField" method="getString"
toVariable="pin"/>
<blue:get node="com/emarson/lemonade/examples/mobank/pin/PinValue"
location="permanent" toVariable="correctPin"/>
<blue:call manager="UtilsManager" method="equalValues"
toVariable="pinsMatch">
<blue:argument type="variable" name="pin"/>
<blue:argument type="variable" name="correctPin"/>
</blue:call>
<blue:if isTrue="pinsMatch">
<blue:set node="com/emarson/lemonade/examples/mobank/pin/MistakesCounter"
location="permanent">
<blue:argument type="byte" value="0"/>
</blue:set>
<blue:call node="com/emarson/lemonade/examples/mobank/MainScreen"
location="@com/emarson/lemonade/examples/mobank"/>
</blue:if>
<blue:else>
<blue:get node="com/emarson/lemonade/examples/mobank/pin/MistakesCounter"
location="permanent" toVariable="mistakesCounter"/>
<blue:call manager="UtilsManager" method="=="
toVariable="thisIsTheThirdMistake">
<blue:argument type="variable" name="mistakesCounter"/>
<blue:argument type="byte" value="2"/>
</blue:call>
<blue:if isTrue="thisIsTheThirdMistake">
<blue:set node="STARTUP_INSTRUCTION" location="permanent">
<blue:argument type="byteArr" contextKey="goToAuthenticationScreen"/>
</blue:set>
<blue:call manager="ResourcesManager" method="remove">
<blue:argument type="node" location="permanent"
name="com/emarson/lemonade/examples/mobank/pin/PinValue"/>
</blue:call>
<blue:call manager="ResourcesManager" method="remove">
<blue:argument type="node" location="permanent"
name="com/emarson/lemonade/examples/mobank/pin/MistakesCounter"/>
</blue:call>
<blue:call node="com/emarson/lemonade/examples/mobank/AuthenticationScreen"
location="@com/emarson/lemonade/examples/mobank"/>
<blue:newInstance module="com/emarson/lemonade/bluelemon/midp1/Alert"
toVariable="alert"/>
<blue:call object="alert" method="initialize">
<blue:argument type="String" value="PIN error"/>
<blue:argument type="String"
value="Three wrong PIN numbers. Please log in."/>
<blue:argument type="byte" value="AlertType.ERROR"/>
<blue:argument type="short" value="Alert.FOREVER"/>
</blue:call>
<blue:call manager="GeneralManager" method="setCurrent">
<blue:argument type="variable" name="alert"/>
</blue:call>
</blue:if>
<blue:else>
<blue:call manager="UtilsManager" method="++">
<blue:argument type="variable" name="mistakesCounter"/>
</blue:call>
<blue:set node="com/emarson/lemonade/examples/mobank/pin/MistakesCounter"
location="permanent">
<blue:argument type="variable" name="mistakesCounter"/>
</blue:set>
<blue:newInstance module="com/emarson/lemonade/bluelemon/midp1/Alert"
toVariable="alert"/>
<blue:call object="alert" method="initialize">
<blue:argument type="String" value="Wrong PIN"/>
<blue:argument type="String"
value="This PIN number is incorrect."/>
<blue:argument type="byte" value="AlertType.WARNING"/>
<blue:argument type="short" value="1500"/>
</blue:call>
<blue:call manager="GeneralManager" method="setCurrent">
<blue:argument type="variable" name="alert"/>
</blue:call>
</blue:else>
</blue:else>
</definition>
</action>
<action name="screen to specify a PIN number">
<type>general/bluelemon/code</type>
<definition resultTo="result">
<blue:newInstance module="com/emarson/lemonade/bluelemon/midp1/TextField"
toVariable="pinField"/>
<blue:call object="pinField" method="initialize">
<blue:argument type="String" value="Your PIN:"/>
<blue:argument type="String" value=""/>
<blue:argument type="byte" value="4"/>
<blue:argument type="int" value="TextField.NUMERICORPASSWORD"/>
</blue:call>
<blue:newInstance module="com/emarson/lemonade/bluelemon/midp1/Form"
toVariable="form"/>
<blue:call object="form" method="initialize">
<blue:argument type="String" value="moBank PIN"/>
</blue:call>
<blue:call object="form" method="appendItem">
<blue:argument type="variable" name="pinField"/>
</blue:call>
<blue:call manager="UtilsManager" method="getActionCommand"
toVariable="command">
<blue:argument type="String" value="Exit"/>
<blue:argument type="byte" value="ActionCommand.EXIT"/>
<blue:argument type="byte" value="0"/>
<blue:argument type="byteArr" contextKey="exitAction"/>
</blue:call>
<blue:call object="form" method="addCommand">
<blue:argument type="variable" name="command"/>
</blue:call>
<blue:call manager="UtilsManager" method="getActionCommand"
toVariable="command">
<blue:argument type="String" value="OK"/>
<blue:argument type="byte" value="ActionCommand.OK"/>
<blue:argument type="byte" value="0"/>
<blue:argument type="byteArr" contextKey="okAction"/>
</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>
<finish name="done">
<return>result</return>
</finish>
</path>
</process>