[jboss-cvs] JBossAS SVN: r79519 - in projects/aop/trunk/asintegration-core: src and 12 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 15 05:57:48 EDT 2008


Author: kabir.khan at jboss.com
Date: 2008-10-15 05:57:47 -0400 (Wed, 15 Oct 2008)
New Revision: 79519

Added:
   projects/aop/trunk/asintegration-core/src/assembly/
   projects/aop/trunk/asintegration-core/src/assembly/test-classpool-a.xml
   projects/aop/trunk/asintegration-core/src/assembly/test-classpool-b.xml
   projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractIsLocalResourcePlugin.java
   projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/ClassPoolDomain.java
   projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DefaultClassLoaderIsLocalResourcePlugin.java
   projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DefaultClassLoaderIsLocalResourcePluginFactory.java
   projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DelegatingClassPool.java
   projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DomainClassPoolRules.java
   projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/IsLocalResourcePlugin.java
   projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/IsLocalResourcePluginFactory.java
   projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/IsLocalResourcePluginFactoryRegistry.java
   projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/TranslatableClassLoaderIsLocalResourcePlugin.java
   projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/TranslatableClassLoaderIsLocalResourcePluginFactory.java
   projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/URLClassLoaderIsLocalResourcePlugin.java
   projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/URLClassLoaderIsLocalResourcePluginFactory.java
   projects/aop/trunk/asintegration-core/src/tests/
   projects/aop/trunk/asintegration-core/src/tests/org/
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/support/
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/support/a/
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/support/a/A.java
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/support/b/
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/support/b/B.java
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ClassPoolTest.java
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ClassPoolTestDelegate.java
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/DelegatingClassPoolTestSuite.java
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/IsLocalResourcePluginFactoryTestCase.java
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ParentFirstDelegatingClassPoolTestCase.java
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ParentLastDelegatingClassPoolTestCase.java
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ScopedSiblingDelegatingClassPoolTestCase.java
   projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/SimpleDelegatingClassPoolTestCase.java
Modified:
   projects/aop/trunk/asintegration-core/.classpath
   projects/aop/trunk/asintegration-core/pom.xml
   projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractJBossClassPoolFactory.java
Log:
[JBAOP-666] Start reimplementing classloaders

Modified: projects/aop/trunk/asintegration-core/.classpath
===================================================================
--- projects/aop/trunk/asintegration-core/.classpath	2008-10-15 09:49:05 UTC (rev 79518)
+++ projects/aop/trunk/asintegration-core/.classpath	2008-10-15 09:57:47 UTC (rev 79519)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" path="src/main"/>
+   <classpathentry excluding="org/jboss/test/aop/classpool/support/a/|org/jboss/test/aop/classpool/support/b/B.java" kind="src" path="src/tests"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/aop"/>
 	<classpathentry kind="lib" path="/thirdparty/javassist/lib/javassist.jar" sourcepath="/javassist"/>
@@ -8,5 +9,7 @@
 	<classpathentry kind="lib" path="/thirdparty/jboss/common-logging-spi/lib/jboss-logging-spi.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/jbossas/core-libs/lib/jboss-system.jar"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/pluggable-instrumentor"/>
+	<classpathentry kind="lib" path="/thirdparty/junit/lib/junit.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/jboss/test/lib/jboss-test.jar" sourcepath="/thirdparty/jboss/test/lib/jboss-test-sources.jar"/>
 	<classpathentry kind="output" path="eclipse-output"/>
 </classpath>

Modified: projects/aop/trunk/asintegration-core/pom.xml
===================================================================
--- projects/aop/trunk/asintegration-core/pom.xml	2008-10-15 09:49:05 UTC (rev 79518)
+++ projects/aop/trunk/asintegration-core/pom.xml	2008-10-15 09:57:47 UTC (rev 79519)
@@ -46,6 +46,23 @@
             </goals>
           </execution>
         </executions>
+        <configuration>
+          <excludes>
+            <exclude>org/jboss/test/aop/classpool/support/a/A.class</exclude>
+            <exclude>org/jboss/test/aop/classpool/support/b/B.class</exclude>
+          </excludes>
+        </configuration>
+        <!-- fileSets>
+          <fileSet>
+            <directory>target/test-classes</directory>
+            <outputDirectory>/</outputDirectory>
+            <excludes>
+              <exclude>org/jboss/test/aop/classpool/support/a/A.class</exclude>
+              <exclude>org/jboss/test/aop/classpool/support/b/B.class</exclude>
+            </excludes>
+          </fileSet>
+        </fileSets -->
+        
       </plugin>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
@@ -85,6 +102,16 @@
       <groupId>org.jboss.logging</groupId>
       <artifactId>jboss-logging-spi</artifactId>
     </dependency>
+    <dependency>
+      <groupId>jboss</groupId>
+      <artifactId>jboss-test</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>compile</scope>
+    </dependency>
   </dependencies>
   
 </project>

Added: projects/aop/trunk/asintegration-core/src/assembly/test-classpool-a.xml
===================================================================
--- projects/aop/trunk/asintegration-core/src/assembly/test-classpool-a.xml	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/assembly/test-classpool-a.xml	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,16 @@
+<assembly>
+  <id>test-classpool-a</id>
+  <formats>
+    <format>jar</format>
+  </formats>
+  <includeBaseDirectory>false</includeBaseDirectory>
+  <fileSets>
+    <fileSet>
+      <directory>target/test-classes</directory>
+      <outputDirectory>/</outputDirectory>
+      <includes>
+        <include>org/jboss/test/aop/classpool/support/a/A.class</include>
+      </includes>
+    </fileSet>
+  </fileSets>
+</assembly>
\ No newline at end of file

Added: projects/aop/trunk/asintegration-core/src/assembly/test-classpool-b.xml
===================================================================
--- projects/aop/trunk/asintegration-core/src/assembly/test-classpool-b.xml	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/assembly/test-classpool-b.xml	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,16 @@
+<assembly>
+  <id>test-classpool-b</id>
+  <formats>
+    <format>jar</format>
+  </formats>
+  <includeBaseDirectory>false</includeBaseDirectory>
+  <fileSets>
+    <fileSet>
+      <directory>target/test-classes</directory>
+      <outputDirectory>/</outputDirectory>
+      <includes>
+        <include>org/jboss/test/aop/classpool/support/b/B.class</include>
+      </includes>
+    </fileSet>
+  </fileSets>
+</assembly>
\ No newline at end of file

Added: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractIsLocalResourcePlugin.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractIsLocalResourcePlugin.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractIsLocalResourcePlugin.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,45 @@
+/*
+* 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;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractIsLocalResourcePlugin implements IsLocalResourcePlugin
+{
+   private final DelegatingClassPool pool;
+   
+   public AbstractIsLocalResourcePlugin(DelegatingClassPool pool)
+   {
+      this.pool = pool;
+      initialise();
+   }
+
+   protected abstract void initialise();
+   
+   protected DelegatingClassPool getPool()
+   {
+      return pool;
+   }
+}

Modified: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractJBossClassPoolFactory.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractJBossClassPoolFactory.java	2008-10-15 09:49:05 UTC (rev 79518)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/AbstractJBossClassPoolFactory.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -21,6 +21,8 @@
 */ 
 package org.jboss.aop.classpool;
 
