KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > jndi > 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.jndi.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  * Main class for the JNDI Browser. Construct the classloader dynamically by scanning directories. Once the classloader has been built, launch the Browser with
22  * a custom security manager.
23  *
24  * @author letiemble
25  * @created 21 mars 2002
26  * @version $Revision: 1.2 $
27  */

28 public class Main
29 {
30    /** Log4j logger */
31    static Logger logger = Logger.getLogger(Main.class);
32
33
34    /**
35     * The main method
36     *
37     * @param args The command line arguments
38     * @exception Exception Exception
39     */

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