[jboss-cvs] JBossAS SVN: r82781 - in projects/aop/trunk: asintegration-jmx/src/main/org/jboss/aop/asintegration/jboss4 and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 12 11:54:24 EST 2009


Author: kabir.khan at jboss.com
Date: 2009-01-12 11:54:24 -0500 (Mon, 12 Jan 2009)
New Revision: 82781

Added:
   projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/asintegration/jboss4/ToClassInvoker.java
   projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/asintegration/jboss4/ToClassInvokerPoolReference.java
   projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ToClassInvoker.java
   projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ToClassInvokerPoolReference.java
Removed:
   projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/classpool/ucl/JBossClassPathHelper.java
Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassPool.java
   projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/asintegration/jboss4/JBossClassPool.java
   projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/classpool/ucl/JBossUclDelegatingClassPool.java
   projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/JBoss5ClassPool.java
   projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/classpool/jbosscl/JBossClDelegatingClassPool.java
Log:
[JBAOP-666] Move out duplicated code for toClass() methods of JBoss ClassPools

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassPool.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassPool.java	2009-01-12 16:49:06 UTC (rev 82780)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassPool.java	2009-01-12 16:54:24 UTC (rev 82781)
@@ -116,13 +116,6 @@
       classLoader = new WeakReference<ClassLoader>(cl);
    }
 
-//   public void registerGeneratedClass(String classname)
-//   {
-//      generatedClasses.put(classname, classname);
-//      String resourcename = getResourceName(classname);
-//      localResources.put(resourcename, Boolean.TRUE);
-//   }
-
    public void close()
    {
       super.close();

Modified: projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/asintegration/jboss4/JBossClassPool.java
===================================================================
--- projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/asintegration/jboss4/JBossClassPool.java	2009-01-12 16:49:06 UTC (rev 82780)
+++ projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/asintegration/jboss4/JBossClassPool.java	2009-01-12 16:54:24 UTC (rev 82781)
@@ -22,17 +22,17 @@
 package org.jboss.aop.asintegration.jboss4;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.net.URL;
 import java.security.ProtectionDomain;
 
-import org.jboss.aop.classpool.AOPClassPool;
-import org.jboss.mx.loading.RepositoryClassLoader;
 import javassist.CannotCompileException;
 import javassist.ClassPool;
 import javassist.CtClass;
 import javassist.scopedpool.ScopedClassPoolRepository;
 
+import org.jboss.aop.classpool.AOPClassPool;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
 /**
  * Comment
  *
@@ -40,21 +40,14 @@
  * @author adrian at jboss.org
  * @version $Revision$
  */
-public class JBossClassPool extends AOPClassPool
+public class JBossClassPool extends AOPClassPool implements ToClassInvokerPoolReference
 {
-   /**
-    * Used for dynamically created classes (see loadClass(String, byte[]), ClassLoader)
-    */
-   protected File tempdir = null;
-   protected URL tempURL = null;
-   // For loadClass tmpdir creation for UCL
-   protected final Object tmplock = new Object();
+   ToClassInvoker toClassInvoker = null;
    
    protected JBossClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, File tmp, URL tmpURL)
    {
       super(cl, src, repository);
-      tempdir = tmp;
-      tempURL = tmpURL;
+      toClassInvoker = new ToClassInvoker(tmp);
    }
 
    protected JBossClassPool(ClassPool src, ScopedClassPoolRepository repository)
@@ -72,66 +65,20 @@
       return false;
    }
 
