package org.jboss.cache.optimistic;

import org.jboss.cache.TreeCache;
import org.jboss.cache.interceptors.Interceptor;
import org.jgroups.blocks.MethodCall;

import java.util.ArrayList;
import java.util.List;

/**
 * Handles putXXX() methods: if the given node doesn't exist, it will be created
 * (depending on the create_if_not_exists argument)
 *
 * @author Bela Ban
 * @version $Id: CreateIfNotExistsInterceptor.java,v 1.7 2005/01/26 11:45:14
 *          belaban Exp $
 */
public class MockFailureInterceptor extends Interceptor
{


    public void setCache(TreeCache cache)
    {
        super.setCache(cache);

    }


    private List allCalled = new ArrayList();
    private List failurelist = new ArrayList();

    public Object invoke(MethodCall m) throws Throwable
    {
        if (failurelist.contains(m.getMethod()))
        {
            throw new Exception("Failure in method" + m);
        }

        allCalled.add(m.getMethod());

        return null;
    }


    /**
     * @return Returns the failurelist.
     */
    public List getFailurelist()
    {
        return failurelist;
    }

    /**
     * @param failurelist The failurelist to set.
     */
    public void setFailurelist(List failurelist)
    {
        this.failurelist = failurelist;
    }

    /**
     * @return Returns the called.
     */
    public List getAllCalled()
    {
        return allCalled;
    }

    /**
     * @param called The called to set.
     */
    public void setAllCalled(List called)
    {
        this.allCalled = called;
    }
}