/* 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 java.util.Iterator;
import javax.ejb.EJBException;

import org.jfox.ejb.handler.Handler;
import org.jfox.ejb.handler.HandlerChain;

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

public class StatelessHandlerChain extends HandlerChain {

    public StatelessHandlerChain(String[] handlers) {
        for(int i = 0; i < handlers.length; i++) {
            addHandler(handlers[i]);
        }
    }

    public Object invokeHome(Bucket bucket, Invocation invocation) throws Exception {
        Iterator iter = invokers.iterator();
        if(iter.hasNext()) {
            return ((Handler) iter.next()).invokeHome(bucket, invocation, iter);
        }
        else {
            throw new EJBException("No Invoker");
        }
    }

    public Object invokeBean(Bucket bucket, Invocation invocation) throws Exception {
        Iterator iter = invokers.iterator();
        if(iter.hasNext()) {
            return ((org.jfox.ejb.handler.Handler) iter.next()).invokeBean(bucket, invocation, iter);
        }
        else {
            throw new EJBException("No Invoker");
        }
    }

    public static void main(String[] args) {

    }
}