## ---------------------------------------------------------------------------
## JOnAS: Java(TM) Open Application Server
## Copyright (C) 1999-2008 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
##
## Initial developer(s): Philippe Durieux.
## Contributor(s): - S. Ali Tokmen, Malek Chahine: EJB statistics
## ---------------------------------------------------------------------------
## $Id: JStatelessRemote.vm 14503 2008-07-10 15:13:06Z chahinem $
## ---------------------------------------------------------------------------

// This class is the bean specific part of JSessionRemote
// Generated by GenIC via Velocity. Do not edit directly this file.
// Start: $Id: JStatelessRemote.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.rmi.AccessException;
import java.rmi.RemoteException;
import javax.ejb.RemoveException;
import java.util.Date;

import org.ow2.jonas.lib.ejb21.JSessionContext;
import org.ow2.jonas.lib.ejb21.JSessionFactory;
import org.ow2.jonas.lib.ejb21.JSessionRemote;
import org.ow2.jonas.lib.ejb21.ha.JRepStatelessRemote;
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.ow2.carol.rmi.exception.RmiUtility;
import org.objectweb.util.monolog.api.BasicLevel;

#if ($isClusterReplicated)
public class $class extends JRepStatelessRemote implements $remote {
#else
public class $class extends JSessionRemote implements $remote {
#end

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

#foreach ($M in $methodList)

#if ($M.isRemoveThis())

    /**
     * remove this bean instance
     */
    public void remove() throws RemoteException, RemoveException {
        //TraceEjb.interp.log(BasicLevel.DEBUG,"");

        #beforeThrowRemoteException()

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

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

        try {
            rctx.ejbContext = bs.getICtx(rctx.currTx);
            rctx.bmcalled = true;
            rctx.ejbContext.setRemoved();
        } catch (javax.ejb.AccessLocalException e) {
            throw new AccessException("Security Exception thrown by an enterprise Bean", e);
        } catch (RuntimeException e) {
            rctx.sysExc = e;
            throw new RemoteException("RuntimeException thrown by an enterprise Bean", e);
        } catch (Error e) {
            rctx.sysExc = e;
            throw new RemoteException("Error thrown by an enterprise Bean", e);
        } catch (RemoteException e) {
            rctx.sysExc = e;
            throw e;
        } finally {
#if ($isClusterReplicated)
/* ******************REPLICATION CODE STARTS HERE*********************** */
            // There is no response to the client (void parameter needed by HA)
            postInvoke(rctx, null);
/* **********************END OF REPLICATION CODE************************ */
#else
            postInvoke(rctx);
#end
        }

        #afterThrowRemoteException()

    }

#else

    public $M.getReturnType() $M.getName()($M.getFormalParameters()) throws $M.getExceptionList() {
        //TraceEjb.interp.log(BasicLevel.DEBUG,"");

        #timerVariablesDeclaration()
        #getRequestStartTime()
        #beforeThrowRemoteException()

#if ($M.getReturnType() != "void")
          $M.getReturnType() result = $M.getDefaultValue();
#end

#if ($isClusterReplicated)
/* ******************REPLICATION CODE STARTS HERE*********************** */
        if (hasResponse()) {
            cmilogger.log(BasicLevel.DEBUG, "Response found");
            // Obtain the response associated with the request
            // and delete the request because the method is going to return
            Object response = getResponse();
    #if ($M.getReturnType() == "void")
            cmilogger.log(BasicLevel.DEBUG, "\tResponse void");
            return;
    #else
            cmilogger.log(BasicLevel.DEBUG, "\tResponse not void");
        #if ($M.getWrapperType() != "")
            return ($M.getReturnType()) (($M.getWrapperType())response).$M.getReturnType()Value();
        #else
            return ($M.getReturnType()) response;
        #end
    #end
        } else {
            cmilogger.log(BasicLevel.DEBUG, "Response not found");
        }
/* **********************END OF REPLICATION CODE************************ */
#end

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

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

        try {
            rctx.ejbContext = bs.getICtx(rctx.currTx);
            $bean_wrp b = ($bean_wrp) rctx.ejbContext.getInstance();
            ejbInv.bean = b;
            checkSecurity(ejbInv);
            rctx.bmcalled = true;
            #getBusinessStartTime()

#if ($M.getReturnType() != "void")
              result =
#end

              b.$M.getName()($M.getActualParameters());

        } catch (javax.ejb.AccessLocalException e) {
              throw new AccessException("Security Exception thrown by an enterprise Bean", e);
        } catch (RuntimeException e) {
            rctx.sysExc = e;
            throw new RemoteException("RuntimeException thrown by an enterprise Bean", e);
        } catch (Error e) {
            rctx.sysExc = e;
              throw new RemoteException("Error thrown by an enterprise Bean", e);
        } catch (RemoteException e) {
            rctx.sysExc = e;
            throw e;
          } finally {
          #getBusinessStopTime()
#if ($isClusterReplicated)
/* ******************REPLICATION CODE STARTS HERE*********************** */
        // If exists, pass the return type to postInvoke (Needed by HA)
        #if ($M.getReturnType() != "void")
            #if ($M.getWrapperType() != "")
            postInvoke(rctx, new $M.getWrapperType()(result));
            #else
            postInvoke(rctx, result);
            #end
        #else
            postInvoke(rctx, null);
        #end
/* **********************END OF REPLICATION CODE************************ */
#else
            postInvoke(rctx);
#end
        #getRequestStopTime()
        #updateEJBMonitoringData()
        }

#if ($M.getReturnType() != "void")
          return result;
#end

#afterThrowRemoteException()

    }

#end

#end

}

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