+import org.jboss.logging.Logger;
+
 import javassist.ClassPool;
 import javassist.scopedpool.ScopedClassPool;
 import javassist.scopedpool.ScopedClassPoolRepository;
@@ -32,6 +34,8 @@
  */
 public abstract class AbstractJBossClassPoolFactory
 {
+   protected final Logger log = Logger.getLogger(this.getClass().getName());
+   
    protected ClassPool getCreateParentClassPools(final ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
    {
       //Make sure that we get classpools for all the parent classloaders

Added: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/ClassPoolDomain.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/ClassPoolDomain.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/ClassPoolDomain.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,272 @@
+/*
+* 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;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+
+import org.jboss.aop.AspectManager;
+
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolDomain
+{
+   private String domainName;
+   
+   private ClassPoolDomain parent;
+   
+   private List<DelegatingClassPool> delegatingPools = new ArrayList<DelegatingClassPool>();
+   
+   private ClassPoolDomainStrategy classPoolDomainStrategy;
+   
+   private boolean parentFirst;
+
+   public ClassPoolDomain(String domainName, ClassPoolDomain parent)
+   {
+      this.parent = parent;
+      this.domainName = domainName;
+
+      if (parent == null)
+      {
+         classPoolDomainStrategy = new RootClassPoolDomainImpl();
+      }
+      else 
+      {
+         classPoolDomainStrategy = new ChildClassPoolDomainImpl();
+      }
+   }
+   
+   public String getDomainName()
+   {
+      return domainName;
+   }
+ 
+   public boolean isParentFirst()
+   {
+      return parentFirst;
+   }
+
+   public void setParentFirst(boolean parentFirst)
+   {
+      this.parentFirst = parentFirst;
+   }
+
+   synchronized void addClassPool(DelegatingClassPool pool)
+   {
+      if (!delegatingPools.contains(pool))
+      {
+         delegatingPools.add(pool);
+      }
+   }
+   
+   synchronized void removeClassPool(DelegatingClassPool pool)
+   {
+      delegatingPools.remove(pool);
+   }
+   
+   synchronized CtClass getCached(DelegatingClassPool initiating, String classname)
+   {
+      if (parentFirst)
+      {
+         CtClass clazz = classPoolDomainStrategy.getParentCached(classname);
+         if (clazz != null)
+         {
+            return clazz;
+         }
+      }
+      for(DelegatingClassPool pool : delegatingPools)
+      {
+         if (pool == initiating)
+         {
+            continue;
+         }
+         if (pool.isUnloadedClassLoader())
+         {
+            AspectManager.instance().unregisterClassLoader(pool.getClassLoader());
+            continue;
+         }
+         CtClass clazz = pool.getCached(false, classname);
+         if (clazz != null)
+         {
+            return clazz;
+         }
+      }
+
+      if (!parentFirst)
+      {
+         return classPoolDomainStrategy.getParentCached(classname); 
+      }
+
+      return null;
+   }
+   
+   synchronized CtClass createCtClass(DelegatingClassPool initiating, String classname, boolean useCache)
+   {
+      if (parentFirst)
+      {
+         CtClass clazz = createParentCtClass(classname, useCache);
+         if (clazz != null)
+         {
+            return clazz;
+         }
+      }
+      for(DelegatingClassPool pool : delegatingPools)
+      {
+         if (pool == initiating)
+         {
+            continue;
+         }
+         if (pool.isUnloadedClassLoader())
+         {
+            AspectManager.instance().unregisterClassLoader(pool.getClassLoader());
+            continue;
+         }
+         CtClass clazz = pool.createCtClass(false, classname, useCache);
+         if (clazz != null)
+         {
+            return clazz;
+         }
+      }
+
+      if (!parentFirst)
+      {
+         return createParentCtClass(classname, useCache); 
+      }
+      return null;
+   }
+   
+   synchronized CtClass createParentCtClass(String classname, boolean useCache)
+   {
+      return classPoolDomainStrategy.createParentCtClass(classname, useCache);
+   }
+   
+   synchronized URL findParentResource(String classname)
+   {
+      return classPoolDomainStrategy.findParentResource(classname);
+   }
+   
+   synchronized URL findResource(String classname)
+   {
+      if (parentFirst)
+      {
+         URL url = classPoolDomainStrategy.findParentResource(classname);
+         if (url != null)
+         {
+            return url;
+         }
+      }
+      for (DelegatingClassPool pool : delegatingPools)
+      {
+         if (pool.isUnloadedClassLoader())
+         {
+            AspectManager.instance().unregisterClassLoader(pool.getClassLoader());
+            continue;
+         }
+         if (pool.isLocalClassLoaderClass(classname))
+         {
+            URL url = pool.find(classname);
+            if (url != null)
+            {
+               return url;
+            }
+         }
+      }
+      if (!parentFirst)
+      {
+         return classPoolDomainStrategy.findParentResource(classname);
+      }
+      return null;
+   }
+   
+   public String toString()
+   {
+      return super.toString() + "[" + domainName + "]";
+   }
+   
+   private interface ClassPoolDomainStrategy
+   {
+      URL findParentResource(String classname);
+      CtClass createParentCtClass(String classname, boolean useCache);
+      CtClass getParentCached(String classname);
+   }
+   
+   private class RootClassPoolDomainImpl implements ClassPoolDomainStrategy
+   {
+      ClassPool defaultPool = ClassPool.getDefault();
+      
+      public URL findParentResource(String classname)
+      {
+         return defaultPool.find(classname);
+      }
+      
+      public CtClass createParentCtClass(String classname, boolean useCache)
+      {
+         try
+         {
+            return defaultPool.get(classname);
+         }
+         catch(NotFoundException ignore)
+         {
+         }
+         return null;
+      }
+      
+      public CtClass getParentCached(String classname)
+      {
+         try
+         {
+            return defaultPool.get(classname);
+         }
+         catch (NotFoundException ignore)
+         {
+         }
+         return null;
+      }
+   }
+   
+   private class ChildClassPoolDomainImpl implements ClassPoolDomainStrategy
+   {
+      public URL findParentResource(String classname)
+      {
+         return parent.findResource(classname);
+      }
+      
+      public CtClass createParentCtClass(String classname, boolean useCache)
+      {
+         return parent.createCtClass(null, classname, useCache);
+      }
+      
+      public CtClass getParentCached(String classname)
+      {
+         return parent.getCached(null, classname);
+      }
+   }
+}

Added: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DefaultClassLoaderIsLocalResourcePlugin.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DefaultClassLoaderIsLocalResourcePlugin.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DefaultClassLoaderIsLocalResourcePlugin.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,46 @@
+/*
+* 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;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultClassLoaderIsLocalResourcePlugin extends AbstractIsLocalResourcePlugin implements IsLocalResourcePlugin
+{
+   public DefaultClassLoaderIsLocalResourcePlugin(DelegatingClassPool pool)
+   {
+      super(pool);
+   }
+
+   @Override
+   protected void initialise()
+   {
+   }
+
+   public boolean isMyResource(String resourceName)
+   {
+      return getPool().getClassLoader().getResource(resourceName) != null;
+   }
+
+}

Added: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DefaultClassLoaderIsLocalResourcePluginFactory.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DefaultClassLoaderIsLocalResourcePluginFactory.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DefaultClassLoaderIsLocalResourcePluginFactory.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,37 @@
+/*
+* 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;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultClassLoaderIsLocalResourcePluginFactory implements IsLocalResourcePluginFactory
+{
+
+   public IsLocalResourcePlugin create(DelegatingClassPool pool)
+   {
+      return new DefaultClassLoaderIsLocalResourcePlugin(pool);
+   }
+
+}

Added: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DelegatingClassPool.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DelegatingClassPool.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DelegatingClassPool.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,233 @@
+/*
+* 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;
+
+import java.net.URL;
+
+import javassist.CtClass;
+import javassist.NotFoundException;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.logging.Logger;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DelegatingClassPool extends AOPClassPool //TODO It would be great not to have this redundant code
+{
+   private final static Logger logger = Logger.getLogger(DelegatingClassPool.class);
+   private final ClassPoolDomain domain;
+   
+   private boolean isTemp;
+   
+   private boolean closed;
+   
+   private IsLocalResourcePlugin isLocalResourcePlugin;
+   
+   public DelegatingClassPool(ClassPoolDomain domain, ClassLoader cl, ScopedClassPoolRepository repository, boolean isTemp)
+   {
+      super(cl, null, repository);
+      this.domain = domain;
+      domain.addClassPool(this);
+      isLocalResourcePlugin = IsLocalResourcePluginFactoryRegistry.getPluginFactory(cl).create(this);
+   }
+
+   protected DelegatingClassPool(ClassPoolDomain domain, ClassLoader cl, ScopedClassPoolRepository repository)
+   {
+      super(cl, null, repository);
+      this.domain = domain;
+      domain.addClassPool(this);
+      isLocalResourcePlugin = IsLocalResourcePluginFactoryRegistry.getPluginFactory(cl).create(this);
+   }
+
+   public CtClass get(String classname) throws NotFoundException 
+   {
+      System.out.println("==> Initiating lookup of " + classname + " in " + this);
+      if (logger.isTraceEnabled())
+      {
+         logger.trace("Initiating lookup of " + classname + " in " + this);
+      }
+      return super.get(classname);
+   }
+
+   
+   /**
+    * Overrides ClassPool.get0() so that we can look up classes without caching them in the initiating pool.
+    * The DelgatingClassPool + DomainClassPool handle the caching in the correct pool + handles the 
+    * parentFirst functionality
+    */
+   @Override
+   protected synchronized CtClass get0(String classname, boolean useCache) throws NotFoundException
+   {
+      CtClass clazz = null;
+      if (useCache) 
+      {
+         clazz = getCached(classname);
+         if (clazz != null)
+         {
+            return clazz;
+         }
+      }
+   
+      return createCtClass(classname, useCache);
+   }
+
+
+   
+   @Override
+   public boolean isUnloadedClassLoader()
+   {
+      return closed;
+   }
+
+   @Override
+   public void close()
+   {
+      closed = true;
+      super.close();
+      domain.removeClassPool(this);
+   }
+
+   @Override
+   public CtClass getCached(String classname)
+   {
+      return getCached(true, classname);
+   }
+   
+   
+   CtClass getCached(boolean isInitiatingPool, String classname)
+   {
+      if (isInitiatingPool && domain.isParentFirst())
+      {
+         CtClass clazz = domain.getCached(this, classname);
+         if (clazz != null)
+         {
+            return clazz;
+         }
+      }
+      CtClass clazz = getCachedLocally(classname);
+      if (clazz != null)
+      {
+         System.out.println("==> Found cached class " + classname + " in " + this);
+         if (logger.isTraceEnabled())
+         {
+            logger.trace("Found cached class " + classname + " in " + this);
+         }
+         return clazz;
+      }
+      if (clazz == null)
+      {
+         boolean isLocal = false;
+
+         ClassLoader cl = getClassLoader0();
+
+         if (cl != null)
+         {
+            isLocal = isLocalResource(classname);
+         }
+
+         if (!isLocal)
+         {
+            Object o = generatedClasses.get(classname);
+            if (o == null && isInitiatingPool)
+            {
+               return domain.getCached(this, classname);
+            }
+         }
+      }
+      // *NOTE* NEED TO TEST WHEN SUPERCLASS IS IN ANOTHER UCL!!!!!!
+      return null;
+   }
+   
+
+   @Override
+   protected CtClass createCtClass(String classname, boolean useCache)
+   {
+      return createCtClass(true, classname, useCache);
+   }
+   
+   CtClass createCtClass(boolean isInitiatingPool, String classname, boolean useCache)
+   {
+      CtClass clazz = null;
+      if (isLocalResource(classname))
+      {
+         URL classUrl = find(classname);
+   
+         boolean create = true;
+         if (domain.isParentFirst())
+         {
+            if (domain.findParentResource(classname) != null)
+            {
+               create = false;
+            }
+         }
+         
+         if (create)
+         {
+            clazz = super.createCtClass(classname, useCache);
+            if (clazz != null && useCache)
+            {
+               if (useCache)
+               {
+                  System.out.println("==> Caching class " + classname + " in " + this);
+                  if (logger.isTraceEnabled())
+                  {
+                     logger.trace("Caching class " + classname + " in " + this);
+                  }
+                  cacheCtClass(clazz.getName(), clazz, false);
+               }
+            }
+         }
+      }
+      if (clazz == null && isInitiatingPool)
+      {
+         return domain.createCtClass(this, classname, useCache);
+      }
+      return clazz;
+   }
+
+   //Lifted from AOPClassPool, also exists in JBossClassPool
+   @Override
+   protected boolean isLocalResource(String resourceName)
+   {
+      return super.isLocalResource(resourceName);
+   }
+
+   @Override
+   public boolean isLocalClassLoaderResource(String classResourceName)
+   {
+      return isLocalResourcePlugin.isMyResource(classResourceName);
+   }
+
+   public boolean isLocalClassLoaderClass(String classname)
+   {
+      return isLocalResourcePlugin.isMyResource(getResourceName(classname));
+   }
+
+   @Override
+   public String toString()
+   {
+      return super.toString() + " domain: " + domain;
+   }
+}

Added: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DomainClassPoolRules.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DomainClassPoolRules.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/DomainClassPoolRules.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,42 @@
+/*
+* 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;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DomainClassPoolRules
+{
+   private boolean parentFirst;
+
+   public boolean isParentFirst()
+   {
+      return parentFirst;
+   }
+
+   public void setParentFirst(boolean parentFirst)
+   {
+      this.parentFirst = parentFirst;
+   }
+}

Added: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/IsLocalResourcePlugin.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/IsLocalResourcePlugin.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/IsLocalResourcePlugin.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,32 @@
+/*
+* 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;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface IsLocalResourcePlugin
+{
+   boolean isMyResource(String resourceName);
+}

Added: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/IsLocalResourcePluginFactory.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/IsLocalResourcePluginFactory.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/IsLocalResourcePluginFactory.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,32 @@
+/*
+* 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;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface IsLocalResourcePluginFactory
+{
+   IsLocalResourcePlugin create(DelegatingClassPool pool);
+}

Added: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/IsLocalResourcePluginFactoryRegistry.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/IsLocalResourcePluginFactoryRegistry.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/IsLocalResourcePluginFactoryRegistry.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,90 @@
+/*
+* 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;
+
+import java.net.URLClassLoader;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.jboss.util.loading.Translatable;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class IsLocalResourcePluginFactoryRegistry
+{
+   private static Map<Class<?>, IsLocalResourcePluginFactory> plugins = new WeakHashMap<Class<?>, IsLocalResourcePluginFactory>();
+   
+   static
+   {
+      addPluginFactory(ClassLoader.class, new DefaultClassLoaderIsLocalResourcePluginFactory());
+      addPluginFactory(URLClassLoader.class, new URLClassLoaderIsLocalResourcePluginFactory());
+      addPluginFactory(Translatable.class, new TranslatableClassLoaderIsLocalResourcePluginFactory());
+   }
+   
+   public static synchronized void addPluginFactory(Class<?> classLoaderClass, IsLocalResourcePluginFactory plugin)
+   {
+      plugins.put(classLoaderClass, plugin);
+   }
+   
+   public static synchronized void removePluginFactory(Class<?> classLoaderClass, IsLocalResourcePluginFactory plugin)
+   {
+      plugins.remove(classLoaderClass);
+   }
+
+   public static synchronized IsLocalResourcePluginFactory getPluginFactory(ClassLoader classLoader)
+   {
+      if (classLoader != null)
+      {
+         return getPluginFactory(classLoader.getClass());
+      }
+      return getPluginFactory(ClassLoader.class);
+   }
+   
+   public static synchronized IsLocalResourcePluginFactory getPluginFactory(Class<?> classLoaderClass)
+   {
+      IsLocalResourcePluginFactory plugin = plugins.get(classLoaderClass);
+      if (plugin == null)
+      {
+         Class<?>[] interfaces = classLoaderClass.getInterfaces();
+         if (interfaces.length > 0)
+         {
+            for (Class<?> iface : interfaces)
+            {
+               plugin = getPluginFactory(iface);
+               if (plugin != null)
+               {
+                  return plugin;
+               }
+            }
+         }
+         Class<?> superClass = classLoaderClass.getSuperclass();
+         if (superClass != null && superClass != Object.class)
+         {
+            return getPluginFactory(superClass);
+         }
+      }
+      return plugin;
+   }
+}

Added: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/TranslatableClassLoaderIsLocalResourcePlugin.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/TranslatableClassLoaderIsLocalResourcePlugin.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/TranslatableClassLoaderIsLocalResourcePlugin.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,54 @@
+/*
+* 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;
+
+import org.jboss.util.loading.Translatable;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TranslatableClassLoaderIsLocalResourcePlugin extends AbstractIsLocalResourcePlugin
+{
+   public TranslatableClassLoaderIsLocalResourcePlugin(DelegatingClassPool pool)
+   {
+      // FIXME TranslatableClassLoaderParentResourcePlugin constructor
+      super(pool);
+   }
+
+   @Override
+   protected void initialise()
+   {
+   }
+
+   public boolean isMyResource(String resourceName)
+   {
+      ClassLoader loader = getPool().getClassLoader();
+      if (loader instanceof Translatable == false)
+      {
+         throw new IllegalStateException("ClassLoader is not instance of Translatable " + loader);
+      }
+      return ((Translatable)getPool().getClassLoader()).getResourceLocally(resourceName) != null;
+   }
+
+}

Added: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/TranslatableClassLoaderIsLocalResourcePluginFactory.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/TranslatableClassLoaderIsLocalResourcePluginFactory.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/TranslatableClassLoaderIsLocalResourcePluginFactory.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,36 @@
+/*
+* 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;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TranslatableClassLoaderIsLocalResourcePluginFactory implements IsLocalResourcePluginFactory
+{
+   public IsLocalResourcePlugin create(DelegatingClassPool pool)
+   {
+      return new TranslatableClassLoaderIsLocalResourcePlugin(pool);
+   }
+
+}

Added: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/URLClassLoaderIsLocalResourcePlugin.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/URLClassLoaderIsLocalResourcePlugin.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/URLClassLoaderIsLocalResourcePlugin.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,73 @@
+/*
+* 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;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class URLClassLoaderIsLocalResourcePlugin extends AbstractIsLocalResourcePlugin 
+{
+   String[] urls;
+   public URLClassLoaderIsLocalResourcePlugin(DelegatingClassPool pool)
+   {
+      // FIXME URLClassLoaderParentResourcePlugin constructor
+      super(pool);
+   }
+   
+   public boolean isMyResource(String resourceName)
+   {
+      URL url = getPool().getClassLoader().getResource(resourceName);
+      if (url != null)
+      {
+         String urlString = url.toString();
+         for (String s : urls)
+         {
+            if (urlString.contains(s))
+            {
+               return true;
+            }
+         }
+      }
+      return false;
+   }
+
+   @Override
+   protected void initialise()
+   {
+      ClassLoader loader = getPool().getClassLoader();
+      if (loader instanceof URLClassLoader == false)
+      {
+         throw new IllegalStateException("Not a URLClassLoader " + loader);
+      }
+      URL[] loaderUrls = ((URLClassLoader)loader).getURLs();
+      urls = new String[loaderUrls.length];
+      for (int i = 0 ; i < loaderUrls.length ; i++)
+      {
+         urls[i] = loaderUrls[i].toString();
+      }
+   }
+}

Added: projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/URLClassLoaderIsLocalResourcePluginFactory.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/URLClassLoaderIsLocalResourcePluginFactory.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/main/org/jboss/aop/classpool/URLClassLoaderIsLocalResourcePluginFactory.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,37 @@
+/*
+* 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;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class URLClassLoaderIsLocalResourcePluginFactory implements IsLocalResourcePluginFactory
+{
+
+   public IsLocalResourcePlugin create(DelegatingClassPool pool)
+   {
+      return new URLClassLoaderIsLocalResourcePlugin(pool);
+   }
+
+}

Added: projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/support/a/A.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/support/a/A.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/support/a/A.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,32 @@
+/*
+* 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.test.aop.classpool.support.a;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class A
+{
+
+}

Added: projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/support/b/B.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/support/b/B.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/support/b/B.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,32 @@
+/*
+* 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.test.aop.classpool.support.b;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class B
+{
+
+}

Added: projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ClassPoolTest.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ClassPoolTest.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ClassPoolTest.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,114 @@
+/*
+* 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.test.aop.classpool.test;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.aop.classpool.AOPClassPoolRepository;
+import org.jboss.aop.classpool.ClassPoolDomain;
+import org.jboss.aop.classpool.DelegatingClassPool;
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolTest extends AbstractTestCaseWithSetup
+{   
+   public final static URL JAR_A = getURLRelativeToProjectRoot("target/jboss-aop-asintegration-core-test-classpool-a.jar");
+   public final static URL JAR_B = getURLRelativeToProjectRoot("target/jboss-aop-asintegration-core-test-classpool-b.jar");
+   public final static String CLASS_A = "org.jboss.test.aop.classpool.support.a.A";
+   public final static String CLASS_B = "org.jboss.test.aop.classpool.support.b.B";
+   
+   //Hard references to classloaders used for pools to avoid them being garbage collected before the test finished
+   private final static List<ClassLoader> loaders = new ArrayList<ClassLoader>(); 
+   
+   public ClassPoolTest(String name)
+   {
+      super(name);
+   }
+
+   protected static URL getURLRelativeToProjectRoot(String relativePath)
+   {
+      try
+      {
+         URL url = ClassPoolTest.class.getProtectionDomain().getCodeSource().getLocation();
+         String location = url.toString();
+         int index = location.lastIndexOf("/asintegration-core/") + "/asintegration-core/".length();
+         location = location.substring(0, index);
+         
+         location = location + relativePath;
+         return new URL(location);
+      }
+      catch (MalformedURLException e)
+      {
+         // AutoGenerated
+         throw new RuntimeException(e);
+      }
+   }
+   
+   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+   {
+      return new ClassPoolTestDelegate(clazz);
+   }
+
+   protected static ClassPoolDomain createClassPoolDomain(String name, ClassPoolDomain parent, boolean parentFirst)
+   {
+      ClassPoolDomain domain = new ClassPoolDomain(name, parent);
+      domain.setParentFirst(parentFirst);
+      return domain;
+   }
+   
+   protected static DelegatingClassPool createDelegatingClassPool(ClassPoolDomain domain, URL...urls) throws ClassNotFoundException
+   {
+      ClassLoader loader = new URLClassLoader(urls);
+      for (URL url : urls)
+      {
+         if (url == JAR_A)
+         {
+            loader.loadClass(CLASS_A);
+         }
+         else if (url == JAR_B)
+         {
+            loader.loadClass(CLASS_B);
+         }
+            
+      }
+      //Once all the classes in the loader have been loaded, it seems to clear the URLs. Work around this 
+      //by recreating the loader since we need the urls in the URLClassLoaderIsLocalResourcePlugin
+      loaders.add(new URLClassLoader(urls));
+      return new DelegatingClassPool(domain, loader, AOPClassPoolRepository.getInstance(), false);
+   }
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      enableTrace("org.jboss.aop.classpool.DelegatingClassPool");
+   }
+}

Added: projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ClassPoolTestDelegate.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ClassPoolTestDelegate.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ClassPoolTestDelegate.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,38 @@
+/*
+* 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.test.aop.classpool.test;
+
+import org.jboss.test.AbstractTestDelegate;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPoolTestDelegate extends AbstractTestDelegate
+{
+   public ClassPoolTestDelegate(Class<?> clazz)
+   {
+      super(clazz);
+   }
+
+}

Added: projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/DelegatingClassPoolTestSuite.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/DelegatingClassPoolTestSuite.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/DelegatingClassPoolTestSuite.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,54 @@
+/*
+* 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.test.aop.classpool.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class DelegatingClassPoolTestSuite extends TestSuite
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("DelegatingClassPool All Tests");
+      
+      suite.addTest(IsLocalResourcePluginFactoryTestCase.suite());
+      suite.addTest(SimpleDelegatingClassPoolTestCase.suite());
+      suite.addTest(ScopedSiblingDelegatingClassPoolTestCase.suite());
+      suite.addTest(ParentFirstDelegatingClassPoolTestCase.suite());
+      suite.addTest(ParentLastDelegatingClassPoolTestCase.suite());
+      
+
+      return suite;
+   }
+
+}

Added: projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/IsLocalResourcePluginFactoryTestCase.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/IsLocalResourcePluginFactoryTestCase.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/IsLocalResourcePluginFactoryTestCase.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,181 @@
+/*
+* 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.test.aop.classpool.test;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import org.jboss.aop.classpool.AOPClassPoolRepository;
+import org.jboss.aop.classpool.ClassPoolDomain;
+import org.jboss.aop.classpool.DefaultClassLoaderIsLocalResourcePlugin;
+import org.jboss.aop.classpool.DefaultClassLoaderIsLocalResourcePluginFactory;
+import org.jboss.aop.classpool.DelegatingClassPool;
+import org.jboss.aop.classpool.IsLocalResourcePlugin;
+import org.jboss.aop.classpool.IsLocalResourcePluginFactory;
+import org.jboss.aop.classpool.IsLocalResourcePluginFactoryRegistry;
+import org.jboss.aop.classpool.TranslatableClassLoaderIsLocalResourcePlugin;
+import org.jboss.aop.classpool.TranslatableClassLoaderIsLocalResourcePluginFactory;
+import org.jboss.aop.classpool.URLClassLoaderIsLocalResourcePlugin;
+import org.jboss.aop.classpool.URLClassLoaderIsLocalResourcePluginFactory;
+import org.jboss.util.loading.Translatable;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class IsLocalResourcePluginFactoryTestCase extends TestCase
+{
+   final static ClassPoolDomain DOMAIN = new ClassPoolDomain("Test", null);
+   final static URL[] URLS;
+   static 
+   {
+      try
+      {
+         URLS = new URL[] {new URL("http://www.blah.com")};
+      }
+      catch (MalformedURLException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   public static Test suite()
+   {
+      return new TestSuite(IsLocalResourcePluginFactoryTestCase.class);
+   }
+
+   public IsLocalResourcePluginFactoryTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testDefaultClassLoader() 
+   {
+      DelegatingClassPool pool = new DelegatingClassPool(DOMAIN, new DefaultClassLoader(), AOPClassPoolRepository.getInstance(), false);
+      assertFactoryAndPlugin(pool, DefaultClassLoaderIsLocalResourcePluginFactory.class, DefaultClassLoaderIsLocalResourcePlugin.class);
+   }
+   
+   public void testURLClassLoaderDirect()
+   {
+      DelegatingClassPool pool = new DelegatingClassPool(DOMAIN, new URLClassLoader(URLS), AOPClassPoolRepository.getInstance(), false);
+      assertFactoryAndPlugin(pool, URLClassLoaderIsLocalResourcePluginFactory.class, URLClassLoaderIsLocalResourcePlugin.class);
+   }
+
+   public void testURLClassLoaderSubClass()
+   {
+      DelegatingClassPool pool = new DelegatingClassPool(DOMAIN, new URLCLassLoaderSubClass(URLS), AOPClassPoolRepository.getInstance(), false);
+      assertFactoryAndPlugin(pool, URLClassLoaderIsLocalResourcePluginFactory.class, URLClassLoaderIsLocalResourcePlugin.class);
+   }
+
+   public void testTranslatableClassLoaderImplementation()
+   {
+      DelegatingClassPool pool = new DelegatingClassPool(DOMAIN, new TranslatableImplementation(), AOPClassPoolRepository.getInstance(), false);
+      assertFactoryAndPlugin(pool, TranslatableClassLoaderIsLocalResourcePluginFactory.class, TranslatableClassLoaderIsLocalResourcePlugin.class);
+   }
+   
+   public void testTranslatableClassLoaderImplementationAndURLClassLoaderSubClass()
+   {
+      DelegatingClassPool pool = new DelegatingClassPool(DOMAIN, new TranslatableImplementationAndURLClassLoaderSubClass(URLS), AOPClassPoolRepository.getInstance(), false);
+      assertFactoryAndPlugin(pool, TranslatableClassLoaderIsLocalResourcePluginFactory.class, TranslatableClassLoaderIsLocalResourcePlugin.class);
+   }
+   
+   public void testTranslatable2ClassLoaderImplementationAndURLClassLoaderSubClass()
+   {
+      DelegatingClassPool pool = new DelegatingClassPool(DOMAIN, new Translatable2ImplementationAndURLClassLoaderSubClass(URLS), AOPClassPoolRepository.getInstance(), false);
+      assertFactoryAndPlugin(pool, TranslatableClassLoaderIsLocalResourcePluginFactory.class, TranslatableClassLoaderIsLocalResourcePlugin.class);
+   }
+   
+   
+   private void assertFactoryAndPlugin(DelegatingClassPool pool, Class<?> factoryClass, Class<?> pluginClass)
+   {
+      IsLocalResourcePluginFactory factory = IsLocalResourcePluginFactoryRegistry.getPluginFactory(pool.getClassLoader());
+      assertNotNull(factory);
+      assertEquals(factoryClass, factory.getClass());
+      IsLocalResourcePlugin plugin = factory.create(pool);
+      assertEquals(pluginClass, plugin.getClass());
+   }
+
+   static class DefaultClassLoader extends ClassLoader
+   {
+   }
+   
+   static class URLCLassLoaderSubClass extends URLClassLoader
+   {
+      public URLCLassLoaderSubClass(URL[] urls)
+      {
+         super(urls);
+      }
+      
+   }
+   
+   static class TranslatableImplementation extends ClassLoader implements Translatable
+   {
+      public URL getResourceLocally(String name)
+      {
+         return null;
+      }
+      
+   }
+   
+   static class TranslatableImplementationAndURLClassLoaderSubClass extends URLClassLoader implements Translatable
+   {
+
+      public TranslatableImplementationAndURLClassLoaderSubClass(URL[] urls)
+      {
+         super(urls);
+      }
+
+      public URL getResourceLocally(String name)
+      {
+         return null;
+      }
+      
+   }
+   
+   interface Translatable2 extends Translatable
+   {
+      
+   }
+   
+   static class Translatable2ImplementationAndURLClassLoaderSubClass extends URLClassLoader implements Translatable2
+   {
+
+      public Translatable2ImplementationAndURLClassLoaderSubClass(URL[] urls)
+      {
+         super(urls);
+      }
+
+      public URL getResourceLocally(String name)
+      {
+         return null;
+      }
+      
+   }
+   
+   
+}

Added: projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ParentFirstDelegatingClassPoolTestCase.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ParentFirstDelegatingClassPoolTestCase.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ParentFirstDelegatingClassPoolTestCase.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,266 @@
+package org.jboss.test.aop.classpool.test;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.aop.classpool.ClassPoolDomain;
+
+
+/*
+* 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.
+*/
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ParentFirstDelegatingClassPoolTestCase extends ClassPoolTest
+{
+   public static Test suite()
+   {
+      return new TestSuite(ParentFirstDelegatingClassPoolTestCase.class);
+   }
+
+   public ParentFirstDelegatingClassPoolTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testClassInParentOnly() throws Exception
+   {
+      ClassPoolDomain parent = createClassPoolDomain("PARENT", null, true);
+      ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+      ClassPool childPool = createDelegatingClassPool(child, JAR_B);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessClassInParentOnly(parentPool, childPool);
+      accessClassInParentOnly(parentPool, childPool);
+   }
+   
+   private void accessClassInParentOnly(ClassPool parentPool, ClassPool childPool) throws Exception
+   {
+      CtClass a1 = childPool.get(CLASS_A);
+      assertEquals(parentPool, a1.getClassPool());
+      
+      CtClass a2 = parentPool.get(CLASS_A);
+      assertEquals(parentPool, a2.getClassPool());
+      assertEquals(a1, a2);
+      
+      CtClass b = childPool.get(CLASS_B);
+      assertEquals(childPool, b.getClassPool());
+      try
+      {
+         parentPool.get(CLASS_B);
+         fail("Should not have been found");
+      }
+      catch(NotFoundException e)
+      {
+      }
+      
+      CtClass string = childPool.get(String.class.getName());
+      assertNotSame("java.lang.String should be loaded by the parent pool", childPool, string.getClassPool());
+      assertEquals(ClassPool.getDefault(), string.getClassPool());
+   }
+   
+   public void testClassInGrandParentOnly() throws Exception
+   {
+      ClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, true);
+      ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+      ClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, true);
+      ClassPool parentPool = createDelegatingClassPool(parent, JAR_B);
+      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+      ClassPool childPool = createDelegatingClassPool(child, JAR_B);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessClassInGrandParentOnly(grandParentPool, parentPool, childPool);
+      accessClassInGrandParentOnly(grandParentPool, parentPool, childPool);
+   }
+   
+   private void accessClassInGrandParentOnly(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+   {
+      CtClass a1 = childPool.get(CLASS_A);
+      assertEquals(grandParentPool, a1.getClassPool());
+      
+      CtClass a2 = parentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a2.getClassPool());
+      assertEquals(a1, a2);
+      
+      CtClass a3 = parentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a3.getClassPool());
+
+      assertEquals(a2, a3);
+      
+      
+      CtClass b1 = childPool.get(CLASS_B);
+      assertEquals(parentPool, b1.getClassPool());
+      CtClass b2 = childPool.get(CLASS_B);
+      assertEquals(parentPool, b2.getClassPool());
+      assertEquals(b1, b2);
+      
+      try
+      {
+         grandParentPool.get(CLASS_B);
+         fail("Should not have been found");
+      }
+      catch(NotFoundException e)
+      {
+      }
+   }
+   
+   public void testChildNotInParent() throws Exception
+   {
+      ClassPoolDomain parent = createClassPoolDomain("PARENT", null, true);
+      ClassPool parentPool = createDelegatingClassPool(parent, JAR_B);
+      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+      ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessChildNotInParent(parentPool, childPool);
+      accessChildNotInParent(parentPool, childPool);
+   }
+   
+   private void accessChildNotInParent(ClassPool parentPool, ClassPool childPool) throws Exception
+   {
+      try
+      {
+         parentPool.get(CLASS_A);
+         fail("Should not have been found");
+      }
+      catch(NotFoundException e)
+      {
+      }
+      CtClass a = childPool.get(CLASS_A);
+      assertEquals(childPool, a.getClassPool());
+      
+   }
+   
+   public void testChildInParent() throws Exception
+   {
+      ClassPoolDomain parent = createClassPoolDomain("PARENT", null, true);
+      ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+      ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessChildInParent(parentPool, childPool);
+      accessChildInParent(parentPool, childPool);
+   }
+   
+   private void accessChildInParent(ClassPool parentPool, ClassPool childPool) throws Exception
+   {
+      CtClass a1 = childPool.get(CLASS_A);
+      assertEquals(parentPool, a1.getClassPool());
+      
+      CtClass a2 = parentPool.get(CLASS_A);
+      assertEquals(parentPool, a2.getClassPool());
+      
+      assertSame(a1, a2);
+   }
+   
+   public void testChildInParentAndGrandParent() throws Exception
+   {
+      ClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, true);
+      ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+      ClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, true);
+      ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+      ClassPool childPool = createDelegatingClassPool(child, JAR_B);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessChildInParentAndGrandParent(grandParentPool, parentPool, childPool);
+      accessChildInParentAndGrandParent(grandParentPool, parentPool, childPool);
+   }
+   
+   private void accessChildInParentAndGrandParent(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+   {
+      CtClass a1 = childPool.get(CLASS_A);
+      assertEquals(grandParentPool, a1.getClassPool());
+      
+      CtClass a2 = parentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a2.getClassPool());
+      assertSame(a1, a2);
+
+      CtClass a3 = grandParentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a3.getClassPool());
+      assertSame(a2, a3);
+   }
+
+   public void testChildInParentAndGrandParentFromTop() throws Exception
+   {
+      ClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, true);
+      ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+      ClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, true);
+      ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+      ClassPool childPool = createDelegatingClassPool(child, JAR_B);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessChildInParentAndGrandParentFromTop(grandParentPool, parentPool, childPool);
+      accessChildInParentAndGrandParentFromTop(grandParentPool, parentPool, childPool);
+   }
+   
+   private void accessChildInParentAndGrandParentFromTop(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+   {
+      CtClass a1 = grandParentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a1.getClassPool());
+      
+      CtClass a2 = parentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a2.getClassPool());
+      assertSame(a1, a2);
+
+      CtClass a3 = childPool.get(CLASS_A);
+      assertEquals(grandParentPool, a3.getClassPool());
+      assertSame(a2, a3);
+   }
+
+   public void testChildInGrandParent() throws Exception
+   {
+      ClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, true);
+      ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+      ClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, true);
+      ClassPool parentPool = createDelegatingClassPool(parent, JAR_B);
+      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, true);
+      ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessChildInGrandParent(grandParentPool, parentPool, childPool);
+      accessChildInGrandParent(grandParentPool, parentPool, childPool);
+   }
+   
+   private void accessChildInGrandParent(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+   {
+      CtClass a1 = childPool.get(CLASS_A);
+      assertEquals(grandParentPool, a1.getClassPool());
+      
+      CtClass a2 = parentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a2.getClassPool());
+      assertSame(a1, a2);
+
+      CtClass a3 = grandParentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a3.getClassPool());
+      assertSame(a2, a3);
+   }
+}