-   public Class<?> toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain)
-   throws CannotCompileException
+   public Class<?> toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
    {
-      lockInCache(cc);
-      if (getClassLoader() == null || tempdir == null)
-      {
-         return super.toClass(cc, loader, domain);
-      }
-      Class<?> dynClass = null;
-      try
-      {
-         File classFile = null;
-         String classFileName = getResourceName(cc.getName());
-         // Write the clas file to the tmpdir
-         synchronized (tmplock)
-         {
-            classFile = new File(tempdir, classFileName);
-            File pkgDirs = classFile.getParentFile();
-            pkgDirs.mkdirs();
-            FileOutputStream stream = new FileOutputStream(classFile);
-            stream.write(cc.toBytecode());
-            stream.flush();
-            stream.close();
-            classFile.deleteOnExit();
-         }
-         // We have to clear Blacklist caches or the class will never
-         // be found
-         //((UnifiedClassLoader)dcl).clearBlacklists();
-         // To be backward compatible
-         RepositoryClassLoader rcl = (RepositoryClassLoader) getClassLoader();
-         rcl.clearClassBlackList();
-         rcl.clearResourceBlackList();
+      return toClassInvoker.toClass(this, cc, getResourceName(cc.getName()), loader, domain);
+   }
 
-         // Now load the class through the cl
-         dynClass = getClassLoader().loadClass(cc.getName());
-      }
-      catch (Exception ex)
-      {
-         ClassFormatError cfe = new ClassFormatError("Failed to load dyn class: " + cc.getName());
-         cfe.initCause(ex);
-         throw cfe;
-      }
-
-      return dynClass;
+   public Class<?> superPoolToClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+   {
+      return super.toClass(cc, loader, domain);
    }
 
    @Override
-   protected boolean isLocalResource(String resourceName)
+   public void lockInCache(CtClass clazz)
    {
-      if (super.isLocalResource(resourceName))
-      {
-         return true;
-      }
-      
-      File file = new File(tempdir, resourceName);
-      if (file.exists())
-      {
-         return true;
-      }
-      
-      return false;
+      super.lockInCache(clazz);
+      localResources.put(getResourceName(clazz.getName()), Boolean.TRUE);
    }
 }

Added: projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/asintegration/jboss4/ToClassInvoker.java
===================================================================
--- projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/asintegration/jboss4/ToClassInvoker.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/asintegration/jboss4/ToClassInvoker.java	2009-01-12 16:54:24 UTC (rev 82781)
@@ -0,0 +1,106 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.aop.asintegration.jboss4;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.CtClass;
+
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ToClassInvoker
+{
+   public File tmpDir;
+
+   public Object tmplock = new Object();
+
+   public ToClassInvoker(File tmpDir)
+   {
+      this.tmpDir = tmpDir;
+   }
+
+   public boolean isDynamicResource(String resourceName)
+   {
+      File file = new File(tmpDir, resourceName);
+      if (file.exists())
+      {
+         return true;
+      }
+      
+      return false;
+   }
+   
+   public Class<?> toClass(ToClassInvokerPoolReference pool, CtClass cc, String classFileName, ClassLoader loader, ProtectionDomain domain)
+   throws CannotCompileException
+   {
+      pool.lockInCache(cc);
+      final ClassLoader myloader = pool.getClassLoader();
+      if (myloader == null || tmpDir == null)
+      {
+         return pool.superPoolToClass(cc, loader, domain);
+      }
+      Class<?> dynClass = null;
+      try
+      {
+         File classFile = null;
+         // Write the clas file to the tmpdir
+         synchronized (tmplock)
+         {
+            classFile = new File(tmpDir, classFileName);
+            File pkgDirs = classFile.getParentFile();
+            pkgDirs.mkdirs();
+            FileOutputStream stream = new FileOutputStream(classFile);
+            stream.write(cc.toBytecode());
+            stream.flush();
+            stream.close();
+            classFile.deleteOnExit();
+         }
+         // We have to clear Blacklist caches or the class will never
+         // be found
+         //((UnifiedClassLoader)dcl).clearBlacklists();
+         // To be backward compatible
+         RepositoryClassLoader rcl = (RepositoryClassLoader)myloader;
+         rcl.clearClassBlackList();
+         rcl.clearResourceBlackList();
+
+         // Now load the class through the cl
+         dynClass = myloader.loadClass(cc.getName());
+      }
+      catch (Exception ex)
+      {
+         ClassFormatError cfe = new ClassFormatError("Failed to load dyn class: " + cc.getName());
+         cfe.initCause(ex);
+         throw cfe;
+      }
+
+      return dynClass;
+   }
+
+}

Added: projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/asintegration/jboss4/ToClassInvokerPoolReference.java
===================================================================
--- projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/asintegration/jboss4/ToClassInvokerPoolReference.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/asintegration/jboss4/ToClassInvokerPoolReference.java	2009-01-12 16:54:24 UTC (rev 82781)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.aop.asintegration.jboss4;
+
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.CtClass;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ToClassInvokerPoolReference
+{
+   Class<?> superPoolToClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException;
+   ClassLoader getClassLoader();
+   void lockInCache(CtClass clazz);
+}

Deleted: projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/classpool/ucl/JBossClassPathHelper.java
===================================================================
--- projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/classpool/ucl/JBossClassPathHelper.java	2009-01-12 16:49:06 UTC (rev 82780)
+++ projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/classpool/ucl/JBossClassPathHelper.java	2009-01-12 16:54:24 UTC (rev 82781)
@@ -1,41 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source.
-* Copyright 2006, Red Hat Middleware LLC, and individual contributors
-* as indicated by the @author tags. See the copyright.txt file in the
-* distribution for a full listing of individual contributors. 
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/ 
-package org.jboss.aop.classpool.ucl;
-
-import java.io.File;
-import java.net.URL;
-
-/**
- * 
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision: 1.1 $
- */
-public class JBossClassPathHelper
-{
-   File tmpDir;
-   URL tmpURL;
-   public JBossClassPathHelper(File tmpDir, URL tmpURL)
-   {
-      this.tmpDir = tmpDir;
-      this.tmpURL = tmpURL;
-   }
-}

Modified: projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/classpool/ucl/JBossUclDelegatingClassPool.java
===================================================================
--- projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/classpool/ucl/JBossUclDelegatingClassPool.java	2009-01-12 16:49:06 UTC (rev 82780)
+++ projects/aop/trunk/asintegration-jmx/src/main/org/jboss/aop/classpool/ucl/JBossUclDelegatingClassPool.java	2009-01-12 16:54:24 UTC (rev 82781)
@@ -22,7 +22,6 @@
 package org.jboss.aop.classpool.ucl;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.net.URL;
 import java.security.ProtectionDomain;
 
@@ -31,74 +30,41 @@
 import javassist.CtClass;
 import javassist.scopedpool.ScopedClassPoolRepository;
 
+import org.jboss.aop.asintegration.jboss4.ToClassInvoker;
+import org.jboss.aop.asintegration.jboss4.ToClassInvokerPoolReference;
 import org.jboss.aop.classpool.ClassPoolDomain;
 import org.jboss.aop.classpool.DelegatingClassPool;
-import org.jboss.mx.loading.RepositoryClassLoader;
 
 /**
  * 
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  * @version $Revision: 1.1 $
  */
-public class JBossUclDelegatingClassPool extends DelegatingClassPool
+public class JBossUclDelegatingClassPool extends DelegatingClassPool implements ToClassInvokerPoolReference
 {
-   File tmpDir;
-   URL tmpURL;
-   // For loadClass tmpdir creation for UCL
-   protected final Object tmplock = new Object();
+   ToClassInvoker toClassInvoker = null;
 
    public JBossUclDelegatingClassPool(ClassPoolDomain domain, ClassLoader cl, ClassPool parent, 
          ScopedClassPoolRepository repository, File tmpDir, URL tmpURL)
    {
       super(domain, cl, parent, repository);
-      this.tmpDir = tmpDir;
-      this.tmpURL = tmpURL;
+      toClassInvoker = new ToClassInvoker(tmpDir);
    }
 
-   public Class<?> toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain)
-   throws CannotCompileException
+   public Class<?> toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
    {
-      lockInCache(cc);
-      if (getClassLoader() == null || tmpDir == null)
-      {
-         return super.toClass(cc, loader, domain);
-      }
-      Class<?> dynClass = null;
-      try
-      {
-         File classFile = null;
-         String classFileName = getResourceName(cc.getName());
-         // Write the clas file to the tmpdir
-         synchronized (tmplock)
-         {
-            classFile = new File(tmpDir, classFileName);
-            File pkgDirs = classFile.getParentFile();
-            pkgDirs.mkdirs();
-            FileOutputStream stream = new FileOutputStream(classFile);
-            stream.write(cc.toBytecode());
-            stream.flush();
-            stream.close();
-            classFile.deleteOnExit();
-         }
-         // We have to clear Blacklist caches or the class will never
-         // be found
-         //((UnifiedClassLoader)dcl).clearBlacklists();
-         // To be backward compatible
-         RepositoryClassLoader rcl = (RepositoryClassLoader) getClassLoader();
-         rcl.clearClassBlackList();
-         rcl.clearResourceBlackList();
+      return toClassInvoker.toClass(this, cc, getResourceName(cc.getName()), loader, domain);
+   }
 
-         // Now load the class through the cl
-         dynClass = getClassLoader().loadClass(cc.getName());
-      }
-      catch (Exception ex)
-      {
-         ClassFormatError cfe = new ClassFormatError("Failed to load dyn class: " + cc.getName());
-         cfe.initCause(ex);
-         throw cfe;
-      }
-
-      return dynClass;
+   public Class<?> superPoolToClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+   {
+      return super.toClass(cc, loader, domain);
    }
 
+   @Override
+   public void lockInCache(CtClass clazz)
+   {
+      super.lockInCache(clazz);
+      localResources.put(getResourceName(clazz.getName()), Boolean.TRUE);
+   }
 }

Modified: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/JBoss5ClassPool.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/JBoss5ClassPool.java	2009-01-12 16:49:06 UTC (rev 82780)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/JBoss5ClassPool.java	2009-01-12 16:54:24 UTC (rev 82781)
@@ -21,8 +21,6 @@
 */ 
 package org.jboss.aop.asintegration.jboss5;
 
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
 import java.net.URL;
 import java.security.ProtectionDomain;
 
@@ -32,28 +30,25 @@
 import javassist.scopedpool.ScopedClassPoolRepository;
 
 import org.jboss.aop.classpool.AOPClassPool;
-import org.jboss.classloader.spi.base.BaseClassLoader;
 import org.jboss.logging.Logger;
-import org.jboss.virtual.plugins.context.memory.MemoryContextFactory;
 
 /**
  * 
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  * @version $Revision: 1.1 $
  */
-public class JBoss5ClassPool extends AOPClassPool
+public class JBoss5ClassPool extends AOPClassPool implements ToClassInvokerPoolReference
 {
    Logger log = Logger.getLogger(JBoss5ClassPool.class);
 
-   protected URL tempURL = null;
-   // For loadClass tmpdir creation for UCL
-   protected final Object tmplock = new Object();
+   protected ToClassInvoker toClassInvoker = null;
+
    boolean closed;
    
    protected JBoss5ClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, URL tmpURL)
    {
       super(cl, src, repository);
-      tempURL = tmpURL;
+      toClassInvoker = new ToClassInvoker(tmpURL);
    }
 
    protected JBoss5ClassPool(ClassPool src, ScopedClassPoolRepository repository)
@@ -74,47 +69,11 @@
 
    public Class<?> toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
    {
-      lockInCache(cc);
-      final ClassLoader myloader = getClassLoader();
-      if (myloader == null || tempURL == null)
-      {
-         return super.toClass(cc, loader, domain);
-      }
-      
-      try
-      {
-         String classFileName = getResourceName(cc.getName());
-         URL outputURL = new URL(tempURL.toString() + "/" + classFileName);
-         //Write the classfile to the temporary url
-         synchronized (tmplock)
-         {
-            ByteArrayOutputStream byteout = new ByteArrayOutputStream();
-            BufferedOutputStream out = new BufferedOutputStream(byteout);
-            out.write(cc.toBytecode());
-            out.flush();
-            out.close();
-            
-            byte[] classBytes = byteout.toByteArray();
-            MemoryContextFactory factory = MemoryContextFactory.getInstance();
-            factory.putFile(outputURL, classBytes);
+      return toClassInvoker.toClass(this, cc, getResourceName(cc.getName()), loader, domain);
+   }
 
-            if (myloader instanceof BaseClassLoader)
-            {
-               //Update check to RealClassLoader once integration project catches up
-               ((BaseClassLoader)myloader).clearBlackList(classFileName);
-               
-            }
-            
-            Class<?> clazz = myloader.loadClass(cc.getName());
-
-            return clazz;
-         }
-      }
-      catch(Exception e)
-      {
-       ClassFormatError cfe = new ClassFormatError("Failed to load dyn class: " + cc.getName() + " on " + this + " loader:" + myloader);
-       cfe.initCause(e);
-       throw cfe;
-      }
+   public Class<?> superPoolToClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+   {
+      return super.toClass(cc, loader, domain);
    }
 }

Added: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ToClassInvoker.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ToClassInvoker.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ToClassInvoker.java	2009-01-12 16:54:24 UTC (rev 82781)
@@ -0,0 +1,92 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.aop.asintegration.jboss5;
+
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.net.URL;
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.CtClass;
+
+import org.jboss.classloading.spi.RealClassLoader;
+import org.jboss.virtual.plugins.context.memory.MemoryContextFactory;
+
+/**
+ * @author  <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version  $Revision: 1.1 $
+ */
+public class ToClassInvoker
+{
+   public URL tempURL;
+
+   public Object tmplock = new Object();
+
+   public ToClassInvoker(URL tempURL)
+   {
+      this.tempURL = tempURL;
+   }
+
+   public Class<?> toClass(ToClassInvokerPoolReference pool, CtClass cc, String classFileName, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+   {
+      pool.lockInCache(cc);
+      final ClassLoader myloader = pool.getClassLoader();
+      if (myloader == null || tempURL == null)
+      {
+         return pool.superPoolToClass(cc, loader, domain);
+      }
+      
+      try
+      {
+         URL outputURL = new URL(tempURL.toString() + "/" + classFileName);
+         //Write the classfile to the temporary url
+         synchronized (tmplock)
+         {
+            ByteArrayOutputStream byteout = new ByteArrayOutputStream();
+            BufferedOutputStream out = new BufferedOutputStream(byteout);
+            out.write(cc.toBytecode());
+            out.flush();
+            out.close();
+            
+            byte[] classBytes = byteout.toByteArray();
+            MemoryContextFactory factory = MemoryContextFactory.getInstance();
+            factory.putFile(outputURL, classBytes);
+
+            if (myloader instanceof RealClassLoader)
+            {
+               ((RealClassLoader)myloader).clearBlackList(classFileName);
+            }
+            
+            Class<?> clazz = myloader.loadClass(cc.getName());
+            
+            return clazz;
+         }
+      }
+      catch(Exception e)
+      {
+       ClassFormatError cfe = new ClassFormatError("Failed to load dyn class: " + cc.getName() + " on " + this + " loader:" + myloader);
+       cfe.initCause(e);
+       throw cfe;
+      }
+   }
+}
\ No newline at end of file

Added: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ToClassInvokerPoolReference.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ToClassInvokerPoolReference.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/asintegration/jboss5/ToClassInvokerPoolReference.java	2009-01-12 16:54:24 UTC (rev 82781)
@@ -0,0 +1,40 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.aop.asintegration.jboss5;
+
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.CtClass;
+
+/**
+ * Exposes methods on ClassPool needed by JBoss5ClassPool
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ToClassInvokerPoolReference
+{
+   Class<?> superPoolToClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException;
+   ClassLoader getClassLoader();
+   void lockInCache(CtClass clazz);
+}

Modified: projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/classpool/jbosscl/JBossClDelegatingClassPool.java
===================================================================
--- projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/classpool/jbosscl/JBossClDelegatingClassPool.java	2009-01-12 16:49:06 UTC (rev 82780)
+++ projects/aop/trunk/asintegration-mc/src/main/org/jboss/aop/classpool/jbosscl/JBossClDelegatingClassPool.java	2009-01-12 16:54:24 UTC (rev 82781)
@@ -21,9 +21,6 @@
 */ 
 package org.jboss.aop.classpool.jbosscl;
 
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.net.URL;
 import java.security.ProtectionDomain;
 
 import javassist.CannotCompileException;
@@ -31,23 +28,23 @@
 import javassist.CtClass;
 import javassist.scopedpool.ScopedClassPoolRepository;
 
+import org.jboss.aop.asintegration.jboss5.ToClassInvoker;
+import org.jboss.aop.asintegration.jboss5.ToClassInvokerPoolReference;
 import org.jboss.aop.classpool.ClassPoolDomain;
 import org.jboss.aop.classpool.DelegatingClassPool;
-import org.jboss.classloader.spi.base.BaseClassLoader;
 import org.jboss.classloading.spi.dependency.Module;
-import org.jboss.virtual.plugins.context.memory.MemoryContextFactory;
 
 /**
  * 
  * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
  * @version $Revision: 1.1 $
  */
-public class JBossClDelegatingClassPool extends DelegatingClassPool
+public class JBossClDelegatingClassPool extends DelegatingClassPool implements ToClassInvokerPoolReference
 {
    private Module module;
-   // For loadClass tmpdir creation for UCL
-   protected final Object tmplock = new Object();
 
+   ToClassInvoker toClassInvoker;
+   
    protected JBossClDelegatingClassPool(ClassPoolDomain domain, ClassLoader cl, ClassPool parent,
          ScopedClassPoolRepository repository, Module module)
    {
@@ -61,6 +58,8 @@
          throw new IllegalArgumentException("Domain was not instance of JBossClClassPoolDomain: " + domain.getClass().getName());
       }
       this.module = module;
+      toClassInvoker = new ToClassInvoker(module == null ? null : module.getDynamicClassRoot());
+         
       ((JBossClClassPoolDomain)domain).setupPoolsByPackage(this);
    }
 
@@ -69,51 +68,14 @@
       return module;
    }
    
-   //Copied from JBoss5ClassPool
    public Class<?> toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
    {
-      lockInCache(cc);
-      final ClassLoader myloader = getClassLoader();
-      if (myloader == null || module.getDynamicClassRoot() == null)
-      {
-         return super.toClass(cc, loader, domain);
-      }
-      
-      try
-      {
-         String classFileName = getResourceName(cc.getName());
-         URL outputURL = new URL(module.getDynamicClassRoot().toString() + "/" + classFileName);
-         //Write the classfile to the temporary url
-         synchronized (tmplock)
-         {
-            ByteArrayOutputStream byteout = new ByteArrayOutputStream();
-            BufferedOutputStream out = new BufferedOutputStream(byteout);
-            out.write(cc.toBytecode());
-            out.flush();
-            out.close();
-            
-            byte[] classBytes = byteout.toByteArray();
-            MemoryContextFactory factory = MemoryContextFactory.getInstance();
-            factory.putFile(outputURL, classBytes);
+      return toClassInvoker.toClass(this, cc, getResourceName(cc.getName()), loader, domain);
+   }
 
-            if (myloader instanceof BaseClassLoader)
-            {
-               //Update check to RealClassLoader once integration project catches up
-               ((BaseClassLoader)myloader).clearBlackList(classFileName);
-               
-            }
-            
-            Class<?> clazz = myloader.loadClass(cc.getName());
-
-            return clazz;
-         }
-      }
-      catch(Exception e)
-      {
-       ClassFormatError cfe = new ClassFormatError("Failed to load dyn class: " + cc.getName() + " on " + this + " loader:" + myloader);
-       cfe.initCause(e);
-       throw cfe;
-      }
+   public Class<?> superPoolToClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+   {
+      return super.toClass(cc, loader, domain);
    }
 
 }




More information about the jboss-cvs-commits mailing list