KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > accounting > MoneyTransfer


1 /*
2  * Created on 26.10.2004
3  */

4 package com.nightlabs.ipanema.accounting;
5
6 import com.nightlabs.ipanema.security.User;
7 import com.nightlabs.ipanema.accounting.Invoice;
8 import com.nightlabs.ipanema.transfer.Anchor;
9 import com.nightlabs.ipanema.transfer.Transfer;
10 import com.nightlabs.ipanema.transfer.TransferRegistry;
11
12 /**
13  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
14  *
15  * @jdo.persistence-capable
16  * identity-type = "application"
17  * persistence-capable-superclass = "com.nightlabs.ipanema.transfer.Transfer"
18  * detachable = "true"
19  *
20  * @jdo.inheritance strategy = "new-table"
21  */

22 public class MoneyTransfer extends Transfer
23 {
24     public static final String JavaDoc TRANSFERTYPEID = "MoneyTransfer";
25     private Invoice[] invoices;
26     private Currency currency;
27     private long amount;
28 // private boolean statistical = false; // necessary?!
29

30     protected MoneyTransfer() { }
31
32     /**
33      * @param transferRegistry
34      * @param container
35      * @param initiator
36      * @param from
37      * @param to
38      * @param currency
39      * @param amount
40      */

41     public MoneyTransfer(TransferRegistry transferRegistry, Transfer container,
42             User initiator, Anchor from, Anchor to, Invoice[] invoices, Currency currency, long amount)
43     {
44         super(transferRegistry, TRANSFERTYPEID, container, initiator, from, to);
45
46         if (currency == null)
47             throw new NullPointerException JavaDoc("currency must not be null!");
48
49         if (from instanceof Account) {
50             Account fromAccount = (Account)from;
51             String JavaDoc fromCurrencyID = fromAccount.getCurrency().getCurrencyID();
52             if (!currency.getCurrencyID().equals(fromCurrencyID))
53                 throw new IllegalArgumentException JavaDoc("currency mismatch! From-account \""+from.getPrimaryKey()+"\" has currency \""+fromCurrencyID+"\", but given currency is \""+currency.getCurrencyID()+"\"!");
54         }
55
56         if (to instanceof Account) {
57             Account toAccount = (Account)to;
58             String JavaDoc toCurrencyID = toAccount.getCurrency().getCurrencyID();
59             if (!currency.getCurrencyID().equals(toCurrencyID))
60                 throw new IllegalArgumentException JavaDoc("currency mismatch! To-account \""+to.getPrimaryKey()+"\" has currency \""+toCurrencyID+"\", but given currency is \""+currency.getCurrencyID()+"\"!");
61         }
62         
63         if ((invoices == null) || (invoices.length == 0))
64             throw new IllegalArgumentException JavaDoc("Parameter invoices must not be null and has to contain at least one value");
65             
66         this.invoices = invoices;
67     }
68
69     /**
70      * Returns the first entry from the list of invoices
71      * this MoneyTransfer is assigned to.
72      *
73      */

74     public Invoice getInvoice() {
75         return invoices[0];
76     }
77     
78     public Invoice[] getInvoices() {
79         return invoices;
80     }
81     /**
82      * @return Returns the currency.
83      */

84     public Currency getCurrency()
85     {
86         return currency;
87     }
88     /**
89      * @return Returns the amount.
90      */

91     public long getAmount()
92     {
93         return amount;
94     }
95     
96 }
97
Popular Tags