001: package olstore.session.helper;
002:
003: import java.util.Collection;
004: import java.util.Iterator;
005: import java.util.Vector;
006: import java.util.ArrayList;
007:
008: import olstore.dto.PictureValue;
009:
010: import olstore.entity.ItemLocal;
011: import olstore.entity.ItemLocalHome;
012: import olstore.entity.TypeLocalHome;
013: import olstore.entity.TypeLocal;
014: import olstore.entity.UserLocal;
015: import olstore.entity.UserLocalHome;
016: import olstore.framework.EJBHomeFactory;
017: import olstore.entity.PictureLocalHome;
018: import olstore.entity.PictureLocal;
019:
020: import olstore.session.ShoppingCartLocal;
021: import olstore.session.ShoppingCartLocalHome;
022:
023: import javax.ejb.SessionBean;
024: import javax.ejb.SessionContext;
025: import javax.ejb.CreateException;
026: import javax.activation.DataHandler;
027: import javax.activation.FileDataSource;
028:
029: import java.net.URL;
030: import java.awt.image.BufferedImage;
031: import javax.imageio.ImageIO;
032: import java.net.URLConnection;
033:
034: import javax.xml.soap.MimeHeader; //import javax.xml.rpc.handler.MessageContext;
035: import javax.xml.rpc.handler.soap.SOAPMessageContext;
036: import javax.xml.soap.SOAPMessage;
037: import javax.xml.soap.AttachmentPart;
038:
039: import org.apache.axis.MessageContext;
040: import org.apache.axis.attachments.Attachments;
041: import org.apache.axis.attachments.AttachmentsImpl;
042: import org.apache.axis.Message;
043:
044: /**
045: * @author mwringe
046: *
047: * @ejb.bean name="ShoppingCartHelper" type="Stateless"
048: * view-type="remote-service-endpoint" jndi-name="ShoppingCartRemote"
049: *
050: * @ejb.transaction type="Required"
051: *
052: * -- This is need for JOnAS. If you are not using JOnAS you can safetly remove
053: * the tags below.
054: *
055: * @jonas.bean ejb-name="ShoppingCartHelper" jndi-name="ShoppingCartRemote"
056: * --
057: *
058: */
059: public class ShoppingCartHelperBean implements SessionBean {
060:
061: private SessionContext ejbContext;
062:
063: public void setSessionContext(SessionContext ctx) {
064: ejbContext = ctx;
065: }
066:
067: public void ejbRemove() {
068: }
069:
070: public void ejbCreate() throws CreateException {
071: }
072:
073: public void ejbPassivate() {
074: }
075:
076: public void ejbActivate() {
077: }
078:
079: /**
080: *
081: * @return All items on special (name, description and price)
082: * @throws Exception
083: *
084: * @ejb.interface-method view-type="remote-service-endpoint"
085: * generate="service-endpoint"
086: * service-endpoint-extends="java.rmi.Remote"
087: *
088: */
089: public boolean createAndCheckoutOrder(String name, String pwd,
090: String[][] cartContents) throws Exception {
091: EJBHomeFactory factory = EJBHomeFactory.getInstance();
092: ShoppingCartLocalHome home = (ShoppingCartLocalHome) factory
093: .getLocalHome(EJBHomeFactory.SHOPPINGCART);
094:
095: try {
096: UserLocal user = getUser(name, pwd);
097: if (user == null)
098: return false;
099: ShoppingCartLocal cart = home.create(user);
100:
101: for (int i = 0; i < cartContents.length; i++) {
102: cart.updateQuantity(
103: Integer.valueOf(cartContents[i][0]), Integer
104: .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: }
|