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

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.core;
  2. import net.javacoding.jspider.api.event.EventSink;
  3. import net.javacoding.jspider.core.dispatch.EventDispatcher;
  4. import net.javacoding.jspider.core.dispatch.impl.EventDispatcherImpl;
  5. import net.javacoding.jspider.core.impl.*;
  6. import net.javacoding.jspider.core.storage.Storage;
  7. import net.javacoding.jspider.core.storage.StorageFactory;
  8. import net.javacoding.jspider.core.throttle.ThrottleFactory;
  9. import net.javacoding.jspider.core.util.config.*;
  10. import java.net.URL;
  11. /**
  12.  *
  13.  * $Id: SpiderContextFactory.java,v 1.12 2003/04/03 15:57:14 vanrogu Exp $
  14.  *
  15.  * @author G黱ther Van Roey
  16.  */
  17. public class SpiderContextFactory {
  18.     public static SpiderContext createContext(URL baseURL) {
  19.         EventSink[] sinks = new PluginFactory().createPlugins();
  20.         PropertySet props = ConfigurationFactory.getConfiguration().getPluginsConfiguration();
  21.         PropertySet filterProps = new MappedPropertySet ( ConfigConstants.CONFIG_FILTER, props );
  22.         EventDispatcher dispatcher = new EventDispatcherImpl("Global Event Dispatcher", sinks, filterProps);
  23.         dispatcher.initialize();
  24.         Storage storage = new StorageFactory().createStorage();
  25.         ThrottleFactory throttleFactory = new ThrottleFactory();
  26.         SpiderContext context = new SpiderContextImpl(baseURL, dispatcher, throttleFactory, storage);
  27.         //todo: This is quite weird, isn't it?  REFACTOR the relationship between Agent and Context!  HOW ???
  28.         context.setAgent(new AgentImpl(context));
  29.         return context;
  30.     }
  31. }