/*
 * 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$
 * --------------------------------------------------------------------------
 */

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

import java.rmi.RemoteException;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.InitialContext;
import javax.naming.NamingException;


/**
 * This class is WoSesSL seesion bean.
 *
 * This bean is stateless.
 *
 */
public class WoSesSL implements SessionBean {

    private String           className = "WoSesSL";
    private WoHomeLocal woHome;
    private SequenceSesHome sequenceSesHome;
    /**
     * Method ejbCreate
     *
     *
     * @throws CreateException
     *
     */
    public void ejbCreate() throws CreateException {
    }
    /**
     * Method schedule
     * @param assId
     * @param qty
     * @return Woid
     * @exception EJBException if there is a system failure
     */
    public Integer schedule(String assId, int qty) {


        WoLocal wo;
        Integer woId = null;

        try {
            wo = woHome.create(assId, qty);
            woId = wo.getId();

        } catch( CreateException e ) {
            throw new EJBException("Unable to create " + e);
        } catch( EJBException e ) {
            e.printStackTrace();
            throw new EJBException(e);
        }
        return woId;
    }
    

    /**
     * Constructor WoSesSL
     *
     *
     */
    public WoSesSL() {
    }

    /**
     * Method ejbRemove
     *
     *
     */
    public void ejbRemove() {
    }

    /**
     * Method ejbActivate
     *
     *
     */
    public void ejbActivate() {
    }

    /**
     * Method ejbPassivate
     *
     *
     */
    public void ejbPassivate() {
    }

    /**
     * Method setSessionContext
     *
     *
     * @param sc
     *
     */
    public void setSessionContext(SessionContext sc) {

        InitialContext initCtx;

        try {
            initCtx       = new InitialContext();
            woHome = (WoHomeLocal) initCtx.lookup("java:comp/env/ejb/WoLocalHome");
            sequenceSesHome =
                (SequenceSesHome) javax.rmi.PortableRemoteObject.narrow(
                                                                       initCtx.lookup("SequencesHome"),
                                                                       SequenceSesHome.class);
        } catch( NamingException e ) {
            e.printStackTrace();

            throw new EJBException(e);
        }

    }
}

