// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.AccessControlException;

public class Test4 implements Test {
    public void test() {
        System.out.printf("Current dir has %d files\n", new File(".").list().length);
    }
    public static void main(String[] args) {
        System.setSecurityManager(new SecurityManager());
        Test4 me = new Test4();
        me.test();
        Test o = null;
        try {
            URLClassLoader cl = new URLClassLoader(new URL[] { new URL("http://localhost/test4x.jar") });
            o = (Test)Class.forName("Test4X", true, cl).getConstructor(Test.class).newInstance(me);
        } catch(Exception ex) {
            System.err.println(ex.getClass().getName() + " : " + ex.getMessage());
            System.exit(1);
        }
        try {
            o.test();
        } catch(AccessControlException ex) {
            System.out.println("Test4X caugth with the hand in the cookie jar: " + ex.getMessage());
        }
    }
}
