KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > olstore > session > helper > ShoppingCartHelperBean


1 package olstore.session.helper;
2
3 import java.util.Collection;
4 import java.util.Iterator;
5 import java.util.Vector;
6 import java.util.ArrayList;
7
8 import olstore.dto.PictureValue;
9
10 import olstore.entity.ItemLocal;
11 import olstore.entity.ItemLocalHome;
12 import olstore.entity.TypeLocalHome;
13 import olstore.entity.TypeLocal;
14 import olstore.entity.UserLocal;
15 import olstore.entity.UserLocalHome;
16 import olstore.framework.EJBHomeFactory;
17 import olstore.entity.PictureLocalHome;
18 import olstore.entity.PictureLocal;
19
20 import olstore.session.ShoppingCartLocal;
21 import olstore.session.ShoppingCartLocalHome;
22
23 import javax.ejb.SessionBean;
24 import javax.ejb.SessionContext;
25 import javax.ejb.CreateException;
26 import javax.activation.DataHandler;
27 import javax.activation.FileDataSource;
28
29 import java.net.URL;
30 import java.awt.image.BufferedImage;
31 import javax.imageio.ImageIO;
32 import java.net.URLConnection;
33
34 import javax.xml.soap.MimeHeader;
35 //import javax.xml.rpc.handler.MessageContext;
36
import javax.xml.rpc.handler.soap.SOAPMessageContext;
37 import javax.xml.soap.SOAPMessage;
38 import javax.xml.soap.AttachmentPart;
39
40 import org.apache.axis.MessageContext;
41 import org.apache.axis.attachments.Attachments;
42 import org.apache.axis.attachments.AttachmentsImpl;
43 import org.apache.axis.Message;
44
45 /**
46  * @author mwringe
47  *
48  * @ejb.bean name="ShoppingCartHelper" type="Stateless"
49  * view-type="remote-service-endpoint" jndi-name="ShoppingCartRemote"
50  *
51  * @ejb.transaction type="Required"
52  *
53  * -- This is need for JOnAS. If you are not using JOnAS you can safetly remove
54  * the tags below.
55  *
56  * @jonas.bean ejb-name="ShoppingCartHelper" jndi-name="ShoppingCartRemote"
57  * --
58  *
59  */

60 public class ShoppingCartHelperBean implements SessionBean {
61
62     private SessionContext ejbContext;
63
64     public void setSessionContext(SessionContext ctx) {
65         ejbContext = ctx;
66     }
67
68     public void ejbRemove() {
69     }
70
71     public void ejbCreate() throws CreateException {
72     }
73
74     public void ejbPassivate() {
75     }
76
77     public void ejbActivate() {
78     }
79
80     /**
81      *
82      * @return All items on special (name, description and price)
83      * @throws Exception
84      *
85      * @ejb.interface-method view-type="remote-service-endpoint"
86      * generate="service-endpoint"
87      * service-endpoint-extends="java.rmi.Remote"
88      *
89      */

90     public boolean createAndCheckoutOrder(String name, String pwd,
91             String[][] cartContents) throws Exception {
92         EJBHomeFactory factory = EJBHomeFactory.getInstance();
93         ShoppingCartLocalHome home = (ShoppingCartLocalHome) factory
94                 .getLocalHome(EJBHomeFactory.SHOPPINGCART);
95
96         try {
97             UserLocal user = getUser(name, pwd);
98             if (user == null)
99                 return false;
100             ShoppingCartLocal cart = home.create(user);
101
102             for (int i = 0; i < cartContents.length; i++) {
103                 cart.updateQuantity(Integer.valueOf(cartContents[i][0]),
104                         Integer.valueOf(cartContents[i][1]));
105
106             }
107             cart.createOrders();
108         } catch (Exception e) {
109             return false;
110         }
111
112         return true;
113
114     }
115
116     private UserLocal getUser(String name, String pwd) throws Exception {
117         EJBHomeFactory factory = EJBHomeFactory.getInstance();
118         UserLocalHome userHome = (UserLocalHome) factory
119                 .getLocalHome(EJBHomeFactory.USER);
120         UserLocal user = userHome.findByUsername(name);
121         if (user.getPasswd().equals(pwd)) {
122             return user;
123
124         } else
125             return null;
126     }
127 }
128
Popular Tags