[jboss-cvs] JBossAS SVN: r77241 - in projects/aop/trunk/aop/src/main/org/jboss/aop: advice and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 20 09:32:54 EDT 2008


Author: kabir.khan at jboss.com
Date: 2008-08-20 09:32:54 -0400 (Wed, 20 Aug 2008)
New Revision: 77241

Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/AdvisorFactory.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GenericInterceptorFactory.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/InstrumentorFactory.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/MatcherStrategy.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/ProxyMatcherStrategy.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/MarshalledInterfaceProxy.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/SecurityActions.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ClassProxyContainer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/SecurityActions.java
Log:
[JBAOP-625] Guess the classloader better than simply using the TCL

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java	2008-08-20 13:28:25 UTC (rev 77240)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java	2008-08-20 13:32:54 UTC (rev 77241)
@@ -1076,7 +1076,6 @@
    /**
     * Set the metadata
     * 
-    * FIXME why does this have java.lang.Object signature?
     * @param metadata the metadata
     */
    public void setMetadata(MetaData metadata)
@@ -1609,7 +1608,7 @@
    void setClassLoader(ClassLoader loader) throws IllegalStateException
    {
       if (this.clazz != null && loader != null &&
-            loader != this.clazz.getClassLoader())
+            loader != SecurityActions.getClassLoader(this.clazz))
       {
          throw new IllegalStateException("Cannot have both loader and class");
       }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AdvisorFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AdvisorFactory.java	2008-08-20 13:28:25 UTC (rev 77240)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AdvisorFactory.java	2008-08-20 13:32:54 UTC (rev 77241)
