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, previously. The directory srcmainjava
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.
We can use the project from the last chapter. If you have already closed it, you can start another temporary session by clicking the following link. Don’t forget that the whole work is volatile unless you sign up to Codenvy and persist the project in your own workspace.
3.1 Account
The domain class Account
represents a bank account. This account could belong to either a campaign or a donor.
package press.turngeek.mycampaign.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 3-1 Account class
3.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 press.turngeek.mycampaign.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 3.2 Donation class
3.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 press.turngeek.mycampaign.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-3 Campaign class
Now we’ve created the domain classes. We’ll look at the internationalization of JSF applications in the next chapter. If you currently use our temporary workspace, please do not close the IDE at this point. We do not provide a new link at the beginning of the next chapter. Please continue with your current project.
Discussion
Use the message board below to give the authors your feedback or to discuss this page’s topic with other readers (in English please!). Please don’t expect the authors to answer directly, but they might update the content of this site according to your feedback.