1 7 package xpetstore.web.webwork.action.cart; 8 9 import java.util.ArrayList ; 10 import java.util.Collection ; 11 import java.util.Iterator ; 12 import java.util.Map ; 13 14 import cirrus.hibernate.Session; 15 16 import xpetstore.domain.Item; 17 import xpetstore.domain.OrderItem; 18 19 import xpetstore.web.webwork.action.BaseAction; 20 21 22 25 public abstract class BaseCartAction 26 extends BaseAction 27 { 28 30 private Collection _cartItems; 31 32 34 39 public Collection getCartItems( ) 40 throws Exception 41 { 42 Session s = null; 43 Map cart = getCart( ); 44 45 try 46 { 47 if ( _cartItems == null ) 48 { 49 _cartItems = new ArrayList ( ); 50 51 if ( cart.size( ) > 0 ) 52 { 53 s = getHibernateSession( ); 54 55 Iterator it = cart.keySet( ).iterator( ); 56 57 while ( it.hasNext( ) ) 58 { 59 String itemId = ( String ) it.next( ); 60 Integer quantity = ( Integer ) cart.get( itemId ); 61 Item item = ( Item ) s.load( Item.class, itemId ); 62 63 _cartItems.add( new OrderItem( item, quantity.intValue( ) ) ); 64 } 65 } 66 } 67 68 return _cartItems; 69 } 70 catch ( Exception e ) 71 { 72 e.printStackTrace( ); 73 throw e; 74 } 75 finally 76 { 77 if ( s != null ) 78 { 79 s.close( ); 80 } 81 } 82 } 83 } 84 | Popular Tags |