@@ -71,7 +71,7 @@
          {         
             try
             {
-               // FIXME ClassLoader - why should this class be visible from the context classloader?
+               //Context classloader is fine in this case since this is only called when initialising the main AspectManager
                Class<?> otherAdvisorClass = SecurityActions.getContextClassLoader().loadClass(property);
                otherAdvisorConstructor = otherAdvisorClass.getConstructor(CONSTRUCTOR_SIG);
             }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java	2008-08-20 13:28:25 UTC (rev 77240)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java	2008-08-20 13:32:54 UTC (rev 77241)
@@ -384,8 +384,12 @@
          for (int i = 0; i < mixins.size(); i++)
          {
             InterfaceIntroduction.Mixin mixin = mixins.get(i);
-            // FIXME ClassLoader - how do we know the class is visible from the context classloader?
-            ClassLoader cl = SecurityActions.getContextClassLoader();
+            ClassLoader cl = getClassLoader();
+            if (cl == null)
+            {
+               // Fall back to context classloader
+               cl = SecurityActions.getContextClassLoader();
+            }
             cl.loadClass(mixin.getClassName());
             String[] interfaces = mixin.getInterfaces();
             for (int j = 0; j < interfaces.length; j++)
@@ -583,8 +587,7 @@
    {
       if (AspectManager.verbose && logger.isDebugEnabled())
       {
-         logger.debug("Creating chains for " + clazz + " " +
-               ((clazz != null) ? clazz.getClassLoader() : null ));
+         logger.debug("Creating chains for " + clazz + " " + getClassLoader());
       }
       // TODO flavia remove this
       // this if is here because the subclass GeneratedClassAdvisor shouldn't be calling
@@ -672,7 +675,7 @@
    {
       if (AspectManager.verbose && logger.isDebugEnabled())
       {
-         logger.debug("Updating chains for " + clazz + " " + ((clazz != null) ? clazz.getClassLoader() : null ));
+         logger.debug("Updating chains for " + clazz + " " + ((clazz != null) ? getClassLoader() : null ));
       }
 
       lockWriteChains();
@@ -864,8 +867,7 @@
       //The standard MethodCalledByXXXXInvocation class calls by reflection and needs access
       SecurityActions.setAccessible(calledMethod);
 
-      // FIXME ClassLoader - how do we know the class is visible from the context classloader?
-      Class<?> calledClazz = SecurityActions.getContextClassLoader().loadClass(calledClass);
+      Class<?> calledClazz = getClassLoader().loadClass(calledClass);
       MethodByConInfo info = new MethodByConInfo(this, calledClazz, callingClass, callingIndex, calledMethod, calledMethodHash, null);
       calledMethodsMap.put(calledMethodHash, info);
       return info;
@@ -895,8 +897,7 @@
    {
       //The standard ConstructorCalledByXXXXInvocation class calls by reflection and needs access
       calledCon.setAccessible(true);
-      // FIXME ClassLoader - how do we know the class is visible from the context classloader?
-      Class<?> calledClazz = SecurityActions.getContextClassLoader().loadClass(calledClass);
+      Class<?> calledClazz = getClassLoader().loadClass(calledClass);
 
       try
       {
@@ -963,8 +964,7 @@
       {
          Constructor<?> callingConstructor = constructors[callingIndex];
          if (callingConstructor == null) throw new RuntimeException("Unable to figure out calling method of a caller pointcut");
-         // FIXME ClassLoader - how do we know the class is visible from the context classloader?
-         Class<?> called = SecurityActions.getContextClassLoader().loadClass(cname);
+         Class<?> called = getClassLoader().loadClass(cname);
          Method calledMethod = MethodHashing.findMethodByHash(called, calledHash);
          if (calledMethod == null) throw new RuntimeException("Unable to figure out calledmethod of a caller pointcut");
 
@@ -994,8 +994,7 @@
       {
          Constructor<?> callingConstructor = constructors[callingIndex];
          if (callingConstructor == null) throw new RuntimeException("Unable to figure out calling method of a caller pointcut");
-         // FIXME ClassLoader - how do we know the class is visible from the context classloader?
-         Class<?> called = SecurityActions.getContextClassLoader().loadClass(cname);
+         Class<?> called = getClassLoader().loadClass(cname);
          Constructor<?> calledCon = MethodHashing.findConstructorByHash(called, calledHash);
          if (calledCon == null) throw new RuntimeException("Unable to figure out calledcon of a caller pointcut");
 
@@ -1585,8 +1584,7 @@
       {
          Constructor<?> callingConstructor = constructors[callingIndex];
          if (callingConstructor == null) throw new RuntimeException("Unable to figure out calling method of a caller pointcut");
-         // FIXME ClassLoader - how do we know the class is visible from the context classloader?
-         Class<?> called = SecurityActions.getContextClassLoader().loadClass(calledClass);
+         Class<?> called = SecurityActions.getClassLoader(callingClass).loadClass(calledClass);
          Method calledMethod = MethodHashing.findMethodByHash(called, calledMethodHash);
          if (calledMethod == null) throw new RuntimeException("Unable to figure out calledmethod of a caller pointcut");
 
@@ -1651,8 +1649,7 @@
       {
          Constructor<?> callingConstructor = constructors[callingIndex];
          if (callingConstructor == null) throw new RuntimeException("Unable to figure out calling method of a caller pointcut");
-         // FIXME ClassLoader - how do we know the class is visible from the context classloader?
-         Class<?> called = SecurityActions.getContextClassLoader().loadClass(calledClass);
+         Class<?> called = SecurityActions.getClassLoader(callingClass).loadClass(calledClass);
          Constructor<?> calledCon = MethodHashing.findConstructorByHash(called, calledConHash);
          if (calledCon == null) throw new RuntimeException("Unable to figure out calledcon of a caller pointcut");
 
@@ -2464,8 +2461,7 @@
          {
             Method callingMethod = MethodHashing.findMethodByHash(clazz, callingMethodHash);
             if (callingMethod == null) throw new RuntimeException("Unable to figure out calling method of a caller pointcut");
-            // FIXME ClassLoader - how do we know the class is visible from the context classloader?
-            Class<?> called = SecurityActions.getContextClassLoader().loadClass(calledClass);
+            Class<?> called = getClassLoader().loadClass(calledClass);
             Method calledMethod = MethodHashing.findMethodByHash(called, calledMethodHash);
             if (calledMethod == null) throw new RuntimeException("Unable to figure out calledmethod of a caller pointcut");
 
@@ -2570,8 +2566,7 @@
          //The standard MethodCalledByXXXXInvocation class calls by reflection and needs access
          calledMethod.setAccessible(true);
 
-         // FIXME ClassLoader - how do we know the class is visible from the context classloader?
-         Class<?> calledClazz = SecurityActions.getContextClassLoader().loadClass(calledClass);
+         Class<?> calledClazz = getClassLoader().loadClass(calledClass);
          MethodByMethodInfo info = new MethodByMethodInfo(ClassAdvisor.this, calledClazz, calledMethod, callingMethod, callingMethodHash, calledMethodHash, null);
          calledMethodsMap.put(calledMethodHash, info);
          return info;
@@ -2583,8 +2578,7 @@
          {
             Method callingMethod = MethodHashing.findMethodByHash(clazz, callingHash);
             if (callingMethod == null) throw new RuntimeException("Unable to figure out calling method of a caller pointcut");
-            // FIXME ClassLoader - how do we know the class is visible from the context classloader?
-            Class<?> called = SecurityActions.getContextClassLoader().loadClass(cname);
+            Class<?> called = getClassLoader().loadClass(cname);
             Method calledMethod = MethodHashing.findMethodByHash(called, calledHash);
             if (calledMethod == null) throw new RuntimeException("Unable to figure out calledmethod of a caller pointcut");
 
@@ -2657,8 +2651,7 @@
          {
             Method callingMethod = MethodHashing.findMethodByHash(clazz, callingHash);
             if (callingMethod == null) throw new RuntimeException("Unable to figure out calling method of a constructor caller pointcut");
-            // FIXME ClassLoader - how do we know the class is visible from the context classloader?
-            Class<?> called = SecurityActions.getContextClassLoader().loadClass(cname);
+            Class<?> called = getClassLoader().loadClass(cname);
             Constructor<?> calledCon = MethodHashing.findConstructorByHash(called, calledHash);
             if (calledCon == null) throw new RuntimeException("Unable to figure out calledcon of a constructor caller pointcut");
             
@@ -2744,8 +2737,7 @@
          {
             Method callingMethod = MethodHashing.findMethodByHash(clazz, callingMethodHash);
             if (callingMethod == null) throw new RuntimeException("Unable to figure out calling method of a constructor caller pointcut");
-            // FIXME ClassLoader - how do we know the class is visible from the context classloader?
-            Class<?> called = SecurityActions.getContextClassLoader().loadClass(calledClass);
+            Class<?> called = getClassLoader().loadClass(calledClass);
             Constructor<?> calledCon = MethodHashing.findConstructorByHash(called, calledConHash);
             if (calledCon == null) throw new RuntimeException("Unable to figure out calledcon of a constructor caller pointcut");
 
@@ -2867,8 +2859,7 @@
          //The standard ConstructorCalledByXXXXInvocation class calls by reflection and needs access
          calledCon.setAccessible(true);
 
-         // FIXME ClassLoader - how do we know the class is visible from the context classloader?
-         Class<?> calledClazz = SecurityActions.getContextClassLoader().loadClass(calledClass);
+         Class<?> calledClazz = getClassLoader().loadClass(calledClass);
          try
          {
             int index = calledClass.lastIndexOf('.');

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java	2008-08-20 13:28:25 UTC (rev 77240)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java	2008-08-20 13:32:54 UTC (rev 77241)
@@ -1039,49 +1039,49 @@
    protected void generateJoinPointClass(MethodInfo info)
    {
       MethodJoinPointGenerator generator = getJoinPointGenerator(info);
-      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+      generator.generateJoinPointClass(getClassLoader(), info);
    }
 
    protected void generateJoinPointClass(FieldInfo info)
    {
       FieldJoinPointGenerator generator = getJoinPointGenerator(info);
-      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+      generator.generateJoinPointClass(getClassLoader(), info);
    }
 
    protected void generateJoinPointClass(ConstructorInfo info)
    {
       ConstructorJoinPointGenerator generator = getJoinPointGenerator(info);
-      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+      generator.generateJoinPointClass(getClassLoader(), info);
    }
 
    protected void generateJoinPointClass(ConstructionInfo info)
    {
       ConstructionJoinPointGenerator generator = getJoinPointGenerator(info);
-      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+      generator.generateJoinPointClass(getClassLoader(), info);
    }
 
    protected void generateJoinPointClass(MethodByMethodInfo info)
    {
       MethodByMethodJoinPointGenerator generator = getJoinPointGenerator(info);
-      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+      generator.generateJoinPointClass(getClassLoader(), info);
    }
 
    protected void generateJoinPointClass(ConByMethodInfo info)
    {
       ConByMethodJoinPointGenerator generator = getJoinPointGenerator(info);
-      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+      generator.generateJoinPointClass(getClassLoader(), info);
    }
 
    protected void generateJoinPointClass(ConByConInfo info)
    {
       ConByConJoinPointGenerator generator = getJoinPointGenerator(info);
-      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+      generator.generateJoinPointClass(getClassLoader(), info);
    }
 
    protected void generateJoinPointClass(MethodByConInfo info)
    {
       MethodByConJoinPointGenerator generator = getJoinPointGenerator(info);
-      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+      generator.generateJoinPointClass(getClassLoader(), info);
    }
    
    protected Object rebindJoinPointWithInstanceInformation(JoinPointInfo info)
@@ -1091,7 +1091,7 @@
       {
          JoinPointGenerator generator = getJoinPointGenerator(info);
          generator.rebindJoinpoint(info);
-         return generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+         return generator.generateJoinPointClass(getClassLoader(), info);
       }
       finally
       {

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GenericInterceptorFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GenericInterceptorFactory.java	2008-08-20 13:28:25 UTC (rev 77240)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GenericInterceptorFactory.java	2008-08-20 13:32:54 UTC (rev 77241)
@@ -87,8 +87,13 @@
             }
             if (clazz != null)
             {
-               // FIXME ClassLoader - why should the class be visible from the context classloader?
-               clazz = SecurityActions.getContextClassLoader().loadClass(classname);
+               ClassLoader cl = advisor.getClassLoader();
+               if (cl == null)
+               {
+                  //Fall back to context classloader
+                  cl = SecurityActions.getContextClassLoader();
+               }
+               clazz = cl.loadClass(classname);
                classRef = new WeakReference<Class<?>>(clazz);
             }
          }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/InstrumentorFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/InstrumentorFactory.java	2008-08-20 13:28:25 UTC (rev 77240)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/InstrumentorFactory.java	2008-08-20 13:32:54 UTC (rev 77241)
@@ -66,7 +66,7 @@
             
             try
             {
-               // FIXME ClassLoader - why should the class be visible from the context classloader?
+               //Context classloader is fine in this case since this is only called when initialising the main AspectManager
                Class<?> otherInstrumentorClass = SecurityActions.getContextClassLoader().loadClass(property);
                otherInstrumentorConstructor = otherInstrumentorClass.getConstructor(CONSTRUCTOR_SIG);
                instrumentor = InstrumentorEnum.OTHER_INSTRUMENTOR;

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/MatcherStrategy.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/MatcherStrategy.java	2008-08-20 13:28:25 UTC (rev 77240)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/MatcherStrategy.java	2008-08-20 13:32:54 UTC (rev 77241)
@@ -64,8 +64,13 @@
          String sub = instanceOf.getInstanceOfAnnotation().substring(1);
          try
          {
-            // FIXME ClassLoader - why should the class be visible from the context classloader? 
-            Class<?> annotation = SecurityActions.getContextClassLoader().loadClass(sub);
+            // FIXME ClassLoader - why should the class be visible from the context classloader?
+            ClassLoader cl = advisor.getClassLoader();
+            if (cl == null)
+            {
+               cl = SecurityActions.getContextClassLoader();
+            }
+            Class<?> annotation = cl.loadClass(sub);
             if (Annotation.class.isAssignableFrom(annotation))
             {
                if (AnnotationElement.getAnyAnnotation(clazz, (Class<? extends Annotation>)annotation) != null)

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/ProxyMatcherStrategy.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/ProxyMatcherStrategy.java	2008-08-20 13:28:25 UTC (rev 77240)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/pointcut/ProxyMatcherStrategy.java	2008-08-20 13:32:54 UTC (rev 77241)
@@ -50,8 +50,12 @@
       {
          if (advisor != null)
          {
-            // FIXME ClassLoader - why should the class be visible from the context classloader?
-            ClassLoader cl = SecurityActions.getContextClassLoader();
+            ClassLoader cl = advisor.getClassLoader();
+            if (cl == null)
+            {
+               //Fall back to context classloader
+               cl = SecurityActions.getContextClassLoader();
+            }
             ArrayList<InterfaceIntroduction> intros = advisor.getInterfaceIntroductions();
             if (intros.size() > 0)
             {

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/MarshalledInterfaceProxy.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/MarshalledInterfaceProxy.java	2008-08-20 13:28:25 UTC (rev 77240)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/MarshalledInterfaceProxy.java	2008-08-20 13:32:54 UTC (rev 77241)
@@ -58,8 +58,13 @@
    {
       try
       {
-         // FIXME ClassLoader - why should the class(es) be visible from the context classloader?
-         return ProxyFactory.createInterfaceProxy(guid, SecurityActions.getContextClassLoader(), interfaces, mixins, advisor);
+         ClassLoader cl = SecurityActions.getClassLoader(advisor.getInstance().getClass());
+         if (cl == null)
+         {
+            //Fall back to the context classloader
+            cl = SecurityActions.getContextClassLoader();
+         }
+         return ProxyFactory.createInterfaceProxy(guid, cl, interfaces, mixins, advisor);
       }
       catch (Exception e)
       {

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/SecurityActions.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/SecurityActions.java	2008-08-20 13:28:25 UTC (rev 77240)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/SecurityActions.java	2008-08-20 13:32:54 UTC (rev 77241)
@@ -98,4 +98,40 @@
       else
          return AccessController.doPrivileged(GetContextClassLoaderAction.INSTANCE);
    }
+   
+   interface GetClassLoaderAction 
+   {
+      ClassLoader getClassLoader(Class<?> clazz);
+      
+      GetClassLoaderAction NON_PRIVILEGED = new GetClassLoaderAction() {
+
+         public ClassLoader getClassLoader(Class<?> clazz)
+         {
+            return clazz.getClassLoader();
+         }};
+
+     GetClassLoaderAction PRIVILEGED = new GetClassLoaderAction() {
+
+         public ClassLoader getClassLoader(final Class<?> clazz)
+         {
+            return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+
+               public ClassLoader run()
+               {
+                  return clazz.getClassLoader();
+               }});
+         }};
+   }
+   
+   static ClassLoader getClassLoader(Class<?> clazz)
+   {
+      if (System.getSecurityManager() == null)
+      {
+         return GetClassLoaderAction.NON_PRIVILEGED.getClassLoader(clazz);
+      }
+      else
+      {
+         return GetClassLoaderAction.PRIVILEGED.getClassLoader(clazz);
+      }
+   }
 }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ClassProxyContainer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ClassProxyContainer.java	2008-08-20 13:28:25 UTC (rev 77240)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ClassProxyContainer.java	2008-08-20 13:32:54 UTC (rev 77241)
@@ -133,10 +133,14 @@
 
    private void addMethodsFromInterfaces(String[] intf) throws Exception
    {
-      ClassLoader cl = SecurityActions.getContextClassLoader();
+      ClassLoader cl = SecurityActions.getClassLoader(clazz);
+      if (cl == null)
+      {
+         //Fall back to context classloader
+         cl = SecurityActions.getContextClassLoader();
+      }
       for (int j = 0; intf != null && j < intf.length; ++j)
       {
-         // FIXME ClassLoader - why should the class be visible from the context classloader?
          Class<?> iface = cl.loadClass(intf[j]);
          Method[] ifaceMethods = iface.getMethods();
          for (int k = 0; k < ifaceMethods.length; k++)

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/SecurityActions.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/SecurityActions.java	2008-08-20 13:28:25 UTC (rev 77240)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/SecurityActions.java	2008-08-20 13:32:54 UTC (rev 77241)
@@ -24,6 +24,8 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 
+import org.jboss.aop.SecurityActions.GetClassLoaderAction;
+
 /**
  * SecurityActions.
  * 
@@ -50,4 +52,42 @@
       else
          return AccessController.doPrivileged(GetContextClassLoaderAction.INSTANCE);
    }
+   
+   
+   interface GetClassLoaderAction 
+   {
+      ClassLoader getClassLoader(Class<?> clazz);
+      
+      GetClassLoaderAction NON_PRIVILEGED = new GetClassLoaderAction() {
+
+         public ClassLoader getClassLoader(Class<?> clazz)
+         {
+            return clazz.getClassLoader();
+         }};
+
+     GetClassLoaderAction PRIVILEGED = new GetClassLoaderAction() {
+
+         public ClassLoader getClassLoader(final Class<?> clazz)
+         {
+            return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+
+               public ClassLoader run()
+               {
+                  return clazz.getClassLoader();
+               }});
+         }};
+   }
+   
+   static ClassLoader getClassLoader(Class<?> clazz)
+   {
+      if (System.getSecurityManager() == null)
+      {
+         return GetClassLoaderAction.NON_PRIVILEGED.getClassLoader(clazz);
+      }
+      else
+      {
+         return GetClassLoaderAction.PRIVILEGED.getClassLoader(clazz);
+      }
+   }
+
 }




More information about the jboss-cvs-commits mailing list