java qr code An aspect that implements the rule for enforcing a minimum balance in Java

Create QR Code 2d barcode in Java An aspect that implements the rule for enforcing a minimum balance

Listing 12.11 An aspect that implements the rule for enforcing a minimum balance
Making Quick Response Code In Java
Using Barcode generation for Java Control to generate, create QR Code image in Java applications.
www.OnBarcode.com
Recognizing QR-Code In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
package rule.java; import rule.common.*; import banking.*; public aspect MinimumBalanceRuleAspect extends AbstractDebitRulesAspect {
Barcode Drawer In Java
Using Barcode drawer for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
Code 39 Full ASCII Encoder In Java
Using Barcode generation for Java Control to generate, create Code 39 Full ASCII image in Java applications.
www.OnBarcode.com
Example: the banking system
Create Code 128 Code Set C In Java
Using Barcode printer for Java Control to generate, create Code 128C image in Java applications.
www.OnBarcode.com
Printing 1D In Java
Using Barcode generation for Java Control to generate, create 1D Barcode image in Java applications.
www.OnBarcode.com
private static final float MINIMUM_BALANCE_REQD = 25; public float SavingsAccount.getAvailableBalance() { return getBalance() - MINIMUM_BALANCE_REQD; } pointcut savingsDebitExecution(Account account, float withdrawalAmount) : debitExecution(account, withdrawalAmount) && this(SavingsAccount); before(Account account, float withdrawalAmount) throws InsufficientBalanceException : savingsDebitExecution(account, withdrawalAmount) { if (account.getAvailableBalance() < withdrawalAmount) { throw new InsufficientBalanceException( "Minimum balance condition not met"); } } }
Make Barcode In Java
Using Barcode creation for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
European Article Number 8 Creator In Java
Using Barcode generation for Java Control to generate, create UPC - 8 image in Java applications.
www.OnBarcode.com
We introduce the getAvailableBalance() method in SavingsAccount, overriding the method introduced into the Account interface by the base aspect. This method reduces the available balance by MINIMUM_BALANCE_REQD. The savingsDebitExecution() pointcut captures the execution of debit transactions in the SavingsAccount interface. It uses the debitExecution() pointcut defined in the base aspect and restricts it with the this(SavingsAccount) pointcut. This restriction causes the pointcut to match only SavingsAccount transactions. The before advice to savingsDebitExecution() throws an InsufficientBalanceException exception if the available balance is less than the requested withdrawal amount. 12.5.3 Implementing the second business rule The second business rule we consider is overdraft protection. In natural language the new rule reads: If a check could not be cleared and if there is a sufficient balance in an overdraft account, clear the check by transferring the required amount from that overdraft account to the checking account. Note that the rule specifies that the application of the overdraft protection rule is only for transactions initiated by the check clearance system. Transactions
QR Code Maker In C#.NET
Using Barcode printer for VS .NET Control to generate, create Denso QR Bar Code image in .NET applications.
www.OnBarcode.com
Recognizing QR Code ISO/IEC18004 In Visual Studio .NET
Using Barcode scanner for .NET framework Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Implementing business rules
DataMatrix Generation In Objective-C
Using Barcode generation for iPhone Control to generate, create ECC200 image in iPhone applications.
www.OnBarcode.com
Scanning PDF417 In Visual Basic .NET
Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
initiated in other ways should not be affected by this rule. For example, if a customer attempts to withdraw an amount from an ATM that exceeds the balance, it will not trigger overdraft protection; instead, the ATM displays the message that the balance is not sufficient. The aspect in listing 12.12 implements the overdraft protection rule by capturing the debit transaction on the checking account that was initiated by the check clearance system. The aspect captures the check clearance join point and performs the overdraft protection logic if the balance in the checking account is not sufficient.
Generate ANSI/AIM Code 39 In None
Using Barcode creator for Software Control to generate, create Code39 image in Software applications.
www.OnBarcode.com
Draw Linear Barcode In C#
Using Barcode generation for .NET Control to generate, create 1D image in VS .NET applications.
www.OnBarcode.com
Listing 12.12 An aspect that implements the overdraft protection rule
Recognize Barcode In C#.NET
Using Barcode Control SDK for Visual Studio .NET Control to generate, create, read, scan barcode image in VS .NET applications.
www.OnBarcode.com
Decode Barcode In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
package rule.java; import java.util.*; import banking.*; import rule.common.*; public aspect OverdraftProtectionRuleAspect extends AbstractDebitRulesAspect { pointcut checkClearanceTransaction() : execution(* CheckClearanceSystem.*(..));
Paint Linear In VB.NET
Using Barcode maker for .NET framework Control to generate, create 1D image in Visual Studio .NET applications.
www.OnBarcode.com
Generate PDF 417 In Java
Using Barcode maker for Eclipse BIRT Control to generate, create PDF-417 2d barcode image in BIRT reports applications.
www.OnBarcode.com
Pointcut for check clearance system transactions
Make PDF-417 2d Barcode In C#.NET
Using Barcode generation for Visual Studio .NET Control to generate, create PDF417 image in .NET framework applications.
www.OnBarcode.com
Decoding PDF-417 2d Barcode In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
pointcut checkingDebitExecution(Account account, float withdrawalAmount) : debitExecution(account, withdrawalAmount) && this(CheckingAccount);
Pointcut for debit transaction in the checking account
before(Account account, float withdrawalAmount) throws InsufficientBalanceException Overdraft : checkingDebitExecution(account, withdrawalAmount) protection && cflow(checkClearanceTransaction()) { advice if (account.getAvailableBalance() < withdrawalAmount) { performOverdraftProtection(account, withdrawalAmount); } } private void performOverdraftProtection(Account account, float withdrawalAmount) throws InsufficientBalanceException { float transferAmountNeeded = withdrawalAmount - account.getAvailableBalance(); Customer customer = account.getCustomer(); Collection overdraftAccounts = customer.getOverdraftAccounts(); for (Iterator iter = overdraftAccounts.iterator();
Example: the banking system
iter.hasNext();) { Account overdraftAccount = (Account)iter.next(); if (overdraftAccount == account) { continue; } Overdraft
protection logic
if (transferAmountNeeded < overdraftAccount.getAvailableBalance()) { overdraftAccount.debit(transferAmountNeeded); account.credit(transferAmountNeeded); return; } } throw new InsufficientBalanceException( "Insufficient funds in overdraft accounts"); } }
b c d
Let s examine the implementation in more detail: The checkClearanceTransaction() pointcut captures the call to any method in the CheckClearanceSystem class. This pointcut excludes calls that are made to the account transaction from other systems, such as an ATM system. The checkingDebitExecution() pointcut restricts the debitExecution() pointcut to checking accounts only. The before() advice uses the cflow() pointcut to advise all debitExecution() methods that occurred in the control flow of the checkClearanceTransaction() pointcut. (This use of cflow() is modeled after the wormhole pattern that we studied in chapter 8.) This results in the advice being applied only to debit() methods executed during a check clearance process, thus ignoring transactions initiated from other systems. If the available balance is less than that withdrawal amount, the advice performs the overdraft protection logic by calling the performOverdraftProtection() method. The performOverdraftProtection() method performs the core logic of overdraft protection. If the account balance is not enough to cover the amount of the check, the method checks to see if one of the overdraft accounts has enough to cover it. If such an account is found, the advice transfers the required amount to the checking account. If no overdraft account has sufficient funds, we throw an InsufficientBalanceException. For simplicity, our overdraft protection does not consider partial withdrawals from multiple accounts to fulfill a request. In a non-AOP solution, implementing the logic so that it checks for debit actions performed through the check clearance system is quite a task. There are multiple ways to achieve the goal, each with its own set of issues. One way would be to
Copyright © OnBarcode.com . All rights reserved.