JUnitEventSink.java :  » Web-Crawler » jspider » net » javacoding » jspider » mockobjects » plugin » Java Open Source

Java Open Source » Web Crawler » jspider 
jspider » net » javacoding » jspider » mockobjects » plugin » JUnitEventSink.java
package net.javacoding.jspider.mockobjects.plugin;

import net.javacoding.jspider.api.event.EventSink;
import net.javacoding.jspider.api.event.JSpiderEvent;

import java.util.HashMap;
import java.util.Map;

/**
 * $Id: JUnitEventSink.java,v 1.7 2003/03/27 17:44:32 vanrogu Exp $
 */
public class JUnitEventSink implements EventSink {

    protected static JUnitEventSink instance;
    protected EventSink otherSink;

    protected Map counters;

    private JUnitEventSink ( ) {
        reset ( );
    }

    public static synchronized JUnitEventSink getInstance ( ) {
        if ( instance == null ) {
            instance = new JUnitEventSink();
        }
        return instance;
    }

    public void notify(JSpiderEvent event) {
        System.out.println("JUnit Plugin : " + event.getClass() );

        if ( event.isError() ) {
            System.out.println(event);
        }

        Integer count = (Integer)counters.get(event.getClass());
        if ( count == null ) {
            count = new Integer ( 0 );
        }
        counters.put ( event.getClass(), new Integer(count.intValue()+1) );
        if ( otherSink != null ) {
            otherSink.notify(event);
        }
    }

    public int getEventCount ( Class eventClass ) {
        Integer count = (Integer)counters.get(eventClass);
        if ( count == null ) {
            return 0;
        } else {
            return count.intValue();
        }
    }

    public void reset ( ) {
      this.counters = new HashMap ( );
      this.otherSink = null;
    }

    public void setOtherSink ( EventSink otherSink ) {
        this.otherSink = otherSink;
    }

    public void initialize() {
    }

    public void shutdown() {
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.