KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > trade > LegalEntity


1 /*
2  * Created on 27.10.2004
3  */

4 package com.nightlabs.ipanema.trade;
5
6 import javax.jdo.JDOHelper;
7 import javax.jdo.PersistenceManager;
8
9 import com.nightlabs.ipanema.accounting.Accountant;
10 import com.nightlabs.ipanema.accounting.InterLegalEntityMoneyTransfer;
11 import com.nightlabs.ipanema.accounting.IntraLegalEntityMoneyTransfer;
12 import com.nightlabs.ipanema.accounting.MoneyTransfer;
13 import com.nightlabs.ipanema.person.Person;
14 import com.nightlabs.ipanema.store.ProductTransfer;
15 import com.nightlabs.ipanema.transfer.Anchor;
16 import com.nightlabs.ipanema.transfer.Transfer;
17
18 /**
19  * @author Marco Schulze - marco at nightlabs dot de
20  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
21  *
22  * @jdo.persistence-capable
23  * identity-type = "application"
24  * persistence-capable-superclass = "com.nightlabs.ipanema.transfer.Anchor"
25  * detachable = "true"
26  *
27  * @jdo.inheritance strategy = "new-table"
28  */

29 public class LegalEntity extends Anchor
30 {
31
32     public LegalEntity() { }
33     /**
34      * @param organisationID
35      * @param anchorID
36      */

37     public LegalEntity(String JavaDoc organisationID, String JavaDoc anchorID)
38     {
39         super(organisationID, anchorID);
40     }
41
42     /**
43      * @jdo.field persistence-modifier="persistent"
44      */

45     private Person person;
46
47     /**
48      * @jdo.field persistence-modifier="persistent"
49      */

50     private Accountant accountant;
51
52     protected void bookMoneyTransfer(PersistenceManager pm, MoneyTransfer transfer)
53     {
54         if (accountant == null)
55             throw new NullPointerException JavaDoc("There is no accountant existing in this LegalEntity (\""+this.getPrimaryKey()+"\")!");
56         
57         if (transfer instanceof InterLegalEntityMoneyTransfer)
58             accountant.bookTransfer(this,transfer);
59         else if (transfer instanceof IntraLegalEntityMoneyTransfer) {
60             // Do nothing but the super implementation
61
// the other anchor should be an account.
62
}
63
64 // Accounting accounting = Accounting.getAccounting(pm);
65
// Anchor from;
66
// Anchor to;
67
// switch (transfer.getAnchorType(this)) {
68
// case Transfer.ANCHORTYPE_FROM:
69
// from = account;
70
// to = this;
71
// break;
72
// case Transfer.ANCHORTYPE_TO:
73
// from = this;
74
// to = account;
75
// break;
76
// default:
77
// throw new IllegalStateException("This should never happen!");
78
// }
79
// InterLegalEntityMoneyTransfer interLegalEntityMoneyTransfer;
80
// if (transfer instanceof InterLegalEntityMoneyTransfer)
81
// interLegalEntityMoneyTransfer = (InterLegalEntityMoneyTransfer)transfer;
82
// else if (transfer instanceof IntraLegalEntityMoneyTransfer)
83
// interLegalEntityMoneyTransfer = ((IntraLegalEntityMoneyTransfer)transfer).getInterLegalEntityMoneyTransfer();
84
// else
85
// throw new IllegalArgumentException("transfer is neither InterLegalEntityMoneyTransfer nor IntraLegalEntityMoneyTransfer, but "+transfer.getClass().getName()+"!");
86

87 // MoneyTransfer localForwardTransfer = new IntraLegalEntityMoneyTransfer(
88
// accounting, transfer, from, to, this, interLegalEntityMoneyTransfer, transfer.getCurrency(), transfer.getAmount());
89
// from.bookTransfer(localForwardTransfer);
90
// to.bookTransfer(localForwardTransfer);
91
}
92     
93     
94     protected void bookProductTransfer(PersistenceManager pm, ProductTransfer transfer)
95     {
96         
97     }
98     
99     /**
100      * @see com.nightlabs.ipanema.transfer.Anchor#internalBookTransfer(com.nightlabs.ipanema.transfer.Transfer)
101      */

102     protected void internalBookTransfer(Transfer transfer)
103     {
104         PersistenceManager pm = JDOHelper.getPersistenceManager(this);
105         if (pm == null)
106             throw new NullPointerException JavaDoc("This instance of LegalEntity is not linked to a PersistenceManager! Cannot call this method while being detached.");
107
108         if (transfer instanceof MoneyTransfer) {
109             bookMoneyTransfer(pm, (MoneyTransfer)transfer);
110         }
111         else if (transfer instanceof ProductTransfer) {
112             bookProductTransfer(pm, (ProductTransfer)transfer);
113         }
114         else
115             throw new IllegalArgumentException JavaDoc("unsupported Transfer type: "+transfer.getClass().getName());
116     }
117
118     
119 }
120
Popular Tags