FileDocCategorySizeDatePackage
BaseCartAction.javaAPI DocJBoss 4.2.12043Fri Jul 13 20:55:42 BST 2007xpetstore.web.webwork.action.cart

BaseCartAction

public abstract class BaseCartAction extends xpetstore.web.webwork.action.BaseAction
author
Herve Tchepannou

Fields Summary
private Collection
_cartItems
Constructors Summary
Methods Summary
public java.util.CollectiongetCartItems()
Returns all the {@link xpetstore.web.cart.CartItem}s

return
Collection
throws
Exception

        Session s = null;
        Map     cart = getCart(  );

        try
        {
            if ( _cartItems == null )
            {
                _cartItems = new ArrayList(  );

                if ( cart.size(  ) > 0 )
                {
                    s = getHibernateSession(  );

                    Iterator it = cart.keySet(  ).iterator(  );

                    while ( it.hasNext(  ) )
                    {
                        String  itemId = ( String ) it.next(  );
                        Integer quantity = ( Integer ) cart.get( itemId );
                        Item    item = ( Item ) s.load( Item.class, itemId );

                        _cartItems.add( new OrderItem( item, quantity.intValue(  ) ) );
                    }
                }
            }

            return _cartItems;
        }
        catch ( Exception e )
        {
            e.printStackTrace(  );
            throw e;
        }
        finally
        {
            if ( s != null )
            {
                s.close(  );
            }
        }