Java Reference
In-Depth Information
The events Project
Events are one of the core components of Duke's Forest. The events project, included
in all three of the main projects, is the most simple project of the application. It has only
one class, OrderEvent , but this class is responsible for most of the messages between
objects in the application.
The application can send messages based on events to different components and react to
them based on the qualification of the event. The application supports the following qual-
ifiers:
@LoggedIn : For authenticated users
@New : When a new order is created by the shopping cart
@Paid : When an order is paid for and ready for shipment
The following code snippet from the PaymentHandler class of Duke's Store shows
how the @Paid event is handled:
Click here to view code image
@Inject @Paid Event<OrderEvent> eventManager;
...
public void onNewOrder(@Observes @New OrderEvent event) {
if (processPayment(convertForWS(event))) {
orderBean.setOrderStatus(event.getOrderID(),
OrderBean.Status.PENDING_PAYMENT.getStatus());
logger.info("Payment Approved");
eventManager.fire(event);
} else {
orderBean.setOrderStatus(event.getOrderID(),
OrderBean.Status.CANCELLED_PAYMENT.getStatus())
logger.info("Payment Denied");
}
}
...
To enable users to add more events to the project easily or update an event class with more
fields for a new client, this component is a separate project within the application.
The entities Project
The entities project is a Java Persistence API (JPA) project used by both Duke's Store
and Duke's Shipment. It is generated from the database schema shown in Figure 27-3 and
Search WWH ::




Custom Search