<%-- * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. --%> <%@page import="openbook.server.OpenBookService"%> <%@page import="openbook.domain.Book"%> <%@page import="openbook.domain.ShoppingCart"%> <%@page import="openbook.domain.PurchaseOrder"%> <%@page import="openbook.domain.LineItem"%> <%@page import="java.util.Map"%> <%@page import="java.util.List"%> <%@page import="openbook.util.JSPUtility"%> <%@include file="header.jsp"%>

Composite Pattern and Derived Identity

You have just created a new Purchase Order . Each Book in the Shopping Cart is turned into separate line item for the order and the Purchase Order and all its line items are inserted as new database records. All this happened with this few lines of Java Code
<% OpenBookService service = (OpenBookService)session.getAttribute(KEY_SERVICE); ShoppingCart cart = (ShoppingCart)session.getAttribute(KEY_CART); PurchaseOrder order = service.placeOrder(cart); %> Purchase Order ID : <%= order.getId() %>
Placed on : <%= JSPUtility.format(order.getPlacedOn()) %>
<% int i = 0; List items = order.getItems(); for (LineItem item : items) { %> <% } %>
<%= order.getItems().size() %> items
Title QuantityPrice
Continue Shopping
<%= item.getBook().getTitle() %> <%= item.getQuantity() %> <%= JSPUtility.format(item.getBook().getPrice() * item.getQuantity()) %>
Total <%= JSPUtility.format(order.getTotal()) %>
<%@include file="footer.jsp"%>