## ---------------------------------------------------------------------------
## JOnAS: Java(TM) Open Application Server
## Copyright (C) 1999-2008 Bull S.A.
## Contact: jonas-team@objectweb.org
## Copyright (C) 2006 Distributed Systems Lab.
## Universidad Politecnica de Madrid (Spain)
## Contact: http://lsd.ls.fi.upm.es/lsd
##
## 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.
## Contributor(s):
## Francisco Perez-Sorrosal (fpsorrosal@no-spam@fi.upm.es)
## Alberto Paz-Jimenez (apaz@no-spam@fi.upm.es)
## S. Ali Tokmen, Malek Chahine: EJB statistics
##
## ---------------------------------------------------------------------------
## $Id: JStatefulLocal.vm 14503 2008-07-10 15:13:06Z chahinem $
## ---------------------------------------------------------------------------

// This class is the bean specific part of JSessionLocal
// Generated by GenIC via Velocity. Do not edit directly this file.
// Start: $Id: JStatefulLocal.vm 14503 2008-07-10 15:13:06Z chahinem $

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

import java.lang.Error;
import java.lang.RuntimeException;
import java.util.Date;
import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.RemoveException;
import org.ow2.jonas.lib.ejb21.JSessionContext;
import org.ow2.jonas.lib.ejb21.JSessionFactory;
import org.ow2.jonas.lib.ejb21.JSessionLocal;
import org.ow2.jonas.lib.ejb21.ha.JRepStatefulLocal;
import org.ow2.jonas.lib.ejb21.RequestCtx;
import org.ow2.jonas.lib.ejb21.TraceEjb;
import org.ow2.jonas.lib.ejb21.EJBInvocation;
import org.ow2.jonas.lib.ejb21.MonitoringEvent;
import org.objectweb.util.monolog.api.BasicLevel;


#if ($isClusterReplicated)
public class $class extends JRepStatefulLocal implements $local {
#else
public class $class extends JSessionLocal implements $local {
#end

    /**
     * Constructor
     */
    public $class(JSessionFactory bf) {
        super(bf);
    }

#foreach ($M in $methodList)

#if ($M.isRemoveThis())

    /**
     * remove this bean instance
     */
    public void remove() throws RemoveException {
        //TraceEjb.interp.log(BasicLevel.DEBUG, "");
        EJBInvocation ejbInv = new EJBInvocation();
        ejbInv.methodPermissionSignature = "$M.getSecuritySignature()";
        ejbInv.arguments = $M.getArrayObjectParameters();

        RequestCtx rctx = preInvoke($M.getTxAttribute());
        checkSecurity(ejbInv);

        try {
            JSessionContext bctx = bs.getICtx(rctx.currTx);
            rctx.bmcalled = true;
            bctx.setRemoved();
        } 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 {
#if ($isClusterReplicated)
/* ******************REPLICATION CODE STARTS HERE*********************** */
            // There is no response to the client (void parameter needed by HA)
            postInvoke(rctx, true);
/* **********************END OF REPLICATION CODE************************ */
#else
            postInvoke(rctx);
#end
       

	   }
    }

#else

    public $M.getReturnType() $M.getName()($M.getFormalParameters())
#if ( $M.getExceptionList().length() > 0 )
    throws $M.getExceptionList()
#end
    {
        #timerVariablesDeclaration()
        #getRequestStartTime()
        //TraceEjb.interp.log(BasicLevel.DEBUG, "");
#if ($M.getReturnType() != "void")
        $M.getReturnType() result;
#end

#if ($isClusterReplicated)
/* ******************REPLICATION CODE STARTS HERE*********************** */
        // Inject the state if found on HA tables
        injectState();
/* **********************END OF REPLICATION CODE************************ */
#end

        EJBInvocation ejbInv = new EJBInvocation();
        ejbInv.methodPermissionSignature = "$M.getSecuritySignature()";
        ejbInv.arguments = $M.getArrayObjectParameters();

        RequestCtx rctx = preInvoke($M.getTxAttribute());
        try {
            JSessionContext bctx = bs.getICtx(rctx.currTx);
            $bean_wrp b = ($bean_wrp) bctx.getInstance();
            ejbInv.bean = b;
            checkSecurity(ejbInv);
            rctx.bmcalled = true;
            #getBusinessStartTime()
            
#if ($M.getReturnType() != "void")
            result =
#end
                b.$M.getName()($M.getActualParameters());
        } 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 {
        #getBusinessStopTime()
#if ($isClusterReplicated)
/* ******************REPLICATION CODE STARTS HERE*********************** */
            postInvoke(rctx, false);
/* **********************END OF REPLICATION CODE************************ */
#else
            postInvoke(rctx);
#end
    #getRequestStopTime()
    #updateEJBMonitoringData()
        }
#if ($M.getReturnType() != "void")
        return result;
#end
    }

#end

#end

}
// End: $Id: JStatefulLocal.vm 14503 2008-07-10 15:13:06Z chahinem $
