/* JFox, the OpenSource J2EE Application Server
 *
 * Distributable under GNU LGPL license by gun.org
 * more details please visit http://www.huihoo.org/jfox
 */

package org.jfox.ejb;

import javax.ejb.SessionBean;

import org.jfox.pool.PoolableObject;

/**
 * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
 */

public class StatelessEJBObjectFactory extends EJBObjectFactory {
    private StatelessSessionBucket bucket;

    public StatelessEJBObjectFactory(Class classType, Class beanClass, StatelessSessionBucket bucket) throws Exception {
        super(classType, beanClass);
        this.bucket = bucket;
    }

    // the object maybe have invoked ejbCreate, if so, must call ejbRemove
    public void destroyObject(PoolableObject object) throws Exception {
        super.destroyObject(object);
        // if the poolable object has called the ejbCreate
        if(((StatelessEJBPoolableObject) object).isEjbCreated()) {
            bucket.ejbRemove((SessionBean) ((StatelessEJBPoolableObject) object).getBeanInstance());
        }
    }

    public static void main(String[] args) {

    }
}
