001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: WoEC2.java 6612 2005-04-22 07:43:55Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.beans.sequence;
027:
028: import java.rmi.RemoteException;
029:
030: import javax.ejb.CreateException;
031: import javax.ejb.EJBException;
032: import javax.ejb.EntityBean;
033: import javax.ejb.EntityContext;
034: import javax.ejb.FinderException;
035: import javax.ejb.RemoveException;
036: import javax.naming.Context;
037: import javax.naming.InitialContext;
038: import javax.naming.NamingException;
039: import javax.rmi.PortableRemoteObject;
040:
041: public abstract class WoEC2 implements EntityBean {
042:
043: protected EntityContext entityContext;
044: private SequenceSesHome sequenceHome;
045:
046: /**
047: * Constructs the WorkOrder object
048: * @param assId
049: * @param qty Original qty
050: */
051: public Integer ejbCreate(String assId, int qty)
052: throws CreateException {
053: setQty(qty);
054: setAssId(assId);
055: try {
056: SequenceSes sequence = sequenceHome.create();
057: setId(new Integer(sequence.nextKey("workorder")));
058: } catch (RemoteException e) {
059: throw new CreateException("Error on sequence:" + e);
060: } catch (FinderException e) {
061: throw new CreateException("Error on sequence:" + e);
062: }
063: return null;
064: }
065:
066: public void ejbPostCreate(String assemblyId, int origQty)
067: throws CreateException {
068: }
069:
070: public void ejbRemove() throws RemoveException {
071: }
072:
073: public void ejbActivate() {
074: }
075:
076: public void ejbPassivate() {
077: }
078:
079: public void ejbLoad() {
080: }
081:
082: public void ejbStore() {
083: }
084:
085: public void unsetEntityContext() {
086: entityContext = null;
087: }
088:
089: public void setEntityContext(EntityContext entityContext) {
090:
091: Context context = null;
092:
093: try {
094: context = new InitialContext();
095: } catch (Exception e) {
096: e.printStackTrace(System.err);
097:
098: throw new EJBException(e);
099: }
100: this .entityContext = entityContext;
101:
102: try {
103: sequenceHome = (SequenceSesHome) PortableRemoteObject
104: .narrow(context
105: .lookup("java:comp/env/ejb/SequenceSes"),
106: SequenceSesHome.class);
107: } catch (NamingException e) {
108: e.printStackTrace();
109: throw new EJBException("Failure looking up home " + e);
110: }
111: }
112:
113: public abstract Integer getId();
114:
115: public abstract void setId(Integer id);
116:
117: public abstract int getQty();
118:
119: public abstract void setQty(int qty);
120:
121: public abstract String getAssId();
122:
123: public abstract void setAssId(String assId);
124:
125: }
|