001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.cmp2.commerce;
023:
024: import javax.naming.InitialContext;
025: import javax.ejb.CreateException;
026: import javax.ejb.EntityBean;
027: import javax.ejb.EntityContext;
028:
029: import org.jboss.varia.autonumber.AutoNumberFactory;
030:
031: public abstract class LineItemBean implements EntityBean {
032: transient private EntityContext ctx;
033:
034: public Long ejbCreate() throws CreateException {
035: setId(new Long(AutoNumberFactory.getNextInteger("LineItem")
036: .longValue()));
037: return null;
038: }
039:
040: public void ejbPostCreate() throws CreateException {
041: try {
042: InitialContext jndiContext = new InitialContext();
043:
044: ProductHome ph = (ProductHome) jndiContext
045: .lookup("commerce/Product");
046: Product p = ph.create();
047: } catch (CreateException e) {
048: throw e;
049: } catch (Exception e) {
050: e.printStackTrace();
051: throw new CreateException("hosed");
052: }
053: }
054:
055: public Long ejbCreate(Long id) throws CreateException {
056: setId(id);
057: return null;
058: }
059:
060: public void ejbPostCreate(Long id) throws CreateException {
061: }
062:
063: public Long ejbCreate(Order order) throws CreateException {
064: setId(new Long(AutoNumberFactory.getNextInteger("LineItem")
065: .longValue()));
066: return null;
067: }
068:
069: public void ejbPostCreate(Order order) throws CreateException {
070: order.getLineItems().add((LineItem) ctx.getEJBLocalObject());
071: }
072:
073: public abstract Long getId();
074:
075: public abstract void setId(Long id);
076:
077: public abstract Order getOrder();
078:
079: public abstract void setOrder(Order o);
080:
081: public abstract Product getProduct();
082:
083: public abstract void setProduct(Product p);
084:
085: public abstract int getQuantity();
086:
087: public abstract void setQuantity(int q);
088:
089: public abstract boolean getShipped();
090:
091: public abstract void setShipped(boolean shipped);
092:
093: public void setEntityContext(EntityContext ctx) {
094: this .ctx = ctx;
095: }
096:
097: public void unsetEntityContext() {
098: this .ctx = null;
099: }
100:
101: public void ejbActivate() {
102: }
103:
104: public void ejbPassivate() {
105: }
106:
107: public void ejbLoad() {
108: }
109:
110: public void ejbStore() {
111: }
112:
113: public void ejbRemove() {
114: }
115: }
|