## ---------------------------------------------------------------------------
## JOnAS: Java(TM) Open Application Server
## Copyright (C) 1999-2004 Bull S.A.S.
## 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
##
## Initial developer(s): Philippe Durieux, Helene Joanin.
## Contributor(s):
##
## ---------------------------------------------------------------------------
## $Id$
## ---------------------------------------------------------------------------

// This class is the bean specific part of JSessionLocalHome for Stateful Sessions
// Generated by GenIC via Velocity. Do not edit directly this file.
// Start: $Id$

#if ($package.length() != 0)
package $package;
#end

import java.lang.Error;
import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.RemoveException;
import javax.ejb.SessionBean;
import org.ow2.jonas.lib.ejb21.RequestCtx;
import org.ow2.jonas.lib.ejb21.JFactory;
import org.ow2.jonas.lib.ejb21.JSessionContext;
import org.ow2.jonas.lib.ejb21.JSessionFactory;
import org.ow2.jonas.lib.ejb21.JSessionLocalHome;
import org.ow2.jonas.lib.ejb21.ha.JRepStatefulLocalHome;
import org.ow2.jonas.lib.ejb21.JSessionLocal;
import org.ow2.jonas.lib.ejb21.JStatefulContext;
import org.ow2.jonas.lib.ejb21.JStatefulFactory;
import org.ow2.jonas.lib.ejb21.JStatefulSwitch;
import org.ow2.jonas.lib.ejb21.TraceEjb;
import org.ow2.jonas.deployment.ejb.MethodDesc;
import org.ow2.jonas.deployment.ejb.SessionDesc;
import org.ow2.jonas.lib.ejb21.EJBInvocation;

import org.objectweb.util.monolog.api.BasicLevel;

#if ($isClusterReplicated)
public class $class extends JRepStatefulLocalHome implements $localhome {
#else
public class $class extends JSessionLocalHome implements $localhome {
#end

    // JOnAS version used to deploy
    public static final String JONAS_VERSION = "$jVersion";

    /**
     * Created by JSessionFactory (by newInstance)
     */
    public $class(SessionDesc dd, JSessionFactory bf) {
        super(dd, bf);
    }

#foreach ($M in $methodList)

#if ($M.isCreate())

    /**
     * create method
     */
    public $M.getReturnType() $M.getName()($M.getFormalParameters())
#if ( $M.getExceptionList().length() > 0 )
        throws $M.getExceptionList()
#end
        {
            //TraceEjb.interp.log(BasicLevel.DEBUG, "");
            EJBInvocation ejbInv = new EJBInvocation();
            ejbInv.methodPermissionSignature = "$M.getSecuritySignature()";
            ejbInv.arguments = $M.getArrayObjectParameters();
            RequestCtx rctx = preInvoke(MethodDesc.TX_NOT_SET);
            JStatefulSwitch bs = null;
            JSessionFactory sf = (JSessionFactory) bf;
            try {
                bs = (JStatefulSwitch) sf.createEJB();
                JSessionContext bctx = sf.getJContext(bs);
                rctx.ejbContext = bctx;
                bs.bindICtx(rctx.currTx, (JStatefulContext) bctx);
                $bean_wrp b = ($bean_wrp) bctx.getInstance();
                ejbInv.bean = b;
                checkSecurity(ejbInv);
                rctx.bmcalled = true;
                b.ejb$M.getCapName()($M.getActualParameters());
                bctx.setActive();
                bs.saveOpenResources();
            } catch (javax.ejb.AccessLocalException e) {
                throw new EJBException("Security Exception thrown by an enterprise Bean", e);
            } catch (EJBException e) {
                rctx.sysExc = e;
                throw e;
            } catch (RuntimeException e) {
                rctx.sysExc = e;
                throw new EJBException("RuntimeException thrown by an enterprise Bean", e);
            } catch (Error e) {
                rctx.sysExc = e;
                throw new EJBException("Error thrown by an enterprise Bean"+e);
            } catch (RemoteException e) {
                rctx.sysExc = e;
                throw new EJBException("Remote Exception raised:", e);
            } finally {
                postInvoke(rctx);
            }
#if ($isClusterReplicated)
        replicateCreate(bs);
#end
            return ($local) bs.getLocal();
        }

#end

#end

    public JSessionLocal createLocalObject() {
        return new $local_wrp((JStatefulFactory)bf);
    }
}
// End: $Id$