Added: projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ParentLastDelegatingClassPoolTestCase.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ParentLastDelegatingClassPoolTestCase.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ParentLastDelegatingClassPoolTestCase.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,222 @@
+package org.jboss.test.aop.classpool.test;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+
+import org.jboss.aop.classpool.ClassPoolDomain;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+
+/*
+* 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.
+*/
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ParentLastDelegatingClassPoolTestCase extends ClassPoolTest
+{
+   public static Test suite()
+   {
+      return new TestSuite(ParentLastDelegatingClassPoolTestCase.class);
+   }
+
+   public ParentLastDelegatingClassPoolTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testChildInParent() throws Exception
+   {
+      ClassPoolDomain parent = createClassPoolDomain("PARENT", null, false);
+      ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
+      ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessChildInParent(parentPool, childPool);
+      accessChildInParent(parentPool, childPool);
+   }
+
+   private void accessChildInParent(ClassPool parentPool, ClassPool childPool) throws Exception
+   {
+      CtClass a1 = childPool.get(CLASS_A);
+      assertEquals(childPool, a1.getClassPool());
+      
+      CtClass a2 = parentPool.get(CLASS_A);
+      assertEquals(parentPool, a2.getClassPool());
+   }
+
+   public void testChildInGrandParent() throws Exception
+   {
+      ClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, false);
+      ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+      ClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, false);
+      ClassPool parentPool = createDelegatingClassPool(parent, JAR_B);
+      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
+      ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessChildInGrandParent(grandParentPool, parentPool, childPool);
+      accessChildInGrandParent(grandParentPool, parentPool, childPool);
+   }
+   
+   private void accessChildInGrandParent(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+   {
+      CtClass a1 = childPool.get(CLASS_A);
+      assertEquals(childPool, a1.getClassPool());
+      
+      CtClass a2 = parentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a2.getClassPool());
+      
+      CtClass a3 = grandParentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a3.getClassPool());
+   }
+   
+   public void testChildInGrandParentFromTop() throws Exception
+   {
+      ClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, false);
+      ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+      ClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, false);
+      ClassPool parentPool = createDelegatingClassPool(parent, JAR_B);
+      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
+      ClassPool childPool = createDelegatingClassPool(child, JAR_A);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessChildInGrandParentFromTop(grandParentPool, parentPool, childPool);
+      accessChildInGrandParentFromTop(grandParentPool, parentPool, childPool);
+   }
+   
+   private void accessChildInGrandParentFromTop(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+   {
+      CtClass a1 = grandParentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a1.getClassPool());
+
+      CtClass a2 = parentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a2.getClassPool());
+      
+      CtClass a3 = childPool.get(CLASS_A);
+      assertEquals(childPool, a3.getClassPool());      
+   }
+   
+   public void testChildInSibling() throws Exception
+   {
+      ClassPoolDomain parent = createClassPoolDomain("PARENT", null, false);
+      ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+      ClassPoolDomain childA = createClassPoolDomain("CHILDA", parent, false);
+      ClassPool childPoolA = createDelegatingClassPool(childA, JAR_A);
+      ClassPoolDomain childB = createClassPoolDomain("CHILDB", parent, false);
+      ClassPool childPoolB = createDelegatingClassPool(childB, JAR_A);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessChildInSibling(parentPool, childPoolA, childPoolB);
+      accessChildInSibling(parentPool, childPoolA, childPoolB);
+   }
+   
+   private void accessChildInSibling(ClassPool parentPool, ClassPool childPoolA, ClassPool childPoolB) throws Exception
+   {
+      CtClass a1 = childPoolA.get(CLASS_A);
+      assertEquals(childPoolA, a1.getClassPool());
+      
+      CtClass a2 = parentPool.get(CLASS_A);
+      assertEquals(parentPool, a2.getClassPool());
+
+      CtClass a3 = childPoolB.get(CLASS_A);
+      assertEquals(childPoolB, a3.getClassPool());
+   }
+
+   public void testClassInParentOnly() throws Exception
+   {
+      ClassPoolDomain parent = createClassPoolDomain("PARENT", null, false);
+      ClassPool parentPool = createDelegatingClassPool(parent, JAR_A);
+      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
+      ClassPool childPool = createDelegatingClassPool(child, JAR_B);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessClassInParentOnly(parentPool, childPool);
+      accessClassInParentOnly(parentPool, childPool);
+   }
+
+   private void accessClassInParentOnly(ClassPool parentPool, ClassPool childPool) throws Exception
+   {
+      CtClass a1 = childPool.get(CLASS_A);
+      assertEquals(parentPool, a1.getClassPool());
+      
+      CtClass a2 = parentPool.get(CLASS_A);
+      assertEquals(parentPool, a2.getClassPool());
+   }
+
+   public void testClassInGrandParentOnly() throws Exception
+   {
+      ClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, false);
+      ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+      ClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, false);
+      ClassPool parentPool = createDelegatingClassPool(parent, JAR_B);
+      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
+      ClassPool childPool = createDelegatingClassPool(child, JAR_B);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessChildInGrandParentOnly(grandParentPool, parentPool, childPool);
+      accessChildInGrandParentOnly(grandParentPool, parentPool, childPool);
+   }
+   
+   private void accessChildInGrandParentOnly(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+   {
+      CtClass a1 = childPool.get(CLASS_A);
+      assertEquals(grandParentPool, a1.getClassPool());
+      
+      CtClass a2 = parentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a2.getClassPool());
+      
+      CtClass a3 = grandParentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a3.getClassPool());
+   }
+
+   public void testClassInGrandParentOnlyFromTop() throws Exception
+   {
+      ClassPoolDomain grandParent = createClassPoolDomain("GRANDPARENT", null, false);
+      ClassPool grandParentPool = createDelegatingClassPool(grandParent, JAR_A);
+      ClassPoolDomain parent = createClassPoolDomain("PARENT", grandParent, false);
+      ClassPool parentPool = createDelegatingClassPool(parent, JAR_B);
+      ClassPoolDomain child = createClassPoolDomain("CHILD", parent, false);
+      ClassPool childPool = createDelegatingClassPool(child, JAR_B);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessChildInGrandParentOnlyFromTop(grandParentPool, parentPool, childPool);
+      accessChildInGrandParentOnlyFromTop(grandParentPool, parentPool, childPool);
+   }
+   
+   private void accessChildInGrandParentOnlyFromTop(ClassPool grandParentPool, ClassPool parentPool, ClassPool childPool) throws Exception
+   {
+      CtClass a1 = grandParentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a1.getClassPool());
+      
+      CtClass a2 = parentPool.get(CLASS_A);
+      assertEquals(grandParentPool, a2.getClassPool());
+      
+      CtClass a3 = childPool.get(CLASS_A);
+      assertEquals(grandParentPool, a3.getClassPool());
+   }
+}

