001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016:
017: package org.columba.core.main;
018:
019: import java.security.AllPermission;
020: import java.security.CodeSource;
021: import java.security.PermissionCollection;
022: import java.security.Permissions;
023: import java.security.Policy;
024:
025: import org.columba.core.shutdown.ShutdownManager;
026:
027: /**
028: * Columba's main class used to start the application.
029: */
030: public class Main {
031:
032: /**
033: * global classloader used as parent classloader in Columba everywhere
034: */
035: public static MainClassLoader mainClassLoader;
036:
037: public static void main(String[] args) throws Exception {
038:
039: // @author: fdietz
040: //
041: // PROBLEM: Extensions don't run using Java Webstart (JWS)
042: //
043: // Even though we assign "all-permission" in our columba.jnlp file, this
044: // only applies
045: // to the initial Java Webstart classloader. But, we create our own
046: // classloaders for
047: // loading extensions. These classloaders don't have the same permission
048: // settings anymore.
049:
050: // WORKAROUND:
051: //
052: // System.setSecurityManager(null);
053: //
054: // This call effectly disables the sandbox mode and seems to work fine.
055: //
056: // Below I use another way. The policy for all classloaders is set to
057: // "all-permissions".
058: // Don't really know the difference though.
059:
060: // grant "all-permissions"
061: Policy.setPolicy(new Policy() {
062: public PermissionCollection getPermissions(
063: CodeSource codesource) {
064: Permissions perms = new Permissions();
065: perms.add(new AllPermission());
066: return (perms);
067: }
068:
069: public void refresh() {
070: }
071: });
072:
073: start(args);
074: }
075:
076: public static void restart(String[] args) throws Exception {
077:
078: // shutdown Columba
079: ShutdownManager.getInstance().shutdown(0);
080: // set global class loader to null
081: mainClassLoader = null;
082:
083: // force object finalization
084: System.runFinalization();
085:
086: // run garbage collector
087: System.gc();
088:
089: // startup Columba
090: start(args);
091: }
092:
093: private static void start(String[] args) throws Exception {
094: // initialize global class loader
095: mainClassLoader = new MainClassLoader(Main.class
096: .getClassLoader());
097:
098: long start = System.currentTimeMillis();
099:
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)
109: / 1000);
110: }
111: }
|