Article

Enterprise JavaBeans, A Primer: Part 3, A Tour of the Java Pet Store

Page: 1 2 3

Placing an Order

To purchase a bulldog, for example, follow these steps:

  1. On the home page, select Dogs.
  2. Click Bulldog.
  3. Click Add to Cart in the row for the Male Adult Bulldog.
  4. Click Check Out. A form for your billing and shipping information appears with pre-filled information.
  5. Click Submit.

When you complete the order, the Storefront sends the order info asynchronously to the order processing center (OPC).

Using the Admin Client

To run the administration module, go to http://localhost:8000/admin/. Launch the administrator, and look at the pending and non-pending orders tabs. The bulldog order will be non-pending, because it was less than $500, and all orders under $500 are automatically approved.

Using the Supplier Client

The supplier and its inventory are managed using a simple Web interface. Be sure to first logout of the admin client, before using the supplier.

To manage the supplier and its inventory, go to http://localhost:8000/supplier/. Look around the inventory; click Display Inventory at the home screen. A table shows the quantity of each item in the inventory.

An Analysis of the Pet Store Application

Let's take an in-depth look at the Pet Store application's architecture and expose its structure so we can understand how it's put together. If we can gain enough knowledge and experience, we might be able to use the application as a platform for some self-directed learning about J2EE.

The Java Pet Store Demo consists of the following high-level module:

  • The front page (storefront) presents a typical user interface for a Web application. Customers use the storefront to place orders for pets.
  • The order processing center (OPC) module receives orders from the storefront.
  • The supplier module fulfills orders from the OPC inventory and invoices the OPC.
  • The admin module presents an administrator interface in a JFC/Swing front-end. Administrators use the admin module to examine pending orders and approve or deny them.

Now, let's take a look at the types of EJBs employed by the Pet Store application and the roles they play.

Stateless Session Beans

  • ShoppingClientFacadeLocal – Provides a facade to all of the EJBs related to a shopping client
  • OrderFulfillmentFacade – Facade used by Supplier Order MDB – called every time the supplier gets a PO and will save a PO, try to fulfill an order, create an Invoice for a shipped order, and any other activities needed to fulfil an order when a purchase order arrives
  • AsyncSender – converts shopping cart contents and customer data into an XML message representing an order, and sends the message to the Order Processing Center
  • OrderProcessingCenterAdminFacade – the facade that OPC uses to handle admin client requests
  • ProcessManager – provides methods to view and modify information for a particular order workflow process
  • Catalog – provides a programmatic interface to the catalog
  • SignOn – creates and authenticates system users
  • UniqueIdGenerator – creates globally unique object identifiers

Stateful Session Beans

  • ShoppingController – controls all the shopping activities that happen for a particular client session
  • ShoppingClientFacade – acts as an intercessory between a shopping client and any business-logic objects
  • ShoppingCart – maintains the contents of an individual user's virtual shopping cart

Entity Beans

  • Inventory – represents the inventory for a given item
  • CreditCard – tracks card number, card type, and expiration date
  • Address – tracks two lines of street address, state, zip code, and country
  • ContactInfo – tracks family and given name, telephone, email, and address
  • LineItem – represents line-items in an Invoice
  • PurchaseOrder – represents purchase orders from customers
  • Customer – tracks customer ID (primary key), account, and profile
  • Account – tracks account status, credit card, and contact info
  • Profile – tracks preferred language, category, list preference, and banner preference
  • User – represents a user who may sign on to the system; tracks a user name and password
  • Counter – represents a counter with a specific prefix; used only by UniqueIdGenerator to manage series of unique numbers
  • SupplierOrder – represents orders sent from suppliers

Message-Driven Beans

  • SupplierOrder – processes PurchaseOrders from the Java Pet Store
  • PurchaseOrder – processes PurchaseOrders from the Java Pet Store
  • Invoice – processes Invoices from the Supplier
  • OrderApproval – processes OrderApprovals from the Admin
  • MailInvoice – processes Invoices received from the Supplier
  • MailOrderApproval – processes receiving an Order Approval
  • MailCompletedOrder – processes a completed order
  • Mailer – receives mail messages from the mailer service
  • OPCAdminFacade – exposes the interface for the Admin client from OPC
  • Manager – provides functionality to view and modify sign-on information for a particular manager

The source code for each EJB is located in an ejb directory under the src directory for each module, as in the following:

  • <PETSTORE_INSTALL_DIR>/src/apps/opc/src/com/sun/j2ee/blueprints/opc /ejb
  • <PETSTORE_INSTALL_DIR>/src/apps/opc/src/com/sun/j2ee/blueprints/opc/admin/ejb
  • <PETSTORE_INSTALL_DIR>/src/apps/petstore/src/com/sun/j2ee/blueprints/petstore/controller/ejb
  • <PETSTORE_INSTALL_DIR>/src/apps/supplier/src/com/sun/j2ee/blueprints/supplier/inventory/ejb

Browse around at the source code for each of the EJBs and pay attention to the way the interfaces are used and reused.

Summary

The Pet Store application offers a full-featured demonstration of the J2EE platform and provides a quick start to building any typical Web application or distributed application. The Pet Store's extensive use of EJBs allows business-logic developer's the opportunity to view many types of interactions and uses for the power of the EJB architecture.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links

Rate This Article

  • 1
    Poor
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
    Great

Comment on This Article

Have something to say?

Post A Comment

You need to be a member of the SitePoint Forums to comment on this post. Sign Up

Already a member? Post using your SitePoint Forums account: