[jboss-cvs] JBossAS SVN: r64495 - in projects/aop/trunk/aop/src/main/org/jboss/aop: advice and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 7 22:57:38 EDT 2007


Author: adrian at jboss.org
Date: 2007-08-07 22:57:38 -0400 (Tue, 07 Aug 2007)
New Revision: 64495

Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GeneratedAdvisorInterceptor.java
Log:
Add an option to always push the advised class's classloader for advice generation - only partly implemented

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java	2007-08-08 02:56:49 UTC (rev 64494)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java	2007-08-08 02:57:38 UTC (rev 64495)
@@ -48,6 +48,8 @@
 
 import org.jboss.aop.advice.AdviceBinding;
 import org.jboss.aop.advice.AspectDefinition;
+import org.jboss.aop.advice.AspectFactory;
+import org.jboss.aop.advice.AspectFactoryWithClassLoaderSupport;
 import org.jboss.aop.advice.CFlowInterceptor;
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.advice.InterceptorFactory;
@@ -78,6 +80,7 @@
 
 /**
  * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author adrian at jboss.org
  * @version $Revision$
  */
 public abstract class Advisor
@@ -672,7 +675,21 @@
    public abstract void removeClassMetaData(ClassMetaDataBinding data);
 
    // This is aspect stuff.  Aspect again, is a class that encapsulates advices
-
+   
+   public Object getPerVMAspect(AspectDefinition def)
+   {
+      AspectFactoryWithClassLoaderSupport pushed = pushClassLoader(def);
+      try
+      {
+         return getManager().getPerVMAspect(def);
+      }
+      finally
+      {
+         if (pushed != null)
+            popClassLoader(pushed);
+      }
+   }
+   
    public void addPerInstanceAspect(AspectDefinition def)
    {
       initPerInstanceAspectDefinitionsSet();
@@ -741,9 +758,18 @@
    public void addPerClassAspect(AspectDefinition def)
    {
       if (aspects.containsKey(def.getName())) return;
-      Object aspect = def.getFactory().createPerClass(this);
-      aspects.put(def.getName(), aspect);
-      def.registerAdvisor(this);
+      AspectFactoryWithClassLoaderSupport pushed = pushClassLoader(def);
+      try
+      {
+         Object aspect = def.getFactory().createPerClass(this);
+         aspects.put(def.getName(), aspect);
+         def.registerAdvisor(this);
+      }
+      finally
+      {
+         if (pushed != null)
+            popClassLoader(pushed);
+      }
    }
 
    public void removePerClassAspect(AspectDefinition def)
@@ -1311,4 +1337,23 @@
          }
       }
    }
+
+   private AspectFactoryWithClassLoaderSupport pushClassLoader(AspectDefinition def)
+   {
+      if (getManager().isPushClassLoader() == false)
+         return null;
+      
+      AspectFactory factory = def.getFactory();
+      if (factory instanceof AspectFactoryWithClassLoaderSupport)
+      {
+         AspectFactoryWithClassLoaderSupport result = (AspectFactoryWithClassLoaderSupport) factory;
+         result.pushScopedClassLoader(getClazz().getClassLoader());
+      }
+      return null;
+   }
+   
+   private void  popClassLoader(AspectFactoryWithClassLoaderSupport factory)
+   {
+      factory.popScopedClassLoader();
+   }
 }
\ No newline at end of file

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java	2007-08-08 02:56:49 UTC (rev 64494)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java	2007-08-08 02:57:38 UTC (rev 64495)
@@ -180,6 +180,9 @@
    // indicates that the transformation process has begun
    protected boolean transformationStarted = false;
 
+   /** Whether to push the classloader of the advised class when generating aspects */
+   protected boolean pushClassLoader = false;
+   
    @Deprecated // replaced by the temporary AOPClassLoaderScopingPolicy - no longer referenced
    protected static AOPScopedClassLoaderHelper scopedCLHelper;
    
@@ -368,6 +371,26 @@
       AspectManager.classLoaderScopingPolicy = classLoaderScopingPolicy;
    }
 
+   /**
+    * Get the pushClassLoader.
+    * 
+    * @return the pushClassLoader.
+    */
+   public boolean isPushClassLoader()
+   {
+      return pushClassLoader;
+   }
+
+   /**
+    * Set the pushClassLoader.
+    * 
+    * @param pushClassLoader the pushClassLoader.
+    */
+   public void setPushClassLoader(boolean pushClassLoader)
+   {
+      this.pushClassLoader = pushClassLoader;
+   }
+
    public InterceptionMarkers getInterceptionMarkers()
    {
       return interceptionMarkers;

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java	2007-08-08 02:56:49 UTC (rev 64494)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java	2007-08-08 02:57:38 UTC (rev 64495)
@@ -1032,5 +1032,8 @@
       return parent.isSet();
    }
 
-
+   public boolean isPushClassLoader()
+   {
+      return parent.isPushClassLoader();
+   }
 }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GeneratedAdvisorInterceptor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GeneratedAdvisorInterceptor.java	2007-08-08 02:56:49 UTC (rev 64494)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/GeneratedAdvisorInterceptor.java	2007-08-08 02:57:38 UTC (rev 64495)
@@ -188,7 +188,7 @@
       {
          if (instance == null)
          {
-            instance = advisor.getManager().getPerVMAspect(def);
+            instance = advisor.getPerVMAspect(def);
          }
          return instance;
       }




More information about the jboss-cvs-commits mailing list