KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > management > browser > Main


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.management.browser;
8
9 import java.beans.Beans JavaDoc;
10 import java.io.File JavaDoc;
11 import java.net.URL JavaDoc;
12 import java.net.URLClassLoader JavaDoc;
13 import java.security.AccessController JavaDoc;
14 import java.security.Permission JavaDoc;
15 import java.security.PrivilegedExceptionAction JavaDoc;
16 import java.util.LinkedList JavaDoc;
17
18 import org.apache.log4j.Logger;
19
20 /**
21  * Description of the Class
22  *
23  * @author Laurent Etiemble
24  * @version $Revision: 1.5 $
25  * @todo Javadoc to complete
26  */

27 public class Main
28 {
29    /** Default logger */
30    private static Logger logger = Logger.getLogger(Main.class);
31
32
33    /**
34     * The main program for the Main class
35     *
36     * @param args The command line arguments
37     * @exception Exception Description of the Exception
38     */

39    public static void main(String JavaDoc[] args)
40       throws Exception JavaDoc
41    {
42       logger.debug("========================================");
43       logger.debug("JAVA_HOME : " + System.getProperty("java.home"));
44       logger.debug("Vendor : " + System.getProperty("java.vendor"));
45       logger.debug("Version : " + System.getProperty("java.version"));
46       logger.debug("Operating Sys. : " + System.getProperty("os.name"));
47       logger.debug("Architecture : " + System.getProperty("os.arch"));
48       logger.debug("Version : " + System.getProperty("os.version"));
49       logger.debug("========================================");
50
51       File JavaDoc pluginDir;
52       File JavaDoc[] plugins;
53       LinkedList JavaDoc list = new LinkedList JavaDoc();
54
55       logger.debug("Building classpath...");
56
57       // Store the files from lib directory
58
logger.debug("Scanning lib directory...");
59       pluginDir = new File JavaDoc("../lib");
60       plugins = pluginDir.listFiles();
61       if (plugins != null)
62       {
63          for (int i = 0; i < plugins.length; i++)
64          {
65             logger.debug("Found " + plugins[i].toURL());
66             list.add(plugins[i].toURL());
67          }
68       }
69
70       // Store the files from lib/ext directory
71
logger.debug("Scanning lib/ext directory...");
72       pluginDir = new File JavaDoc("../lib/ext");
73       plugins = pluginDir.listFiles();
74       if (plugins != null)
75       {
76          for (int i = 0; i < plugins.length; i++)
77          {
78             logger.debug("Found " + plugins[i].toURL());
79             list.add(plugins[i].toURL());
80          }
81       }
82       logger.debug("========================================");
83
84       // Create a custom classloader
85
URL JavaDoc[] pluginURLs = (URL JavaDoc[]) list.toArray(new URL JavaDoc[list.size()]);
86       Thread.currentThread().setContextClassLoader(
87          new URLClassLoader JavaDoc(pluginURLs, Thread.currentThread().getContextClassLoader())
88          );
89
90       // Custom security manager
91
System.setSecurityManager(
92          new SecurityManager JavaDoc()
93          {
94             public void checkPermission(Permission JavaDoc p) { }
95
96
97             public void checkPermission(Permission JavaDoc perm, Object JavaDoc context) { }
98          });
99
100       // Create the Management Browser JavaBean
101
logger.debug("Launching EJTools Management Browser");
102       AccessController.doPrivileged(
103          new PrivilegedExceptionAction JavaDoc()
104          {
105             public Object JavaDoc run()
106                throws Exception JavaDoc
107             {
108                Beans.instantiate(
109                   Thread.currentThread().getContextClassLoader(),
110                   "org.ejtools.management.browser.Browser"
111                   );
112                return null;
113             }
114          });
115    }
116 }
117
118
Popular Tags