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

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.tool.util;
  2. import net.javacoding.jspider.tool.Tool;
  3. import net.javacoding.jspider.tool.impl.*;
  4. /**
  5.  * $Id: ToolFactory.java,v 1.2 2003/04/08 15:50:39 vanrogu Exp $
  6.  */
  7. public class ToolFactory {
  8.     public static Tool createTool ( String[] args ) {
  9.         Tool tool = null;
  10.         String toolName = getToolName ( args );
  11.         if( toolName != null ) {
  12.           tool = getTool ( toolName );
  13.         }
  14.         return tool;
  15.     }
  16.     protected static String getToolName ( String[] args ) {
  17.         String toolName = null;
  18.         for (int i = 0; i < args.length; i++) {
  19.             String arg = args[i];
  20.             if ( ! arg.startsWith("-") ) {
  21.                 toolName = arg;
  22.                 break;
  23.             }
  24.         }
  25.         return toolName;
  26.     }
  27.     protected static Tool getTool ( String name ) {
  28.         Tool tool = null;
  29.         if ( "headers".equals ( name ) ) {
  30.             tool = new HeadersTool();
  31.         } else if ( "download".equals ( name ) ) {
  32.             tool = new DownloadTool();
  33.         } else if ( "info".equals ( name ) ) {
  34.             tool = new InfoTool();
  35.         } else if ( "fetch".equals ( name ) ) {
  36.             tool = new FetchTool();
  37.         } else if ( "findlinks".equals ( name ) ) {
  38.             tool = new FindLinksTool();
  39.         } else if ( "email".equals ( name ) ) {
  40.             tool = new EMailTool();
  41.         }
  42.         return tool;
  43.     }
  44. }