KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > pets > Visit


1 package org.apache.tapestry.pets;
2
3 import java.io.Serializable JavaDoc;
4 import java.math.BigDecimal JavaDoc;
5 import java.util.Hashtable JavaDoc;
6
7 import johnmammen.betterpetshop.service.PetshopManager;
8
9 import org.apache.tapestry.IRequestCycle;
10 import org.apache.tapestry.listener.ListenerMap;
11 import org.apache.tapestry.pets.domain.model.ICustomer;
12 import org.apache.tapestry.pets.domain.model.IItem;
13 import org.apache.tapestry.pets.domain.model.IShoppingCart;
14 import org.apache.tapestry.pets.domain.model.pojo.BasketItem;
15 import org.apache.tapestry.pets.domain.model.pojo.ShoppingCart;
16 import org.springframework.web.context.WebApplicationContext;
17 import org.springframework.web.context.support.WebApplicationContextUtils;
18
19 public class Visit implements Serializable JavaDoc {
20
21     private transient Hashtable JavaDoc orderInformation;
22
23     private transient ListenerMap listeners = null;
24
25     private IShoppingCart userCart;
26
27     private ICustomer customer;
28
29     private String JavaDoc bannerpath;
30
31     public ListenerMap getListeners() {
32         if (listeners == null) {
33             listeners = new ListenerMap(this);
34         }
35
36         return listeners;
37     }
38
39     public boolean isUserLoggedIn() {
40         return customer != null;
41     }
42
43     public IShoppingCart getUserCart() {
44         return userCart;
45     }
46
47     public void setUserCart(IShoppingCart userCart) {
48         this.userCart = userCart;
49     }
50
51     public void directAddItemToCart(IRequestCycle cycle) {
52         Object JavaDoc[] parameters = cycle.getServiceParameters();
53         String JavaDoc itemToAdd = ((String JavaDoc) parameters[0]);
54         //
55
PetshopManager petManager=null;
56         try {
57             WebApplicationContext appcontext = WebApplicationContextUtils
58                     .getWebApplicationContext(//getRequestCycle()
59
cycle.getRequestContext().getServlet()
60                             .getServletContext());
61             petManager = (PetshopManager) appcontext.getBean("petshopService");
62         }catch(Exception JavaDoc e){
63             
64         }
65         
66         //IItem item = Products.getItem(getItemID(), getUserLanguage());
67
IItem item = petManager.getItem(itemToAdd);
68         //
69

70         //IItem item = Products.getItem(itemToAdd, getLanguage());
71
BigDecimal JavaDoc price = item.getListprice();
72         int qty = item.getQty();
73         String JavaDoc itemName = item.getProduct().getProductdetail().getName();
74         boolean inStock = (qty > 0) ? true : false;
75
76         // add new item to cart
77
if (userCart == null) {
78             userCart = new ShoppingCart();
79         }
80
81         userCart.add(new BasketItem(itemToAdd, itemName, inStock, 1, price));
82
83         // display the udpated cart
84
cycle.activate("Cart");
85     }
86
87     public Hashtable JavaDoc getOrderInformation() {
88         return orderInformation;
89     }
90
91     public void setOrderInformation(Hashtable JavaDoc shoppingAddressSession) {
92         this.orderInformation = shoppingAddressSession;
93     }
94
95     public String JavaDoc getLanguage() {
96         return PetConstants.DEFAULT_LANGUAGE;
97     }
98
99     public boolean getListOptions() {
100         return false ;
101     }
102
103     public boolean getBannerOptions() {
104         return false;
105 // return (getCustomer() == null) ? false : getCustomer().getProfile()
106
// .getBannerOpt();
107
}
108
109     public String JavaDoc getFavoriteCategory() {
110         return null;
111 // return (getCustomer() == null) ? null : getCustomer().getProfile()
112
// .getFavCategory();
113
}
114
115     public ICustomer getCustomer() {
116         return customer;
117     }
118
119     public void setCustomer(ICustomer customer) {
120         this.customer = customer;
121     }
122
123     public String JavaDoc getBannerpath() {
124         return bannerpath;
125     }
126
127     public void setBannerpath(String JavaDoc bannerpath) {
128         this.bannerpath = bannerpath;
129     }
130
131 }
Popular Tags