KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ve > luz > ica > jackass > daemon > NameServiceThread


1 /*
2  * Copyright (c) 2003 by The Jackass Team
3  * Licensed under the Open Software License version 2.0
4  */

5 package ve.luz.ica.jackass.daemon;
6
7 import java.io.File JavaDoc;
8 import java.lang.reflect.Method JavaDoc;
9 import java.net.URL JavaDoc;
10 import java.net.URLClassLoader JavaDoc;
11
12 import org.apache.commons.logging.Log;
13 import org.apache.commons.logging.LogFactory;
14
15 /**
16  * This object represents the thread where the name service will be executed.
17  * @author Carlos Arévalo
18  */

19 class NameServiceThread extends Thread JavaDoc
20 {
21     private static final Log LOG = LogFactory.getLog(NameServiceThread.class);
22     private static final String JavaDoc MAIN_METHOD = "main";
23
24     private String JavaDoc className = null;
25     private String JavaDoc[] commandLineParams = null;
26
27     /**
28      * Class constructor
29      * @param name the name service class name
30      * @param params the command line parameters
31      */

32     public NameServiceThread(String JavaDoc name, String JavaDoc[] params)
33     {
34         this.className = name;
35         this.commandLineParams = params;
36     }
37
38     /**
39      * Load the name service class and execute the main method.
40      */

41     public void run()
42     {
43         Class JavaDoc[] params = {String JavaDoc[].class};
44         Class JavaDoc nsClass;
45         try
46         {
47             File JavaDoc file = new File JavaDoc(className);
48
49             if (LOG.isDebugEnabled()) LOG.debug("loading " + file.getPath());
50
51             URL JavaDoc[] urls = {file.toURL()};
52             URLClassLoader JavaDoc loader = new URLClassLoader JavaDoc(urls);
53
54             nsClass = Class.forName(className, true, loader);
55             Method JavaDoc mainMethod = nsClass.getDeclaredMethod(MAIN_METHOD, params);
56             mainMethod.invoke(null, new Object JavaDoc[] {commandLineParams});
57         }
58         catch (Exception JavaDoc e)
59         {
60             LOG.error("Error starting the name service", e);
61         }
62     }
63
64 }
65
Popular Tags