Added: projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ScopedSiblingDelegatingClassPoolTestCase.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ScopedSiblingDelegatingClassPoolTestCase.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/ScopedSiblingDelegatingClassPoolTestCase.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,113 @@
+package org.jboss.test.aop.classpool.test;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.aop.classpool.ClassPoolDomain;
+
+
+/*
+* 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.
+*/
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ScopedSiblingDelegatingClassPoolTestCase extends ClassPoolTest
+{
+   public static Test suite()
+   {
+      return new TestSuite(ScopedSiblingDelegatingClassPoolTestCase.class);
+   }
+
+   public ScopedSiblingDelegatingClassPoolTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testNoVisibilityBetweenSiblings() throws Exception
+   {
+      ClassPoolDomain root = createClassPoolDomain("ROOT", null, false);
+      ClassPoolDomain domainA = createClassPoolDomain("A", root, false);
+      ClassPool poolA = createDelegatingClassPool(domainA, JAR_A);
+      ClassPoolDomain domainB = createClassPoolDomain("B", root, false);
+      ClassPool poolB = createDelegatingClassPool(domainB, JAR_B);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessNoVisibilityBetweenSiblings(poolA, poolB);
+      accessNoVisibilityBetweenSiblings(poolA, poolB);
+   }
+   
+   public void accessNoVisibilityBetweenSiblings(ClassPool poolA, ClassPool poolB) throws Exception
+   {
+      CtClass a = poolA.get(CLASS_A);
+      assertEquals(poolA, a.getClassPool());
+      CtClass b = poolB.get(CLASS_B);
+      assertEquals(poolB, b.getClassPool());
+      
+      try
+      {
+         poolA.get(CLASS_B);
+         fail("Should not have found B in poolA");
+      }
+      catch (Exception e)
+      {
+      }
+      try
+      {
+         poolB.get(CLASS_A);
+         fail("Should not have found A in poolB");
+      }
+      catch (Exception e)
+      {
+      }
+   }
+   
+   public void testUsesOwnCopy() throws Exception
+   {
+      ClassPoolDomain root = createClassPoolDomain("ROOT", null, false);
+      ClassPoolDomain domainA = createClassPoolDomain("A", root, false);
+      ClassPool poolA = createDelegatingClassPool(domainA, JAR_A, JAR_B);
+      ClassPoolDomain domainB = createClassPoolDomain("B", root, false);
+      ClassPool poolB = createDelegatingClassPool(domainB, JAR_B, JAR_A);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessUsesOwnCopy(poolA, poolB);
+      accessUsesOwnCopy(poolA, poolB);
+   }
+   
+   public void accessUsesOwnCopy(ClassPool poolA, ClassPool poolB) throws Exception
+   {
+      CtClass aa = poolA.get(CLASS_A);
+      assertEquals(poolA, aa.getClassPool());
+      CtClass ab = poolA.get(CLASS_A);
+      assertEquals(poolA, ab.getClassPool());
+      
+      CtClass ba = poolA.get(CLASS_A);
+      assertEquals(poolA, ba.getClassPool());
+      CtClass bb = poolB.get(CLASS_B);
+      assertEquals(poolB, bb.getClassPool());
+   }   
+}

