[jboss-cvs] JBossAS SVN: r62951 - projects/aop/trunk/aop/docs/examples/beforeafter.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed May 9 22:20:40 EDT 2007


Author: flavia.rainone at jboss.com
Date: 2007-05-09 22:20:40 -0400 (Wed, 09 May 2007)
New Revision: 62951

Added:
   projects/aop/trunk/aop/docs/examples/beforeafter/NoSuchAccountException.java
Modified:
   projects/aop/trunk/aop/docs/examples/beforeafter/Bank.java
   projects/aop/trunk/aop/docs/examples/beforeafter/Parser.java
Log:
[JBAOP-44] Bank application updated to make it more similar to the one used in finally example.

Modified: projects/aop/trunk/aop/docs/examples/beforeafter/Bank.java
===================================================================
--- projects/aop/trunk/aop/docs/examples/beforeafter/Bank.java	2007-05-10 01:06:12 UTC (rev 62950)
+++ projects/aop/trunk/aop/docs/examples/beforeafter/Bank.java	2007-05-10 02:20:40 UTC (rev 62951)
@@ -46,27 +46,28 @@
    }
    
    public Transaction getDepositTransaction(String accountName)
+      throws NoSuchAccountException
    {
       return new Deposit(getAccount(accountName));
    }
    
    public Transaction getWithdrawalTransaction(String accountName)
+      throws NoSuchAccountException
    {
       return new Withdrawal(getAccount(accountName));
    }
    
    public Transaction getWireTransferTransaction(String fromAccountName,
-         String toAccountName)
+         String toAccountName) throws NoSuchAccountException
    {
       return new WireTransfer(getAccount(fromAccountName), getAccount(toAccountName));
    }
    
-   private Account getAccount(String name)
+   private Account getAccount(String name) throws NoSuchAccountException
    {
       if (!accounts.containsKey(name))
       {
-         System.err.println("Account named '" + name + "' does not exist.");
-         System.exit(1);
+         throw new NoSuchAccountException("Account named '" + name + "' does not exist.");
       }
       return accounts.get(name);
    }

Added: projects/aop/trunk/aop/docs/examples/beforeafter/NoSuchAccountException.java
===================================================================
--- projects/aop/trunk/aop/docs/examples/beforeafter/NoSuchAccountException.java	                        (rev 0)
+++ projects/aop/trunk/aop/docs/examples/beforeafter/NoSuchAccountException.java	2007-05-10 02:20:40 UTC (rev 62951)
@@ -0,0 +1,29 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+public class NoSuchAccountException extends Exception
+{
+   public NoSuchAccountException(String message)
+   {
+      super(message);
+   }
+}

Modified: projects/aop/trunk/aop/docs/examples/beforeafter/Parser.java
===================================================================
--- projects/aop/trunk/aop/docs/examples/beforeafter/Parser.java	2007-05-10 01:06:12 UTC (rev 62950)
+++ projects/aop/trunk/aop/docs/examples/beforeafter/Parser.java	2007-05-10 02:20:40 UTC (rev 62951)
@@ -62,41 +62,47 @@
          // read first string
          String accountName = readAccountName(line, "an operation");
          Transaction transaction = null;
-         
-         // if first string contains a transfer (A->B, for example)
-         int transferIndex = accountName.indexOf("->");
-         if (transferIndex != -1)
+         try
          {
-            // create wire transfer
-            String fromAccountName = accountName.substring(0, transferIndex);
-            String toAccountName = accountName.substring(transferIndex + 2);
-            transaction = bank.getWireTransferTransaction(fromAccountName, toAccountName);
-         }
-         else
-         {
-            // create deposit or withdrawal
-            switch(line.charAt(++index))
+            // if first string contains a transfer (A->B, for example)
+            int transferIndex = accountName.indexOf("->");
+            if (transferIndex != -1)
             {
-               case '+':
-                  transaction = bank.getDepositTransaction(accountName);
-                  break;
-               case '-':
-                  transaction = bank.getWithdrawalTransaction(accountName);
-                  break;
-               default:
-                  System.err.println("Unexpected character at line " + lineNumber +
-                  ". Should be \'+\' or \'-\', to indicate deposit and withdrawal transactions, respectively.");
-               System.exit(1);
-
+               // create wire transfer
+               String fromAccountName = accountName.substring(0, transferIndex);
+               String toAccountName = accountName.substring(transferIndex + 2);
+               transaction = bank.getWireTransferTransaction(fromAccountName, toAccountName);
             }
+            else
+            {
+               // create deposit or withdrawal
+               switch(line.charAt(++index))
+               {
+                  case '+':
+                     transaction = bank.getDepositTransaction(accountName);
+                     break;
+                  case '-':
+                     transaction = bank.getWithdrawalTransaction(accountName);
+                     break;
+                  default:
+                     System.err.println("Unexpected character at line " + lineNumber +
+                     ". Should be \'+\' or \'-\', to indicate deposit and withdrawal transactions, respectively.");
+                  System.exit(1);
+               }
+            }
+            // read and set transaction amount
+            double amount = readAmount(line);
+            transaction.setAmount(amount);
+            
+            // add transaction to collection
+            transactions.add(transaction);
          }
+         catch(NoSuchAccountException e)
+         {
+            System.out.println("ERROR invalid transaction: " + e.getMessage());
+         }
          
-         // read and set transaction amount
-         double amount = readAmount(line);
-         transaction.setAmount(amount);
          
-         // add transaction to collection
-         transactions.add(transaction);
          
          lineNumber ++;
          line = reader.readLine().trim();




More information about the jboss-cvs-commits mailing list