WoEC2.java :  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » jtests » beans » sequence » Java Open Source

Java Open Source » J2EE » JOnAS 4.8.6 
JOnAS 4.8.6 » org » objectweb » jonas » jtests » beans » sequence » WoEC2.java
/*
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 1999 Bull S.A.
 * Contact: jonas-team@objectweb.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id: WoEC2.java 6612 2005-04-22 07:43:55Z durieuxp $
 * --------------------------------------------------------------------------
 */

package org.objectweb.jonas.jtests.beans.sequence;

import java.rmi.RemoteException;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.FinderException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;


public abstract class WoEC2 implements EntityBean {

    protected EntityContext     entityContext;
    private SequenceSesHome     sequenceHome;

    /**
     * Constructs the WorkOrder object
     * @param assId
     * @param qty  Original qty
     */
    public Integer ejbCreate(String assId, int qty) throws CreateException {
        setQty(qty);
        setAssId(assId);
        try {
            SequenceSes sequence = sequenceHome.create();
            setId(new Integer(sequence.nextKey("workorder")));
        } catch (RemoteException e) {
            throw new CreateException("Error on sequence:" + e);
        } catch (FinderException e) {
            throw new CreateException("Error on sequence:" + e);
        }
        return null;
    }

    public void ejbPostCreate(String assemblyId, int origQty) throws CreateException {
    }

    public void ejbRemove() throws RemoveException {}

    public void ejbActivate() {
    }

    public void ejbPassivate() {
    }

    public void ejbLoad() {
    }

    public void ejbStore() {
    }

    public void unsetEntityContext() {
        entityContext = null;
    }

    public void setEntityContext(EntityContext entityContext) {

        Context context = null;

        try {
            context = new InitialContext();
        } catch( Exception e ) {
            e.printStackTrace(System.err);

            throw new EJBException(e);
        }
        this.entityContext = entityContext;

        try {
            sequenceHome =
            (SequenceSesHome) PortableRemoteObject.narrow( context.lookup("java:comp/env/ejb/SequenceSes"),
               SequenceSesHome.class);
        } catch( NamingException e ) {
            e.printStackTrace();
            throw new EJBException("Failure looking up home " + e);
        }
    }

    public abstract Integer getId() ;

    public abstract void setId(Integer id) ;

    public abstract int getQty() ;

    public abstract void setQty(int qty) ;

    public abstract String getAssId() ;

    public abstract void setAssId(String assId) ;

}



java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.