JUnitEventSink.java
上传用户:qing5858
上传日期:2015-10-27
资源大小:6056k
文件大小:2k
源码类别:

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.mockobjects.plugin;
  2. import net.javacoding.jspider.api.event.EventSink;
  3. import net.javacoding.jspider.api.event.JSpiderEvent;
  4. import java.util.HashMap;
  5. import java.util.Map;
  6. /**
  7.  * $Id: JUnitEventSink.java,v 1.7 2003/03/27 17:44:32 vanrogu Exp $
  8.  */
  9. public class JUnitEventSink implements EventSink {
  10.     protected static JUnitEventSink instance;
  11.     protected EventSink otherSink;
  12.     protected Map counters;
  13.     private JUnitEventSink ( ) {
  14.         reset ( );
  15.     }
  16.     public static synchronized JUnitEventSink getInstance ( ) {
  17.         if ( instance == null ) {
  18.             instance = new JUnitEventSink();
  19.         }
  20.         return instance;
  21.     }
  22.     public void notify(JSpiderEvent event) {
  23.         System.out.println("JUnit Plugin : " + event.getClass() );
  24.         if ( event.isError() ) {
  25.             System.out.println(event);
  26.         }
  27.         Integer count = (Integer)counters.get(event.getClass());
  28.         if ( count == null ) {
  29.             count = new Integer ( 0 );
  30.         }
  31.         counters.put ( event.getClass(), new Integer(count.intValue()+1) );
  32.         if ( otherSink != null ) {
  33.             otherSink.notify(event);
  34.         }
  35.     }
  36.     public int getEventCount ( Class eventClass ) {
  37.         Integer count = (Integer)counters.get(eventClass);
  38.         if ( count == null ) {
  39.             return 0;
  40.         } else {
  41.             return count.intValue();
  42.         }
  43.     }
  44.     public void reset ( ) {
  45.       this.counters = new HashMap ( );
  46.       this.otherSink = null;
  47.     }
  48.     public void setOtherSink ( EventSink otherSink ) {
  49.         this.otherSink = otherSink;
  50.     }
  51.     public void initialize() {
  52.     }
  53.     public void shutdown() {
  54.     }
  55. }