Added: projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/SimpleDelegatingClassPoolTestCase.java
===================================================================
--- projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/SimpleDelegatingClassPoolTestCase.java	                        (rev 0)
+++ projects/aop/trunk/asintegration-core/src/tests/org/jboss/test/aop/classpool/test/SimpleDelegatingClassPoolTestCase.java	2008-10-15 09:57:47 UTC (rev 79519)
@@ -0,0 +1,113 @@
+package org.jboss.test.aop.classpool.test;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.aop.classpool.ClassPoolDomain;
+
+
+/*
+* 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.
+*/
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleDelegatingClassPoolTestCase extends ClassPoolTest
+{
+   public static Test suite()
+   {
+      return new TestSuite(SimpleDelegatingClassPoolTestCase.class);
+   }
+
+   public SimpleDelegatingClassPoolTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testAllClassesOnePool() throws Exception
+   {
+      ClassPoolDomain domain = createClassPoolDomain("SIMPLE", null, false);
+      ClassPool pool = createDelegatingClassPool(domain, JAR_A, JAR_B);
+
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessAllClassesOnePool(pool);
+      accessAllClassesOnePool(pool);
+   }
+   
+   private void accessAllClassesOnePool(ClassPool pool) throws Exception
+   {
+      CtClass a = pool.get(CLASS_A);
+      CtClass b = pool.get(CLASS_B);
+      assertEquals(pool, a.getClassPool());
+      assertEquals(pool, b.getClassPool());
+      
+      CtClass string = pool.get(String.class.getName());
+      assertNotSame("java.lang.String should be loaded by the parent pool", pool, string.getClassPool());
+      assertEquals(ClassPool.getDefault(), string.getClassPool());
+   }
+   
+   public void testOnePoolPerClassLoadedByA() throws Exception
+   {
+      ClassPoolDomain domain = createClassPoolDomain("SIMPLE", null, false);
+      ClassPool poolA = createDelegatingClassPool(domain, JAR_A);
+      ClassPool poolB = createDelegatingClassPool(domain, JAR_B);
+      
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessOnePoolPerClassLoadedByA(poolA, poolB);
+      accessOnePoolPerClassLoadedByA(poolA, poolB);
+   }
+   
+   private  void accessOnePoolPerClassLoadedByA(ClassPool poolA, ClassPool poolB) throws Exception
+   {
+      CtClass a = poolA.get(CLASS_A);
+      CtClass b = poolA.get(CLASS_B);
+
+      assertNotSame(a.getClassPool(), b.getClassPool());
+      assertEquals(poolA, a.getClassPool());
+      assertEquals(poolB, b.getClassPool());
+   }
+   
+   public void testOnePoolPerClassLoadedByB() throws Exception
+   {
+      ClassPoolDomain domain = createClassPoolDomain("SIMPLE", null, false);
+      ClassPool poolA = createDelegatingClassPool(domain, JAR_A);
+      ClassPool poolB = createDelegatingClassPool(domain, JAR_B);
+
+      //The first time we access the pool it will create the classes, second time will use the cache
+      accessOnePoolPerClassLoadedByB(poolA, poolB);
+      accessOnePoolPerClassLoadedByB(poolA, poolB);
+}
+   
+   public void accessOnePoolPerClassLoadedByB(ClassPool poolA, ClassPool poolB) throws Exception
+   {
+      CtClass a = poolB.get(CLASS_A);
+      CtClass b = poolB.get(CLASS_B);
+      
+      assertNotSame(a.getClassPool(), b.getClassPool());
+      assertEquals(poolA, a.getClassPool());
+      assertEquals(poolB, b.getClassPool());
+   }
+}




More information about the jboss-cvs-commits mailing list