KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > tool > util > ToolFactory


1 package net.javacoding.jspider.tool.util;
2
3 import net.javacoding.jspider.tool.Tool;
4 import net.javacoding.jspider.tool.impl.*;
5
6 /**
7  * $Id: ToolFactory.java,v 1.2 2003/04/08 15:50:39 vanrogu Exp $
8  */

9 public class ToolFactory {
10
11     public static Tool createTool ( String JavaDoc[] args ) {
12         Tool tool = null;
13         String JavaDoc toolName = getToolName ( args );
14         if( toolName != null ) {
15           tool = getTool ( toolName );
16         }
17         return tool;
18     }
19
20     protected static String JavaDoc getToolName ( String JavaDoc[] args ) {
21         String JavaDoc toolName = null;
22         for (int i = 0; i < args.length; i++) {
23             String JavaDoc arg = args[i];
24             if ( ! arg.startsWith("-") ) {
25                 toolName = arg;
26                 break;
27             }
28         }
29         return toolName;
30     }
31
32     protected static Tool getTool ( String JavaDoc name ) {
33         Tool tool = null;
34
35         if ( "headers".equals ( name ) ) {
36             tool = new HeadersTool();
37         } else if ( "download".equals ( name ) ) {
38             tool = new DownloadTool();
39         } else if ( "info".equals ( name ) ) {
40             tool = new InfoTool();
41         } else if ( "fetch".equals ( name ) ) {
42             tool = new FetchTool();
43         } else if ( "findlinks".equals ( name ) ) {
44             tool = new FindLinksTool();
45         } else if ( "email".equals ( name ) ) {
46             tool = new EMailTool();
47         }
48
49         return tool;
50     }
51
52 }
53
Popular Tags