commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ryan McGuinness <r...@fallingonline.com>
Subject Betwixt : Class Loader - Food for thought
Date Sun, 20 Nov 2005 17:42:59 GMT
I have been trying to get betwixt running with the IBM JDK within  
WebSphere. While sifting through the source, I noticed that each  
class that deals with loading classes does something a little  
different. Should there be a Utility class to handle this.

Also, in more secure containers, it may be a good idea to get the  
class loader a little differently:
Below is a code snip-it on getting the loader through the Security  
Manager.

package myPackage;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ResourceBundle;

public class myClassWithInternalLoaer {

protected static final class Security extends SecurityManager {
         Security() {}
         ClassLoader getCallingClassLoader() {
             Class[] stack = getClassContext();
             for (int i = 0; i < stack.length; i++) {
                 if (stack[i] != Security.class && stack[i] !=  
ResourceBundle.class)
                     return stack[i].getClassLoader();
             }
             return null;
         }
     }
     protected static final Security security = (Security)  
AccessController.doPrivileged(new PrivilegedAction() {
         public Object run() {
             return new Security();
         }
     });
     protected ClassLoader getLoader() {
         ClassLoader cl = security.getCallingClassLoader();
         if (cl == null)
             cl = ClassLoader.getSystemClassLoader();
         return cl;
     }

     ClassLoader myLoader = getLoader();
     ...

}

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message