| 1 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 22 public class MoneyTransfer extends Transfer 23 { 24 public static final String TRANSFERTYPEID = "MoneyTransfer"; 25 private Invoice[] invoices; 26 private Currency currency; 27 private long amount; 28 30 protected MoneyTransfer() { } 31 32 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 ("currency must not be null!"); 48 49 if (from instanceof Account) { 50 Account fromAccount = (Account)from; 51 String fromCurrencyID = fromAccount.getCurrency().getCurrencyID(); 52 if (!currency.getCurrencyID().equals(fromCurrencyID)) 53 throw new IllegalArgumentException ("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 toCurrencyID = toAccount.getCurrency().getCurrencyID(); 59 if (!currency.getCurrencyID().equals(toCurrencyID)) 60 throw new IllegalArgumentException ("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 ("Parameter invoices must not be null and has to contain at least one value"); 65 66 this.invoices = invoices; 67 } 68 69 74 public Invoice getInvoice() { 75 return invoices[0]; 76 } 77 78 public Invoice[] getInvoices() { 79 return invoices; 80 } 81 84 public Currency getCurrency() 85 { 86 return currency; 87 } 88 91 public long getAmount() 92 { 93 return amount; 94 } 95 96 } 97 | Popular Tags |