4.2 Domain Classes as JavaBeans

No new technology is required for the implementation of domain classes. The domain classes can be developed as ordinary JavaBeans. During implementation, we will adhere to the specifications laid out in section 3.3. The directory src\main\java already exists within the structure of our project. In it will be  stored the directory structures for the packages and the sources of the Java classes for the entire project. The domain classes are required for all use cases.

4.2.1 Account

The domain class Account represents a bank account. This account could belong to either a campaign or a donor.

package de.dpunkt.myaktion.model;

public class Account {
	private String name;
	private String nameOfBank;
	private String iban;

	public Account() {
		this(null, null, null);
	}
	public Account(String name, String nameOfBank, String iban) {
		super();
		this.name = name;
		this.nameOfBank = nameOfBank;
		this.iban = iban;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getNameOfBank() {
		return nameOfBank;
	}
	public void setNameOfBank(String nameOfBank) {
		this.nameOfBank = nameOfBank;
	}
	public String getIban() {
		return iban;
	}
	public void setIban(String iban) {
		this.iban = iban;
	}
}

Listing 4-1     Account class

4.2.2 Donation

The Donation class represents a donation to a campaign. A donation can be in one of two states: in process, or already transferred. An inner enumeration class (enum Status) is therefore defined in the Donation class to represent the status of the donation. Within the Donation class, the elements of the type can be addressed directly with the name of the enumeration Status. The enumeration is public to enable access from outside the classes.

package de.dpunkt.myaktion.model;
public class Donation {
	private Double amount;
	private String donorName;
	private Boolean receiptRequested;
	private Status status;
	private Account account;

	public enum Status {
		TRANSFERRED, IN_PROCESS;
	}
	public Donation() {
		this.account = new Account();
	}
	public Double getAmount() {
		return amount;
	}
	public void setAmount(Double amount) {
		this.amount = amount;
	}
	public String getDonorName() {
		return donorName;
	}
	public void setDonorName(String donorName) {
		this.donorName = donorName;
	}
	public Boolean getReceiptRequested() {
		return receiptRequested;
	}
	public void setReceiptRequested(Boolean receiptRequested) {
		this.receiptRequested = receiptRequested;
	}
	public Status getStatus() {
		return status;
	}
	public void setStatus(Status status) {
		this.status = status;
	}
	public Account getAccount() {
		return account;
	}
	public void setAccount(Account account) {
		this.account = account;
	}
}

Listing 4.2     Donation class

4.2.3 Campaign

A donation campaign is described by the class Campaign. The class uses a list represented by the generic interface java.util.List<E> to implement the 1:n relation to the class Donation. The Donation class is specified for the element type E to make it possible to check at compile time whether all objects stored in the list are compatible with the Donation class. The setter method setDonations can be used to assign a concrete list and therefore also a concrete instance of an implementation class (e.g. java.util.LinkedList) belonging to the interface List.

package de.dpunkt.myaktion.model;
import java.util.List;

public class Campaign {
	private String name;
	private Double targetAmount;
	private Double donationMinimum;
	private Double amountDonatedSoFar;
	private Account account;
	private Long id;
	private List<Donation> donations;

	public Campaign() {
		account = new Account();
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Double getTargetAmount() {
		return targetAmount;
	}
	public void setTargetAmount(Double targetAmount) {
		this.targetAmount = targetAmount;
	}
	public Double getDonationMinimum() {
		return donationMinimum;
	}
	public void setDonationMinimum(Double donationMinimum) {
		this.donationMinimum = donationMinimum;
	}
	public Double getAmountDonatedSoFar() {
		return amountDonatedSoFar;
	}
	public void setAmountDonatedSoFar(Double amountDonatedSoFar) {
		this.amountDonatedSoFar = amountDonatedSoFar;
	}
	public Account getAccount() {
		return account;
	}
	public void setAccount(Account account) {
		this.account = account;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Long getId() {
		return id;
	}
	public List<Donation> getDonations() {
		return donations;
	}
	public void setDonations(List<Donation> donations) {
		this.donations = donations;
	}
}

Listing 3     Campaign class

Now we’ve created the domain classes, we’ll look at the internationalization of JSF applications.