KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > golfShop > presentation > xmlc > utilities > CartUtils


1 /*
2  * Enhydra Java Application Server
3  * The Initial Developer of the Original Code is Lutris Technologies Inc.
4  * Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies
5  * Inc.
6  * All Rights Reserved.
7  *
8  * The contents of this file are subject to the Enhydra Public License Version
9  * 1.0 (the "License"); you may not use this file except in compliance with the
10  * License. You may obtain a copy of the License at
11  * http://www.enhydra.org/software/license/epl.html
12  *
13  * Software distributed under the License is distributed on an "AS IS" basis,
14  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15  * License for the specific language governing rights and limitations under the
16  * License.
17  *
18  *
19  */

20
21 package golfShop.presentation.xmlc.utilities;
22
23 import java.math.BigDecimal JavaDoc;
24 import java.util.Enumeration JavaDoc;
25
26
27 import golfShop.spec.cart.*;
28
29 import com.lutris.util.*;
30 import com.lutris.appserver.server.session.*;
31 import com.lutris.appserver.server.httpPresentation.*;
32
33 /**
34  * This class provides static functions for formatted output of the
35  * cart contents.
36  */

37 public class CartUtils {
38     
39     private static String JavaDoc FF = "<FONT FACE=\"Arial,Helvetica,C Univers 57 Condensed,Futura Book\" SIZE=\"2\">";
40
41     /**
42      * A CartUtils constructor. Prevent instantiation with a private
43      * constructor.
44      */

45     private CartUtils() {
46     }
47
48     /**
49      * Find the cart object in session. Creating it if it doesn't
50      * exist.
51      */

52     public static Cart getCart(Session session)
53         throws HttpPresentationException {
54         try {
55             Cart cart = (Cart)session.getSessionData().get("cart");
56             if (cart == null) {
57                 
58                Cart car = CartFactory.getCart("golfShop.business.cart.CartImpl");
59     
60                 session.getSessionData().set("cart", car);
61             
62             }
63             return cart;
64 /*
65  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run GolfShop_pres )
66  * We need to allow GolfShop_pres to be functional
67  * so the cart will be null
68  */

69  
70         } catch(NullPointerException JavaDoc ex) {
71              return null;
72         } catch (KeywordValueException except) {
73             throw new HttpPresentationException(except);
74         }
75     }
76
77     /**
78      * Add an item to the cart.
79      */

80     public static void addItem(Session session, long objectId)
81         throws HttpPresentationException {
82
83         Cart cart = getCart(session);
84         cart.addItem(objectId);
85         cart.doneModifying();
86     }
87
88 }
89
Popular Tags