KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > main > Main


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16

17 package org.columba.core.main;
18
19 import java.security.AllPermission JavaDoc;
20 import java.security.CodeSource JavaDoc;
21 import java.security.PermissionCollection JavaDoc;
22 import java.security.Permissions JavaDoc;
23 import java.security.Policy JavaDoc;
24
25 import org.columba.core.shutdown.ShutdownManager;
26
27 /**
28  * Columba's main class used to start the application.
29  */

30 public class Main {
31
32     /**
33      * global classloader used as parent classloader in Columba everywhere
34      */

35     public static MainClassLoader mainClassLoader;
36
37     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
38
39         
40         // @author: fdietz
41
//
42
// PROBLEM: Extensions don't run using Java Webstart (JWS)
43
//
44
// Even though we assign "all-permission" in our columba.jnlp file, this
45
// only applies
46
// to the initial Java Webstart classloader. But, we create our own
47
// classloaders for
48
// loading extensions. These classloaders don't have the same permission
49
// settings anymore.
50

51         // WORKAROUND:
52
//
53
// System.setSecurityManager(null);
54
//
55
// This call effectly disables the sandbox mode and seems to work fine.
56
//
57
// Below I use another way. The policy for all classloaders is set to
58
// "all-permissions".
59
// Don't really know the difference though.
60

61         // grant "all-permissions"
62
Policy.setPolicy(new Policy JavaDoc() {
63             public PermissionCollection JavaDoc getPermissions(CodeSource JavaDoc codesource) {
64                 Permissions JavaDoc perms = new Permissions JavaDoc();
65                 perms.add(new AllPermission JavaDoc());
66                 return (perms);
67             }
68
69             public void refresh() {
70             }
71         });
72
73         start(args);
74     }
75
76     
77     public static void restart(String JavaDoc[] args) throws Exception JavaDoc {
78
79         // shutdown Columba
80
ShutdownManager.getInstance().shutdown(0);
81         // set global class loader to null
82
mainClassLoader = null;
83
84         // force object finalization
85
System.runFinalization();
86
87         // run garbage collector
88
System.gc();
89
90         // startup Columba
91
start(args);
92     }
93
94     private static void start(String JavaDoc[] args) throws Exception JavaDoc {
95         // initialize global class loader
96
mainClassLoader = new MainClassLoader(Main.class.getClassLoader());
97
98         long start = System.currentTimeMillis();
99
100         // use global class loader to bootstrap Columba
101
Bootstrap startup = (Bootstrap) mainClassLoader.loadClass(
102                 Bootstrap.class.getName()).newInstance();
103         startup.run(args);
104
105         long stop = System.currentTimeMillis();
106
107         System.out.println("total startup time (ms)=" + (stop - start));
108         System.out.println("total startup time (sec)=" + (stop - start) / 1000);
109     }
110 }
Popular Tags