/*
 * 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.beanexc;

import javax.ejb.EJBContext;
import java.rmi.RemoteException;

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

/**
 * Common part to all beans.
 * @author Philippe Durieux, Philippe Coq
 */
public abstract class AccountCommon implements java.io.Serializable {

    protected static Logger logger = null;
    protected boolean iAmDestroyed = false;

    public abstract void setBalance(long val);
    public abstract EJBContext getContext();

    public void doAppException_1() throws AppException {
        logger.log(BasicLevel.DEBUG, "");
        setBalance(5000);
        throw new AppException("doAppException_1");
    }

    public void doAppException_2(boolean rollflg) throws AppException {
        logger.log(BasicLevel.DEBUG, "");
        setBalance(50);
        if (rollflg) {
            getContext().setRollbackOnly();
        }
        throw new AppException("doAppException_2");
    }

    public void doAppException_3() throws AppException {
        logger.log(BasicLevel.DEBUG, "");
        throw new AppException("doAppException_3");
    }

    public void doUncheckedException_1()  {
        logger.log(BasicLevel.DEBUG, "");
        int zero = 0;
        iAmDestroyed = true;
        float f = 10 / zero;
    }

    public void doUncheckedException_2() {
        logger.log(BasicLevel.DEBUG, "");
        setBalance(1000);
        int zero = 0;
        iAmDestroyed = true;
        float f = 10 / zero;
    }

    public void doUncheckedException_3() {
        logger.log(BasicLevel.DEBUG, "");
        int zero = 0;
        iAmDestroyed = true;
        float f = 10 / zero;
    }

    public void doRemoteException_1() throws RemoteException {
        logger.log(BasicLevel.DEBUG, "");
        setBalance(10);
        iAmDestroyed = true;
        throw new RemoteException("RemoteException in doRemoteException_1");
    }

    public void doEJBException_1() {
        logger.log(BasicLevel.DEBUG, "");
        setBalance(10);
        iAmDestroyed = true;
        throw new javax.ejb.EJBException("EJBException in doEJBException_1");
    }

    public void doEJBException_2() {
        logger.log(BasicLevel.DEBUG, "");
        setBalance(10);
        iAmDestroyed = true;
        throw new javax.ejb.EJBException("EJBException in doEJBException_2");
    }
    
    public void doEJBException_sup() {
        logger.log(BasicLevel.DEBUG, "");
        setBalance(10);
        iAmDestroyed = true;
        throw new javax.ejb.EJBException("EJBException in doEJBException_sup");
    }
    
    public boolean iAmDestroyed() {
        logger.log(BasicLevel.DEBUG, "");
        return iAmDestroyed;
    }

    public void ping() {
        logger.log(BasicLevel.DEBUG, "");
    }

    public void ejbPostCreate(int flag) {
    }

    public void ejbPostCreate(boolean flag) {
    }
    
}
