View Javadoc

1   package org.sourceforge.jemm.sample.demo1.model;
2   
3   import org.sourceforge.jemm.lifecycle.ConstructorLifecycle;
4   import org.sourceforge.jemm.lifecycle.ShadowUserObject;
5   import org.sourceforge.jemm.util.JEMMObject;
6   
7   public class Account implements JEMMObject {
8   
9       // Added by the compiler
10      protected ShadowUserObject jemmOIF;
11  
12      double                 balance;
13  
14      /**
15       * Create a new account with an initial balance of 0.
16       * 
17       * Enhanced constructor with begin and end marking points.
18       */
19      public Account() {
20      	ConstructorLifecycle.preConstructor(Account.class.getName());
21          ConstructorLifecycle.beginConstructor(this);
22          try {
23          	this.balance = 0;
24          	ConstructorLifecycle.endConstructor(this);
25          } catch(Throwable t) {
26          	ConstructorLifecycle.failedConstructor(this);
27          	//would in the real program throw t not a RuntimeException
28          	throw new RuntimeException(t);
29          }
30      }
31  
32      /**
33       * Generated by the compiler and used internally for creating an object.
34       * 
35       * @param jemmOIF The shadow object this object uses to talk to the store.
36       */
37      public Account(ShadowUserObject jemmOIF) {
38          this.jemmOIF = jemmOIF;
39      }
40  
41      /**
42       * Create a new account with the given initial balance.
43       * 
44       * @param initialBalance The initial account balance.
45       */
46      public Account(double initialBalance) {
47          ConstructorLifecycle.beginConstructor(this);
48          try {
49          	this.balance = initialBalance;
50          	ConstructorLifecycle.endConstructor(this);
51          } catch(Throwable t) {
52          	ConstructorLifecycle.failedConstructor(this);
53          	//would in the real program throw t not a RuntimeException
54          	throw new RuntimeException(t);
55          }
56      }
57  
58      /**
59       * Returns the balance on the account.
60       * 
61       * This is just a renamed method from getBalance.
62       * 
63       * @return The balance of the account.
64       */
65      public double getBalance() {
66          jemmOIF.entityEntered("org.sourceforge.jemm.sample.demo1.model.Account#getBalance ()D");
67          jemmOIF.beginLock();
68          try {
69              return balance;
70          } finally {
71              jemmOIF.endLock();
72              jemmOIF.entityExited("org.sourceforge.jemm.sample.demo1.model.Account#getBalance ()D");
73          }
74      }
75  
76      /**
77       * Deposit the given about into the account, increasing the balance.
78       * 
79       * @param amount The amount to deposit.
80       */
81      public void deposit(double amount) {
82          jemmOIF.entityEntered("org.sourceforge.jemm.sample.demo1.model.Account#deposit (D)V");
83          jemmOIF.beginLock();
84          try {
85              balance += amount;
86          } finally {
87              jemmOIF.endLock();
88              jemmOIF.entityExited("org.sourceforge.jemm.sample.demo1.model.Account#deposit (D)V");
89          }
90      }
91  }