1 package org.sf.jlaunchpad.util; 2 3 import java.security.Permission; 4 5 public class ExitProtector { 6 7 public void forbidSystemExitCall() { 8 final SecurityManager securityManager = new SecurityManager() { 9 public void checkPermission( Permission permission ) { 10 System.out.println("permission.getName() " + permission.getName()); 11 12 if(permission.getName().startsWith("exitVM")) { 13 throw new ExitTrappedException() ; 14 } 15 } 16 }; 17 18 System.setSecurityManager( securityManager ) ; 19 } 20 21 public void enableSystemExitCall() { 22 System.setSecurityManager( null ) ; 23 } 24 25 }