KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3  * EJTools, the Enterprise Java Tools
4
5  *
6
7  * Distributable under LGPL license.
8
9  * See terms at http://opensource.org/licenses/lgpl-license.php
10
11  */

12
13 package org.ejtools.jmx.browser;
14
15
16
17 import java.beans.Beans JavaDoc;
18
19 import java.io.File JavaDoc;
20
21 import java.net.URL JavaDoc;
22
23 import java.net.URLClassLoader JavaDoc;
24
25 import java.security.AccessController JavaDoc;
26
27 import java.security.Permission JavaDoc;
28
29 import java.security.PrivilegedExceptionAction JavaDoc;
30
31 import java.util.LinkedList JavaDoc;
32
33
34
35 import org.apache.log4j.Logger;
36
37
38
39 /**
40
41  * Description of the Class
42
43  *
44
45  * @version $Revision: 1.5 $
46
47  * @author Laurent Etiemble
48
49  * @created 21 mars 2002
50
51  */

52
53 public class Main {
54
55    /** Description of the Field */
56
57    private static Logger logger = Logger.getLogger(Main.class);
58
59
60
61
62
63    /**
64
65     * The main program for the Main class
66
67     *
68
69     * @param args The command line arguments
70
71     * @exception Exception Description of the Exception
72
73     */

74
75    public static void main(String JavaDoc[] args)
76
77           throws Exception JavaDoc {
78
79       logger.debug("========================================");
80
81       logger.debug("JAVA_HOME : " + System.getProperty("java.home"));
82
83       logger.debug("Vendor : " + System.getProperty("java.vendor"));
84
85       logger.debug("Version : " + System.getProperty("java.version"));
86
87       logger.debug("Operating Sys. : " + System.getProperty("os.name"));
88
89       logger.debug("Architecture : " + System.getProperty("os.arch"));
90
91       logger.debug("Version : " + System.getProperty("os.version"));
92
93       logger.debug("========================================");
94
95
96
97       File JavaDoc pluginDir;
98
99       File JavaDoc[] plugins;
100
101       LinkedList JavaDoc list = new LinkedList JavaDoc();
102
103
104
105       logger.debug("Building classpath...");
106
107
108
109       // Store the files from lib directory
110

111       logger.debug("Scanning lib directory...");
112
113       pluginDir = new File JavaDoc("../lib");
114
115       plugins = pluginDir.listFiles();
116
117       if (plugins != null) {
118
119          for (int i = 0; i < plugins.length; i++) {
120
121             logger.debug("Found " + plugins[i].toURL());
122
123             list.add(plugins[i].toURL());
124
125          }
126
127       }
128
129
130
131       // Store the files from lib/ext directory
132

133       logger.debug("Scanning lib/ext directory...");
134
135       pluginDir = new File JavaDoc("../lib/ext");
136
137       plugins = pluginDir.listFiles();
138
139       if (plugins != null) {
140
141          for (int i = 0; i < plugins.length; i++) {
142
143             logger.debug("Found " + plugins[i].toURL());
144
145             list.add(plugins[i].toURL());
146
147          }
148
149       }
150
151       logger.debug("========================================");
152
153
154
155       // Create a custom classloader
156

157       URL JavaDoc[] pluginURLs = (URL JavaDoc[]) list.toArray(new URL JavaDoc[list.size()]);
158
159       Thread.currentThread().setContextClassLoader(
160
161             new URLClassLoader JavaDoc(pluginURLs, Thread.currentThread().getContextClassLoader())
162
163             );
164
165
166
167       // Custom security manager
168

169       System.setSecurityManager(
170
171          new SecurityManager JavaDoc() {
172
173             public void checkPermission(Permission JavaDoc p) { }
174
175
176
177
178
179             public void checkPermission(Permission JavaDoc perm, Object JavaDoc context) { }
180
181          });
182
183
184
185       // Create the JMX Browser JavaBean
186

187       logger.debug("Launching EJTools JMX Browser");
188
189       AccessController.doPrivileged(
190
191          new PrivilegedExceptionAction JavaDoc() {
192
193             public Object JavaDoc run()
194
195                    throws Exception JavaDoc {
196
197                Beans.instantiate(
198
199                      Thread.currentThread().getContextClassLoader(),
200
201                      "org.ejtools.jmx.browser.Browser"
202
203                      );
204
205                return null;
206
207             }
208
209          });
210
211    }
212
213 }
214
215
216
217
Popular Tags