[jboss-cvs] JBossAS SVN: r97737 - in projects/jboss-classpool/trunk/ucl: src and 22 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 11 08:53:13 EST 2009


Author: flavia.rainone at jboss.com
Date: 2009-12-11 08:53:12 -0500 (Fri, 11 Dec 2009)
New Revision: 97737

Added:
   projects/jboss-classpool/trunk/ucl/src/
   projects/jboss-classpool/trunk/ucl/src/main/
   projects/jboss-classpool/trunk/ucl/src/main/java/
   projects/jboss-classpool/trunk/ucl/src/main/java/org/
   projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/
   projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/
   projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/
   projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/
   projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/JBossClassPool.java
   projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/JBossClassPoolFactory.java
   projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/LoaderRepositoryUrlUtil.java
   projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ScopedJBossClassPool.java
   projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ScopedRepositoryClassLoaderHelper.java
   projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/SecurityActions.java
   projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ToClassInvoker.java
   projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ToClassInvokerPoolReference.java
   projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/UclDelegatingClassPool.java
   projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/UclDelegatingClassPoolFactory.java
   projects/jboss-classpool/trunk/ucl/src/main/resources/
   projects/jboss-classpool/trunk/ucl/src/main/resources/jbossorg-eula.txt
   projects/jboss-classpool/trunk/ucl/src/test/
   projects/jboss-classpool/trunk/ucl/src/test/java/
   projects/jboss-classpool/trunk/ucl/src/test/java/org/
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/UclClassPoolTestSuite.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ChildUCLInfo.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/GlobalUCLInfo.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ParentLastURLClassLoader.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ParentLastURLClassLoaderInfo.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/SupportArchives.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/SupportClasses.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/UCLFactory.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/UCLInfo.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/URLClassLoaderInfo.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/a/
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/a/A.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/b/
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/b/B.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/c/
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/c/C.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/CtClassCreationTestCase.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositoryClassPoolTestCase.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositorySanityTestCase.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositoryTest.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTest.java
   projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTestDelegate.java
   projects/jboss-classpool/trunk/ucl/src/test/resources/
   projects/jboss-classpool/trunk/ucl/src/test/resources/log4j.xml
Log:
[JBREFLECT-75] Src dir of classpool-ucl module

Added: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/JBossClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/JBossClassPool.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/JBossClassPool.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,84 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classpool.plugins.ucl;
+
+import java.io.File;
+import java.net.URL;
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classpool.spi.AbstractClassPool;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author adrian at jboss.org
+ * @version $Revision$
+ */
+public class JBossClassPool extends AbstractClassPool implements ToClassInvokerPoolReference
+{
+   ToClassInvoker toClassInvoker = null;
+   
+   protected JBossClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, File tmp, URL tmpURL)
+   {
+      super(cl, src, repository);
+      toClassInvoker = new ToClassInvoker(tmp);
+   }
+
+   protected JBossClassPool(ClassPool src, ScopedClassPoolRepository repository)
+   {
+      super(src, repository);
+   }
+
+   public boolean isUnloadedClassLoader()
+   {
+      if (getClassLoader() instanceof RepositoryClassLoader)
+      {
+         RepositoryClassLoader rcl = (RepositoryClassLoader) getClassLoader();
+         return rcl.getLoaderRepository() == null;
+      }
+      return false;
+   }
+
+   public Class<?> toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+   {
+      return toClassInvoker.toClass(this, cc, getResourceName(cc.getName()), loader, domain);
+   }
+
+   public Class<?> superPoolToClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+   {
+      return super.toClass(cc, loader, domain);
+   }
+
+   @Override
+   public void lockInCache(CtClass clazz)
+   {
+      super.lockInCache(clazz);
+      localResources.put(getResourceName(clazz.getName()), Boolean.TRUE);
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/JBossClassPool.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/JBossClassPoolFactory.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/JBossClassPoolFactory.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/JBossClassPoolFactory.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,128 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classpool.plugins.ucl;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classpool.plugins.AbstractJBossClassPoolFactory;
+import org.jboss.classpool.spi.AbstractClassPool;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author adrian at jboss.org
+ * @version $Revision$
+ **/
+public class JBossClassPoolFactory extends AbstractJBossClassPoolFactory
+{
+   protected File tmpClassesDir;
+
+   public JBossClassPoolFactory(File tmpClassesDir) throws IOException
+   {
+      this.tmpClassesDir = tmpClassesDir;
+
+   }
+   public AbstractClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+   {
+      ClassPool parent = getCreateParentClassPools(cl, src, repository);
+      if (cl instanceof RepositoryClassLoader)
+      {
+         File tempdir = getTempDirectory(cl);
+         URL tmpCP;
+         try
+         {
+            tmpCP = createURLAndAddToLoader(cl, tempdir);
+         }
+         catch (IOException e)
+         {
+            throw new RuntimeException(e);
+         }
+         if (ScopedRepositoryClassLoaderHelper.isScopedClassLoader(cl))
+         {
+            //It is scoped
+            return new ScopedJBossClassPool(cl, parent, repository, tempdir, tmpCP);
+         }
+         return new JBossClassPool(cl, parent, repository, tempdir, tmpCP);
+      }
+      return new AbstractClassPool(cl, parent, repository);
+   }
+
+   protected File getTempDirectory(ClassLoader cl)
+   {
+      File tempdir = null;
+      int attempts = 0;
+      IOException ex = null;
+      while (tempdir == null && attempts < 5)
+      {
+         //Workaround for JBAOP-254, retry a few times
+         try
+         {
+            tempdir = createTempDir(cl);
+         }
+         catch (IOException e)
+         {
+            ex = e;
+         }
+      }
+      
+      if (tempdir == null)
+      {
+         throw new RuntimeException("", ex);
+      }
+      
+      return tempdir;
+   }
+
+   public File createTempDir(ClassLoader cl) throws IOException
+   {
+      File tempdir = File.createTempFile("ucl", "", tmpClassesDir);
+      tempdir.delete();
+      tempdir.mkdir();
+      tempdir.deleteOnExit();
+
+      return tempdir;
+   }
+   
+   private URL createURLAndAddToLoader(ClassLoader cl, File tempdir) throws IOException
+   {
+      URL tmpURL = tempdir.toURL();
+      URL tmpCP = new URL(tmpURL, "?dynamic=true");
+
+      RepositoryClassLoader ucl = (RepositoryClassLoader) cl;
+
+      // We may be undeploying.
+      if (ucl.getLoaderRepository() != null)
+      {
+         ucl.addURL(tmpCP);
+      }
+      
+      return tmpCP;
+   }
+
+}


Property changes on: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/JBossClassPoolFactory.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/LoaderRepositoryUrlUtil.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/LoaderRepositoryUrlUtil.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/LoaderRepositoryUrlUtil.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,173 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classpool.plugins.ucl;
+
+import java.net.URL;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanServer;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+
+import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.util.MBeanServerLocator;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+public class LoaderRepositoryUrlUtil implements NotificationListener
+{
+   final static MBeanServer SERVER;
+   final static ObjectName MAIN_LOADER_REPOSITORY_OBJECT_NAME;
+   final static LoaderRepository MAIN_LOADER_REPOSITORY;
+   static
+   {
+      SERVER = MBeanServerLocator.locateJBoss();
+      try
+      {
+         MAIN_LOADER_REPOSITORY_OBJECT_NAME = new ObjectName("JMImplementation:name=Default,service=LoaderRepository");
+         MAIN_LOADER_REPOSITORY = (LoaderRepository)SERVER.invoke(MAIN_LOADER_REPOSITORY_OBJECT_NAME, "getInstance", new Object[0], new String[0]);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   long currentSequenceNumber;
+   long lastSequenceNumber = -1;
+   URL[] urls;
+   
+   public LoaderRepositoryUrlUtil()
+   {
+      try
+      {
+         SERVER.addNotificationListener(MAIN_LOADER_REPOSITORY_OBJECT_NAME, this, null, null);
+      }
+      catch (InstanceNotFoundException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public synchronized void handleNotification(Notification notification, Object handback)
+   {
+      if (notification.getType().equals(LoaderRepository.CLASSLOADER_ADDED))
+      {
+         currentSequenceNumber = notification.getSequenceNumber();
+      }
+      else if (notification.getType().equals(LoaderRepository.CLASSLOADER_REMOVED))
+      {
+         currentSequenceNumber = notification.getSequenceNumber();
+      }
+   }
+   
+   public synchronized UrlInfo getURLInfo(HeirarchicalLoaderRepository3 scopedLoader, UrlInfo urlInfo)
+   {
+      boolean changed = false;
+      if (lastSequenceNumber != currentSequenceNumber)
+      {
+         urls = MAIN_LOADER_REPOSITORY.getURLs();
+         lastSequenceNumber = currentSequenceNumber;
+         changed = true;
+      }
+      if (!changed)
+      {
+         changed = urlInfo != null && (urlInfo.getSequenceNumber() != lastSequenceNumber);
+      }
+      if (urlInfo == null || changed)
+      {
+         URL[] localUrls = getLocalUrls(scopedLoader, urls);
+         urlInfo = new UrlInfo(urls, localUrls, lastSequenceNumber);
+      }
+      return urlInfo;
+   }
+   
+   public long getCurrentSequenceNumber()
+   {
+      return currentSequenceNumber;
+   }
+   
+   private URL[] getLocalUrls(HeirarchicalLoaderRepository3 scopedRepository, URL[] globalUrls)
+   {
+      URL[] scopedRepositoryUrls = scopedRepository.getURLs();
+
+      //This is a bit of a hack, since this relies on the order of the urls returned by HeirarchicalLoaderRepository3
+      //My urls, followed by parent urls.
+      int scopedLength = 0;
+      for (int i = 0 ; i < scopedRepositoryUrls.length ; i++)
+      {
+         for (int j = 0 ; j < globalUrls.length ; j ++)
+         {
+            if (scopedRepositoryUrls[i].equals(globalUrls[j]))
+            {
+               scopedLength = i;
+               break;
+            }
+         }
+         if (scopedLength > 0)
+         {
+            break;
+         }
+      }
+      
+      URL[] localUrls = new URL[scopedLength];
+      System.arraycopy(scopedRepositoryUrls, 0, localUrls, 0, scopedLength);
+      return localUrls;
+   }
+   
+   public class UrlInfo
+   {
+      
+      URL[] globalUrls;
+      URL[] localUrls;
+      long sequenceNumber;
+
+      public UrlInfo(URL[] globalUrls, URL[] localUrls, long sequenceNumber)
+      {
+         super();
+         this.globalUrls = globalUrls;
+         this.localUrls = localUrls;
+         this.sequenceNumber = sequenceNumber;
+      }
+      
+      public URL[] getGlobalUrls()
+      {
+         return globalUrls;
+      }
+      
+      public URL[] getLocalUrls()
+      {
+         return localUrls;
+      }
+
+      public long getSequenceNumber()
+      {
+         return sequenceNumber;
+      }
+   }
+   
+}


Property changes on: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/LoaderRepositoryUrlUtil.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ScopedJBossClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ScopedJBossClassPool.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ScopedJBossClassPool.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,273 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classpool.plugins.ucl;
+
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.NotFoundException;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classpool.plugins.ucl.LoaderRepositoryUrlUtil.UrlInfo;
+import org.jboss.classpool.spi.AbstractClassPool;
+import org.jboss.classpool.spi.ClassPoolRepository;
+import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ * A classpool in JBoss backed by a scoped (HierarchicalLoaderRepository) loader repository
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+public class ScopedJBossClassPool extends JBossClassPool 
+{
+   final static LoaderRepositoryUrlUtil LOADER_REPOSITORY_UTIL = new LoaderRepositoryUrlUtil();
+   
+   private UrlInfo urlInfo;
+   private ThreadLocal<ClassPool> lastPool = new ThreadLocal<ClassPool>();
+
+   public ScopedJBossClassPool(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository, File tmp, URL tmpURL)
+   {
+      super(cl, src, repository, tmp, tmpURL);
+      
+      boolean parentFirst = false;
+      LoaderRepository loaderRepository = null;
+      ClassLoader prnt = cl;
+      while (prnt != null)
+      {
+         if (prnt instanceof RepositoryClassLoader)
+         {
+            loaderRepository = ((RepositoryClassLoader)prnt).getLoaderRepository();
+            if (loaderRepository instanceof HeirarchicalLoaderRepository3)
+            {
+               parentFirst = ((HeirarchicalLoaderRepository3)loaderRepository).getUseParentFirst();
+            }
+            break;
+         }
+         prnt = SecurityActions.getParent(cl);
+      }
+      
+      super.childFirstLookup = !parentFirst;
+   }
+   
+
+   private HeirarchicalLoaderRepository3 getRepository()
+   {
+      ClassLoader cl = getClassLoader0();
+      if (cl != null)
+      {
+         return (HeirarchicalLoaderRepository3)((RepositoryClassLoader)cl).getLoaderRepository();
+      }
+      return null;
+   }
+
+   private URL getResourceUrlForClass(String resourcename)
+   {
+      HeirarchicalLoaderRepository3 repo = getRepository();
+      return repo.getResource(resourcename, super.getClassLoader());
+   }
+   
+   private boolean isMine(URL url)
+   {
+      HeirarchicalLoaderRepository3 repo = getRepository();
+      if (repo != null)
+      {
+         //The URL of the class loaded with my scoped classloader
+         if (url != null)
+         {
+            urlInfo = LOADER_REPOSITORY_UTIL.getURLInfo(getRepository(), urlInfo);
+            
+            URL[] myUrls = urlInfo.getLocalUrls();
+            String resource = url.toString();
+            for (int i = 0 ; i < myUrls.length ; i++)
+            {
+               if (resource.indexOf(myUrls[i].toString()) >= 0)
+               {
+                  return true;
+               }
+            }
+            return false;
+         }
+      }
+      return true;
+   }
+
+   public CtClass getCached(String classname)
+   {
+      if (classname == null)
+      {
+         return null;
+      }
+      if (isUnloadedClassLoader())
+      {
+         return null;
+      }
+
+      if (generatedClasses.get(classname) != null)
+      {
+         //It is a new class, and this callback is probably coming from the frozen check when creating a new nested class
+         return super.getCached(classname);
+      }
+      
+      //Is this from the scoped classloader itself of from the parent?
+      String resourcename = getResourceName(classname);
+      URL url = getResourceUrlForClass(resourcename);
+      boolean isMine = isMine(url);
+      
+      if (isMine)
+      {
+         if (super.childFirstLookup)
+         {
+            //Parent delegation is false, attempt to get this class out of ourselves
+            CtClass clazz = super.getCachedLocally(classname);
+            if (clazz == null)
+            {
+               clazz = createCtClass(classname, false);
+               if (clazz != null)
+               {
+                  lockInCache(clazz);
+               }
+            }
+            if (clazz != null)
+            {
+               return clazz;
+            }
+         }
+         return super.getCached(classname);
+      }
+      
+
+      try
+      {
+         ClassPool pool = getCorrectPoolForResource(classname, url);
+         if (pool != lastPool.get())
+         {
+            lastPool.set(pool);
+            return pool.get(classname);
+         }
+      }
+      catch (NotFoundException e)
+      {
+      }
+      catch(StackOverflowError e)
+      {
+         throw e;
+      }
+      finally
+      {
+         lastPool.set(null);
+      }
+
+      return null;
+   }
+
+   @Override
+   protected boolean includeInGlobalSearch()
+   {
+      return false;
+   }
+   
+   private ClassPool getCorrectPoolForResource(String classname, URL url)
+   {
+      ClassPoolRepository classPoolRepository = ClassPoolRepository.getInstance();
+      synchronized(classPoolRepository.getRegisteredCLs())
+      {
+         //JBoss 5 has an extra NoAnnotationURLCLassLoader that is not on the default path, make sure that that is checked at the end
+         //FIXME This needs revisiting/removing once the 
+         ArrayList<AbstractClassPool> noAnnotationURLClassLoaderPools = null;
+         String resource = url.toString();
+         for(ClassPool pool : classPoolRepository.getRegisteredCLs().values())
+         {
+            AbstractClassPool candidate = (AbstractClassPool)pool;
+            if (candidate.isUnloadedClassLoader())
+            {
+               classPoolRepository.unregisterClassLoader(candidate.getClassLoader());
+               continue;
+            }
+            
+            if (candidate.getClassLoader() instanceof RepositoryClassLoader)
+            {
+               //Sometimes the ClassLoader is a proxy for MBeanProxyExt?!
+               RepositoryClassLoader rcl = (RepositoryClassLoader)candidate.getClassLoader();
+               URL[] urls = rcl.getClasspath();
+               
+               for (int i = 0 ; i < urls.length ; i++)
+               {
+                  if (resource.indexOf(urls[i].getFile()) >= 0)
+                  {
+                     return candidate;
+                  }
+               }
+            }
+            //FIXME Remove once we have the JBoss 5 version of pool
+            else if (isInstanceOfNoAnnotationURLClassLoader(candidate.getClassLoader()))
+            {
+               if (noAnnotationURLClassLoaderPools == null)
+               {
+                  noAnnotationURLClassLoaderPools = new ArrayList<AbstractClassPool>(); 
+               }
+               noAnnotationURLClassLoaderPools.add(candidate);
+            }
+         }
+         
+         //FIXME Remove once we have the JBoss 5 version of pool
+         if (noAnnotationURLClassLoaderPools != null)
+         {
+            for (AbstractClassPool pool : noAnnotationURLClassLoaderPools)
+            {
+               try
+               {
+                  pool.get(classname);
+                  return pool;
+               }
+               catch(NotFoundException ignoreTryNext)
+               {
+               }
+            }
+         }
+      }
+      return ClassPoolRepository.getInstance().getClassPoolFactory().
+      create(ClassPool.getDefault(), ClassPoolRepository.getInstance());
+   }
+   
+   /**
+    * NoAnnotationURLCLassLoader lives in different packages in JBoss 4 and 5
+    */
+   private boolean isInstanceOfNoAnnotationURLClassLoader(ClassLoader loader)
+   {
+      Class<?> parent = loader.getClass();
+      while (parent != null)
+      {
+         if ("NoAnnotationURLClassLoader".equals(parent.getSimpleName()))
+         {
+            return true;
+         }
+         parent = parent.getSuperclass();
+      }
+      return false;
+   }
+}


Property changes on: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ScopedJBossClassPool.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ScopedRepositoryClassLoaderHelper.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ScopedRepositoryClassLoaderHelper.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ScopedRepositoryClassLoaderHelper.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.classpool.plugins.ucl;
+
+import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @autor adrian at jboss.org
+ * @version $Revision$
+ */
+public class ScopedRepositoryClassLoaderHelper
+{
+   public static boolean isScopedClassLoader(ClassLoader loader)
+   {
+      boolean scoped = false;
+      if (loader instanceof RepositoryClassLoader)
+      {
+         LoaderRepository repository = ((RepositoryClassLoader)loader).getLoaderRepository();
+         if (repository instanceof HeirarchicalLoaderRepository3)
+         {
+            scoped = true;
+            //HeirarchicalLoaderRepository3 hlr = (HeirarchicalLoaderRepository3)repository;
+            //boolean parentFirst = hlr.getUseParentFirst();
+         }
+      }
+      return scoped;
+   }
+}


Property changes on: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ScopedRepositoryClassLoaderHelper.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/SecurityActions.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/SecurityActions.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/SecurityActions.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,84 @@
+/*
+* 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.classpool.plugins.ucl;
+
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+class SecurityActions
+{
+   interface GetParentAction
+   {
+      ClassLoader getParent(ClassLoader loader);
+      
+      GetParentAction NON_PRIVILEGED = new GetParentAction()
+      {
+         public ClassLoader getParent(ClassLoader loader)
+         {
+            return loader.getParent();
+         }
+      };
+      
+      GetParentAction PRIVILEGED = new GetParentAction()
+      {
+         public ClassLoader getParent(final ClassLoader loader)
+         {
+            try
+            {
+               return AccessController.doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
+               {
+                  public ClassLoader run() throws Exception
+                  {
+                     return loader.getParent();
+                  }
+               });
+            }
+            catch (PrivilegedActionException e)
+            {
+               throw new RuntimeException(e.getException());
+            }
+         }
+      };
+   }
+   
+   public static ClassLoader getParent(ClassLoader loader)
+   {
+      if (loader == null)
+      {
+         return null;
+      }
+      if (System.getSecurityManager() == null)
+      {
+         return GetParentAction.NON_PRIVILEGED.getParent(loader);
+      }
+      else
+      {
+         return GetParentAction.PRIVILEGED.getParent(loader);
+      }
+   }
+}


Property changes on: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/SecurityActions.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ToClassInvoker.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ToClassInvoker.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ToClassInvoker.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,103 @@
+/*
+* 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.classpool.plugins.ucl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.CtClass;
+
+import org.jboss.logging.Logger;
+import org.jboss.mx.loading.RepositoryClassLoader;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+public class ToClassInvoker
+{
+   Logger logger = Logger.getLogger(this.getClass());
+
+   public File tmpDir;
+
+   public Object tmplock = new Object();
+
+   public ToClassInvoker(File tmpDir)
+   {
+      this.tmpDir = tmpDir;
+   }
+
+   public Class<?> toClass(ToClassInvokerPoolReference pool, CtClass cc, String classFileName, ClassLoader loader, ProtectionDomain domain)
+   throws CannotCompileException
+   {
+      boolean trace = logger.isTraceEnabled();
+      pool.lockInCache(cc);
+      final ClassLoader myloader = pool.getClassLoader();
+      if (myloader == null || tmpDir == null)
+      {
+         if (trace) logger.trace(this + " " + pool + ".toClass() myloader:" + myloader + " tmpDir:" + tmpDir + " default to superPool.toClass for " + cc.getName());
+         Class<?> clazz = pool.superPoolToClass(cc, loader, domain);
+         if (trace) logger.trace(this + " " + pool + " myloader:" + myloader + " created class:" + clazz);
+         return clazz;
+      }
+      Class<?> dynClass = null;
+      try
+      {
+         File classFile = null;
+         // Write the clas file to the tmpdir
+         synchronized (tmplock)
+         {
+            classFile = new File(tmpDir, classFileName);
+            if (trace) logger.trace(this + " " + pool + ".toClass() myloader:" + myloader + " writing bytes to " + classFile);
+            File pkgDirs = classFile.getParentFile();
+            pkgDirs.mkdirs();
+            FileOutputStream stream = new FileOutputStream(classFile);
+            stream.write(cc.toBytecode());
+            stream.flush();
+            stream.close();
+            classFile.deleteOnExit();
+         }
+         // We have to clear Blacklist caches or the class will never
+         // be found
+         //((UnifiedClassLoader)dcl).clearBlacklists();
+         // To be backward compatible
+         RepositoryClassLoader rcl = (RepositoryClassLoader)myloader;
+         rcl.clearClassBlackList();
+         rcl.clearResourceBlackList();
+
+         // Now load the class through the cl
+         dynClass = myloader.loadClass(cc.getName());
+         if (trace) logger.trace(this + " " + pool + " myloader:" + myloader + " created class:" + dynClass);
+         return dynClass;
+      }
+      catch (Exception ex)
+      {
+         ClassFormatError cfe = new ClassFormatError("Failed to load dyn class: " + cc.getName());
+         cfe.initCause(ex);
+         throw cfe;
+      }
+   }
+
+}


Property changes on: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ToClassInvoker.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

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


Property changes on: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/ToClassInvokerPoolReference.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/UclDelegatingClassPool.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/UclDelegatingClassPool.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/UclDelegatingClassPool.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,68 @@
+/*
+* 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.classpool.plugins.ucl;
+
+import java.io.File;
+import java.net.URL;
+import java.security.ProtectionDomain;
+
+import javassist.CannotCompileException;
+import javassist.ClassPool;
+import javassist.CtClass;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classpool.domain.ClassPoolDomain;
+import org.jboss.classpool.plugins.DelegatingClassPool;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+public class UclDelegatingClassPool extends DelegatingClassPool implements ToClassInvokerPoolReference
+{
+   ToClassInvoker toClassInvoker = null;
+
+   public UclDelegatingClassPool(ClassPoolDomain domain, ClassLoader cl, ClassPool parent, 
+         ScopedClassPoolRepository repository, File tmpDir, URL tmpURL)
+   {
+      super(domain, cl, parent, repository);
+      toClassInvoker = new ToClassInvoker(tmpDir);
+   }
+
+   public Class<?> toClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+   {
+      return toClassInvoker.toClass(this, cc, getResourceName(cc.getName()), loader, domain);
+   }
+
+   public Class<?> superPoolToClass(CtClass cc, ClassLoader loader, ProtectionDomain domain) throws CannotCompileException
+   {
+      return super.toClass(cc, loader, domain);
+   }
+
+   @Override
+   public void lockInCache(CtClass clazz)
+   {
+      super.lockInCache(clazz);
+      localResources.put(getResourceName(clazz.getName()), Boolean.TRUE);
+   }
+}


Property changes on: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/UclDelegatingClassPool.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/UclDelegatingClassPoolFactory.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/UclDelegatingClassPoolFactory.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/UclDelegatingClassPoolFactory.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,169 @@
+/*
+* 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.classpool.plugins.ucl;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import javassist.ClassPool;
+import javassist.scopedpool.ScopedClassPoolRepository;
+
+import org.jboss.classpool.base.BaseClassPoolDomain;
+import org.jboss.classpool.domain.ClassPoolDomain;
+import org.jboss.classpool.domain.ClassPoolDomainRegistry;
+import org.jboss.classpool.plugins.NonDelegatingClassPool;
+import org.jboss.classpool.plugins.temp.TempClassPoolFactory;
+import org.jboss.classpool.spi.AbstractClassPool;
+import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.loading.RepositoryClassLoader;
+import org.jboss.mx.server.ServerConstants;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+public class UclDelegatingClassPoolFactory extends TempClassPoolFactory
+{
+   private ClassPoolDomain mainDomain;
+   protected File tmpClassesDir;
+
+   public UclDelegatingClassPoolFactory(File tmpClassesDir) throws IOException
+   {
+      System.out.println("TMP CLASSES DIR: " + tmpClassesDir);
+      this.tmpClassesDir = tmpClassesDir;
+   }
+   
+   public synchronized AbstractClassPool create(ClassLoader cl, ClassPool src, ScopedClassPoolRepository repository)
+   {
+      ClassPool parent = getCreateParentClassPools(cl, src, repository);
+
+      if (cl instanceof RepositoryClassLoader)
+      {
+         ClassPoolDomain domain = getDomain((RepositoryClassLoader)cl);  
+         
+         File tempdir = getTempDirectory(cl);
+         URL tmpCP = createURLAndAddToLoader(cl, tempdir);
+         
+         return new UclDelegatingClassPool(domain, cl, parent, repository, tempdir, tmpCP);
+      }
+      
+      if (parent == null)
+      {
+         parent = ClassPool.getDefault();
+      }
+      return new NonDelegatingClassPool(cl, parent, repository, true);
+   }
+
+   private ClassPoolDomain getDomain(RepositoryClassLoader cl)
+   {
+      LoaderRepository loaderRepository = cl.getLoaderRepository();
+      ClassPoolDomainRegistry registry = ClassPoolDomainRegistry.getInstance();
+      ClassPoolDomain domain = registry.getDomain(loaderRepository);
+      if (domain == null)
+      {
+         if (loaderRepository instanceof HeirarchicalLoaderRepository3)
+         {
+            
+            boolean parentFirst = ((HeirarchicalLoaderRepository3)loaderRepository).getUseParentFirst();
+            domain = new BaseClassPoolDomain("Scoped" + System.identityHashCode(loaderRepository), mainDomain, parentFirst);
+         }
+         else
+         {
+            if (mainDomain == null)
+            {
+               domain = new BaseClassPoolDomain(ServerConstants.DEFAULT_LOADER_NAME, null, false);
+               mainDomain = domain;
+            }
+            else
+            {
+               domain = mainDomain;
+            }
+            registry.addClassPoolDomain(loaderRepository, domain);
+         }
+      }
+      return domain;
+   }
+   
+   protected File getTempDirectory(ClassLoader cl)
+   {
+      File tempdir = null;
+      int attempts = 0;
+      IOException ex = null;
+      while (tempdir == null && attempts < 5)
+      {
+         //Workaround for JBAOP-254, retry a few times
+         try
+         {
+            tempdir = createTempDir(cl);
+         }
+         catch (IOException e)
+         {
+            ex = e;
+         }
+      }
+      
+      if (tempdir == null)
+      {
+         throw new RuntimeException("", ex);
+      }
+      
+      return tempdir;
+   }
+
+   public File createTempDir(ClassLoader cl) throws IOException
+   {
+      File tempdir = File.createTempFile("ucl", "", tmpClassesDir);
+      tempdir.delete();
+      tempdir.mkdir();
+      tempdir.deleteOnExit();
+
+      return tempdir;
+   }
+   
+   private URL createURLAndAddToLoader(ClassLoader cl, File tempdir)
+   {
+      try
+      {
+         URL tmpURL = tempdir.toURL();
+         URL tmpCP = new URL(tmpURL, "?dynamic=true");
+
+         RepositoryClassLoader ucl = (RepositoryClassLoader) cl;
+
+         // We may be undeploying.
+         if (ucl.getLoaderRepository() != null)
+         {
+            ucl.addURL(tmpCP);
+         }
+         
+         return tmpCP;
+      }
+      catch(Exception e)
+      {
+         // AutoGenerated
+         throw new RuntimeException(e);
+      }
+   }
+
+}


Property changes on: projects/jboss-classpool/trunk/ucl/src/main/java/org/jboss/classpool/plugins/ucl/UclDelegatingClassPoolFactory.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/main/resources/jbossorg-eula.txt
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/main/resources/jbossorg-eula.txt	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/main/resources/jbossorg-eula.txt	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,107 @@
+LICENSE AGREEMENT
+JBOSS(r)
+
+This License Agreement governs the use of the Software Packages and any updates to the Software 
+Packages, regardless of the delivery mechanism.  Each Software Package is a collective work 
+under U.S. Copyright Law.  Subject to the following terms, Red Hat, Inc. ("Red Hat") grants to 
+the user ("Client") a license to the applicable collective work(s) pursuant to the 
+GNU Lesser General Public License v. 2.1 except for the following Software Packages: 
+(a) JBoss Portal Forums and JBoss Transactions JTS, each of which is licensed pursuant to the 
+GNU General Public License v.2; 
+
+(b) JBoss Rules, which is licensed pursuant to the Apache  License v.2.0;
+
+(c) an optional download for JBoss Cache for the Berkeley DB for Java database, which is licensed under the 
+(open source) Sleepycat License (if Client does not wish to use the open source version of this database, 
+it may purchase a license from Sleepycat Software); 
+
+and (d) the BPEL extension for JBoss jBPM, which is licensed under the Common Public License v.1, 
+and, pursuant to the OASIS BPEL4WS standard, requires parties wishing to redistribute to enter various 
+royalty-free patent licenses.  
+
+Each of the foregoing licenses is available at http://www.opensource.org/licenses/index.php.
+
+1.  The Software.  "Software Packages" refer to the various software modules that are created and made available 
+for distribution by the JBoss.org open source community at http://www.jboss.org.   Each of the Software Packages 
+may be comprised of hundreds of software components.  The end user license agreement for each component is located in 
+the component's source code.  With the exception of certain image files identified in Section 2 below, 
+the license terms for the components permit Client to copy, modify, and redistribute the component, 
+in both source code and binary code forms.  This agreement does not limit Client's rights under, 
+or grant Client rights that supersede, the license terms of any particular component.
+
+2.  Intellectual Property Rights.  The Software Packages are owned by Red Hat and others and are protected under copyright 
+and other laws.  Title to the Software Packages and any component, or to any copy, modification, or merged portion shall 
+remain with the aforementioned, subject to the applicable license.  The "JBoss" trademark, "Red Hat" trademark, the 
+individual Software Package trademarks, and the "Shadowman" logo are registered trademarks of Red Hat and its affiliates 
+in the U.S. and other countries.  This agreement permits Client to distribute unmodified copies of the Software Packages 
+using the Red Hat trademarks that Red Hat has inserted in the Software Packages on the condition that Client follows Red Hat's 
+trademark guidelines for those trademarks located at http://www.redhat.com/about/corporate/trademark/.  Client must abide by 
+these trademark guidelines when distributing the Software Packages, regardless of whether the Software Packages have been modified. 
+If Client modifies the Software Packages, then Client must replace all Red Hat trademarks and logos identified at 
+http://www.jboss.com/company/logos, unless a separate agreement with Red Hat is executed or other permission granted.  
+Merely deleting the files containing the Red Hat trademarks may corrupt the Software Packages.  
+
+3.  Limited Warranty.  Except as specifically stated in this Paragraph 3 or a license for a particular 
+component, to the maximum extent permitted under applicable law, the Software Packages and the 
+components are provided and licensed "as is" without warranty of any kind, expressed or implied, 
+including the implied warranties of merchantability, non-infringement or fitness for a particular purpose.  
+Red Hat warrants that the media on which Software Packages may be furnished will be free from defects in 
+materials and manufacture under normal use for a period of 30 days from the date of delivery to Client.  
+Red Hat does not warrant that the functions contained in the Software Packages will meet Client's requirements 
+or that the operation of the Software Packages will be entirely error free or appear precisely as described 
+in the accompanying documentation. This warranty extends only to the party that purchases the Services 
+pertaining to the Software Packages from Red Hat or a Red Hat authorized distributor. 
+
+4.  Limitation of Remedies and Liability. To the maximum extent permitted by applicable law, the remedies 
+described below are accepted by Client as its only remedies.  Red Hat's entire liability, and Client's 
+exclusive remedies, shall be: If the Software media is defective, Client may return it within 30 days of 
+delivery along with a copy of Client's payment receipt and Red Hat, at its option, will replace it or 
+refund the money paid by Client for the Software.  To the maximum extent permitted by applicable law, 
+Red Hat or any Red Hat authorized dealer will not be liable to Client for any incidental or consequential 
+damages, including lost profits or lost savings arising out of the use or inability to use the Software, 
+even if Red Hat or such dealer has been advised of the possibility of such damages.  In no event shall 
+Red Hat's liability under this agreement exceed the amount that Client paid to Red Hat under this 
+Agreement during the twelve months preceding the action.
+
+5.  Export Control.  As required by U.S. law, Client represents and warrants that it: 
+(a) understands that the Software Packages are subject to export controls under the 
+U.S. Commerce Department's Export Administration Regulations ("EAR"); 
+
+(b) is not located in a prohibited destination country under the EAR or U.S. sanctions regulations 
+(currently Cuba, Iran, Iraq, Libya, North Korea, Sudan and Syria); 
+
+(c) will not export, re-export, or transfer the Software Packages to any prohibited destination, entity, 
+or individual without the necessary export license(s) or authorizations(s) from the U.S. Government; 
+
+(d) will not use or transfer the Software Packages for use in any sensitive nuclear, chemical or 
+biological weapons, or missile technology end-uses unless authorized by the U.S. Government by 
+regulation or specific license; 
+
+(e) understands and agrees that if it is in the United States and exports or transfers the Software 
+Packages to eligible end users, it will, as required by EAR Section 740.17(e), submit semi-annual 
+reports to the Commerce Department's Bureau of Industry & Security (BIS), which include the name and 
+address (including country) of each transferee; 
+
+and (f) understands that countries other than the United States may restrict the import, use, or 
+export of encryption products and that it shall be solely responsible for compliance with any such 
+import, use, or export restrictions.
+
+6.  Third Party Programs. Red Hat may distribute third party software programs with the Software Packages 
+that are not part of the Software Packages and which Client must install separately.  These third party 
+programs are subject to their own license terms.  The license terms either accompany the programs or 
+can be viewed at http://www.redhat.com/licenses/.  If Client does not agree to abide by the applicable 
+license terms for such programs, then Client may not install them.  If Client wishes to install the programs 
+on more than one system or transfer the programs to another party, then Client must contact the licensor 
+of the programs.
+
+7.  General.  If any provision of this agreement is held to be unenforceable, that shall not affect the 
+enforceability of the remaining provisions.  This License Agreement shall be governed by the laws of the 
+State of North Carolina and of the United States, without regard to any conflict of laws provisions, 
+except that the United Nations Convention on the International Sale of Goods shall not apply.
+
+Copyright 2006 Red Hat, Inc.  All rights reserved.  
+"JBoss" and the JBoss logo are registered trademarks of Red Hat, Inc.  
+All other trademarks are the property of their respective owners. 
+
+	Page 1 of 1	18 October 2006
+


Property changes on: projects/jboss-classpool/trunk/ucl/src/main/resources/jbossorg-eula.txt
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/UclClassPoolTestSuite.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/UclClassPoolTestSuite.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/UclClassPoolTestSuite.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,55 @@
+/*
+ * 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.classpool.ucl;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.classpool.ucl.test.CtClassCreationTestCase;
+import org.jboss.test.classpool.ucl.test.RepositoryClassPoolTestCase;
+import org.jboss.test.classpool.ucl.test.RepositorySanityTestCase;
+
+/**
+ * Test suite containing all UCL tests.
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+public class UclClassPoolTestSuite extends TestSuite
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("UclClassPool All Tests");
+      
+      suite.addTestSuite(RepositorySanityTestCase.class);
+      suite.addTestSuite(RepositoryClassPoolTestCase.class);
+      suite.addTestSuite(CtClassCreationTestCase.class);
+      
+      return suite;
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/UclClassPoolTestSuite.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ChildUCLInfo.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ChildUCLInfo.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ChildUCLInfo.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.classpool.ucl.support;
+
+import static org.jboss.test.classpool.ucl.support.UCLFactory.MAIN_LOADER_REPOSITORY_OBJECT_NAME;
+
+import java.net.URL;
+
+import org.jboss.mx.loading.HeirarchicalLoaderRepository3;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.util.MBeanServerLocator;
+
+/**
+ * Creates a UCL in new loader repository. This loader repository will be registered as a child
+ * to the global repository.
+ * 
+ * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class ChildUCLInfo extends UCLInfo
+{
+   private boolean parentFirst;
+   
+   /**
+    * Constructor.
+    * 
+    * @param url         the classpath of the class loader
+    * @param parentFirst indicates the policy that will be used by the child loader repository
+    *                    for delegation to its parent (the global repository) 
+    */
+   public ChildUCLInfo(URL url, boolean parentFirst)
+   {
+      super(url);
+      this.parentFirst = parentFirst;
+   }
+   
+   @Override
+   protected ClassLoader internalCreate(LoaderRepository globalRepository) throws Exception
+   {
+      HeirarchicalLoaderRepository3 repository = new HeirarchicalLoaderRepository3(
+            MBeanServerLocator.locateJBoss(), MAIN_LOADER_REPOSITORY_OBJECT_NAME);
+      repository.setUseParentFirst(parentFirst);
+      ClassLoader cl = repository.newClassLoader(url, true);
+      return cl;
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ChildUCLInfo.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/GlobalUCLInfo.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/GlobalUCLInfo.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/GlobalUCLInfo.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.classpool.ucl.support;
+
+import java.net.URL;
+
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.loading.UnifiedClassLoader3;
+
+/**
+ * Creates an UnifiedClassLoader registered to the global repository.
+ * 
+ * @author <a href="mailto:flavia.rainone at jboss.org">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class GlobalUCLInfo extends UCLInfo
+{
+   private ClassLoader parent;
+   
+   public GlobalUCLInfo(URL url)
+   {
+      super(url);
+   }
+   
+   public GlobalUCLInfo(URL url, ClassLoader parent)
+   {
+      this(url);
+      this.parent = parent;
+   }
+   
+   @Override
+   protected ClassLoader internalCreate(LoaderRepository repository) throws Exception
+   {
+      if (parent == null)
+      {
+         return repository.newClassLoader(url, true);
+      }
+      else
+      {
+         ClassLoader classLoader = new UnifiedClassLoader3(url, null, parent, repository);
+         repository.addClassLoader(classLoader);
+         return classLoader; 
+      }
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/GlobalUCLInfo.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ParentLastURLClassLoader.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ParentLastURLClassLoader.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ParentLastURLClassLoader.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,81 @@
+/*
+* 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.classpool.ucl.support;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+/**
+ * An attempt to emulate the web classloader with parent last search order in AS.
+ * This class cannot be used for Sanity tests, because of its delegation structure, if you call
+ * Class<?>.getClassLoader() on a class loaded by it, it will never return this class loader.
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+public class ParentLastURLClassLoader extends URLClassLoader
+{
+   ClassLoader parent;
+   URLClassLoader delegate;
+
+   public ParentLastURLClassLoader(URL[] urls, ClassLoader parent)
+   {
+      super(urls, parent);
+      delegate = new URLClassLoader(urls);
+      this.parent = parent;
+   }
+
+   @Override
+   public URL findResource(String name)
+   {
+      URL url = delegate.findResource(name);
+      if (url == null && parent instanceof URLClassLoader)
+      {
+         url = ((URLClassLoader)parent).findResource(name);
+      }
+      return url;
+   }
+
+   @Override
+   public URL getResource(String name)
+   {
+      URL url = delegate.getResource(name);
+      if (url == null)
+      {
+         url = parent.getResource(name);
+      }
+      return url;
+   }
+
+   @Override
+   public Class<?> loadClass(String name) throws ClassNotFoundException
+   {
+      try
+      {
+         return delegate.loadClass(name);
+      }
+      catch(ClassNotFoundException e)
+      {
+      }
+      return parent.loadClass(name);
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ParentLastURLClassLoader.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ParentLastURLClassLoaderInfo.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ParentLastURLClassLoaderInfo.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ParentLastURLClassLoaderInfo.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.classpool.ucl.support;
+
+import java.net.URL;
+
+import org.jboss.mx.loading.LoaderRepository;
+
+/**
+ * Contains information for the creation of a {@link ParentLastURLClassLoader}.
+ * 
+ * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class ParentLastURLClassLoaderInfo extends UCLInfo
+{
+   private ClassLoader parent;
+   
+   /**
+    * Constructor.
+    * 
+    * @param url    the classpath of the classloader
+    * @param parent the parent of the class loader
+    */
+   public ParentLastURLClassLoaderInfo(URL url, ClassLoader parent)
+   {
+      super(url);
+      this.parent = parent;
+   }
+
+   @Override
+   protected ClassLoader internalCreate(LoaderRepository repository) throws Exception
+   {
+      return new ParentLastURLClassLoader(new URL[] {url}, parent);
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/ParentLastURLClassLoaderInfo.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/SupportArchives.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/SupportArchives.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/SupportArchives.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,63 @@
+package org.jboss.test.classpool.ucl.support;
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.
+ */
+
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+
+/**
+ * Contains the name of the support archives.
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class SupportArchives
+{
+   /************ CLASSPATH URLS ***************************/
+   
+   public final static URL JAR_A_1_URL = getURL("a1.jar");
+   public final static URL JAR_A_2_URL = getURL("a2.jar");
+   public final static URL JAR_B_1_URL = getURL("b1.jar");
+   public final static URL JAR_B_2_URL = getURL("b2.jar");
+   public final static URL JAR_C_1_URL = getURL("c.jar");
+   
+   /** Returns the relative URL to the project root */
+   private static URL getURL(String relativePath)
+   {
+      try
+      {
+         URL url = SupportArchives.class.getProtectionDomain().getCodeSource().getLocation();
+         String location = url.toString();
+         int index = location.lastIndexOf("/target/") + "/target/".length();
+         location = location.substring(0, index) + "archives/";
+         
+         location = location + relativePath;
+         return new URL(location);
+      }
+      catch (MalformedURLException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/SupportArchives.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/SupportClasses.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/SupportClasses.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/SupportClasses.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,29 @@
+package org.jboss.test.classpool.ucl.support;
+
+
+
+
+
+/**
+ * Contains the name of all support classes.
+ * 
+ * @author  <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class SupportClasses
+{
+   public static final String PACKAGE_ROOT = SupportClasses.class.getPackage().getName() + ".excluded";
+   public final static String PACKAGE_A = PACKAGE_ROOT + ".a";
+   public final static String PACKAGE_B = PACKAGE_ROOT + ".b";
+   public final static String PACKAGE_C = PACKAGE_ROOT + ".c";
+   public final static String CLASS_A = PACKAGE_A + ".A";
+   public final static String CLASS_B = PACKAGE_B + ".B";
+   public final static String CLASS_C = PACKAGE_C + ".C";
+   
+   private static final String[] SUPPORT_CLASSES = new String[]{CLASS_A, CLASS_B, CLASS_C};
+   
+   public static final String[] getAllSupportClasses()
+   {
+      return SUPPORT_CLASSES;
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/SupportClasses.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/UCLFactory.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/UCLFactory.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/UCLFactory.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,191 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.classpool.ucl.support;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import junit.framework.Assert;
+
+import org.jboss.classpool.spi.ClassPoolRepository;
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.mx.loading.RepositoryClassLoader;
+import org.jboss.mx.loading.UnifiedLoaderRepository3;
+import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.test.classpool.support.ClassLoaderFactory;
+import org.jboss.util.NotImplementedException;
+
+/**
+ * A factory of Unified Class Loaders.
+ * 
+ * @author <a href="mailto:flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class UCLFactory implements ClassLoaderFactory<UCLInfo>
+{
+   final static ObjectName MAIN_LOADER_REPOSITORY_OBJECT_NAME;
+   static
+   {
+      try
+      {
+         MAIN_LOADER_REPOSITORY_OBJECT_NAME = new ObjectName(
+         "JMImplementation:name=Default,service=LoaderRepository");
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   // The global loader repository
+   private LoaderRepository globalRepository;
+   //Keep a strong reference to the classloaders so that they are not garbage collected
+   final static Set<ClassLoader> registeredClassLoaders = new HashSet<ClassLoader>();
+
+   /**
+    * Constructor.
+    */
+   public UCLFactory()
+   {
+      try
+      {
+         MBeanServer mBeanServer = MBeanServerLocator.locateJBoss();
+         globalRepository = (LoaderRepository)mBeanServer.invoke(
+               MAIN_LOADER_REPOSITORY_OBJECT_NAME, "getInstance", new Object[0], new String[0]);
+      }
+      catch(Exception e)
+      {
+         throw new RuntimeException("Unexpected exception", e);
+      }
+   }
+
+   public ClassLoader create(UCLInfo uclInfo) throws Exception
+   {
+      ClassLoader classLoader = uclInfo.create(globalRepository);
+      registeredClassLoaders.add(classLoader);
+      return classLoader;
+   }
+
+   public void destroy(UCLInfo uclInfo) throws Exception
+   {
+      ClassLoader classLoader = uclInfo.getCreatedClassLoader();
+      destroyClassLoader(classLoader);
+      registeredClassLoaders.remove(classLoader);
+   }
+
+   public void destroyAll()
+   {
+      Set<UnifiedLoaderRepository3> repositories = new HashSet<UnifiedLoaderRepository3>(); 
+      for (ClassLoader registeredClassLoader :registeredClassLoaders)
+      {
+         LoaderRepository repository = destroyClassLoader(registeredClassLoader);
+         if (repository != null && repository instanceof UnifiedLoaderRepository3)
+         {
+            repositories.add((UnifiedLoaderRepository3) repository);
+         }
+      }
+      // FIXME: this is here to cover a bug
+      for (UnifiedLoaderRepository3 repository: repositories)
+      {
+         repository.flush();
+      }
+      registeredClassLoaders.clear();
+      for (String className: SupportClasses.getAllSupportClasses())
+      {
+         try
+         {
+            globalRepository.loadClass(className);
+            Assert.fail("Should not have been able to load " + className);
+         }
+         catch(Exception expected) {}
+      }
+   }
+
+   public ClassLoader retrieve(UCLInfo uclInfo) throws Exception
+   {
+      return uclInfo.getCreatedClassLoader();
+   }
+
+   public Collection<ClassLoader> retrieveAll()
+   {
+      return registeredClassLoaders;
+   }
+
+   /************* HELPER METHODS **********************************************************/
+
+   public boolean isAvailable(UCLInfo uclInfo) throws Exception
+   {
+      throw new NotImplementedException("Functionality unavailable");
+   }
+
+   private LoaderRepository destroyClassLoader(ClassLoader classLoader)
+   {
+      if (classLoader != null && classLoader instanceof RepositoryClassLoader)
+      {
+         RepositoryClassLoader repoClassLoader = (RepositoryClassLoader) classLoader;
+         LoaderRepository repository = repoClassLoader.getLoaderRepository();
+         repository.removeClassLoader(repoClassLoader);
+         //Delete the temporary directory since running in Eclipse does not do this automatically
+         deleteTempDir();
+         ClassPoolRepository.getInstance().unregisterClassLoader(classLoader);
+         return repository;
+      }
+      return null;
+   }
+
+   private void deleteTempDir()
+   {
+      File dir = new File(".");
+      String[] uclFiles = dir.list(
+            new FilenameFilter() 
+            {
+               public boolean accept(File dir, String name) 
+               {
+                  return name.startsWith("ucl");
+
+               }
+            });
+      for (String uclFile : uclFiles)
+      {
+         deleteRecursively(dir, uclFile);
+      }
+   }
+
+   private void deleteRecursively(File dir, String name)
+   {
+      File file = new File(dir, name);
+      if (file.isDirectory())
+      {
+         String[] fileNames = file.list();
+         for (String fileName : fileNames)
+         {
+            deleteRecursively(file, fileName);
+         }
+      }
+      file.delete();
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/UCLFactory.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/UCLInfo.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/UCLInfo.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/UCLInfo.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.classpool.ucl.support;
+
+import java.net.URL;
+
+import junit.framework.Assert;
+
+import org.jboss.mx.loading.LoaderRepository;
+import org.jboss.test.classpool.support.ClassLoaderInfo;
+
+/**
+ * Contains information necessary for the creation of a class loader that will be added to
+ * a UCL structure.
+ * 
+ * @author <a href="mailto:flavia.rainone at jboss.org">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public abstract class UCLInfo implements ClassLoaderInfo
+{
+   protected URL url;
+   private ClassLoader createdClassLoader;
+   
+   /**
+    * Constructor.
+    * 
+    * @param url the classpath of the class loader to be created
+    */
+   public UCLInfo(URL url)
+   {
+      this.url = url;
+   }
+   
+   /**
+    * Creates a class loader and adds it to {@code globalRepository}.
+    * Can be called only once.
+    * 
+    * @param globalRepository the global loader repository
+    * @return                 the created class loader
+    * @throws Exception       if an unexpected error occurs
+    */
+   ClassLoader create(LoaderRepository globalRepository) throws Exception
+   {
+      Assert.assertNull("Double creation of class loader", createdClassLoader);
+      this.createdClassLoader = internalCreate(globalRepository);
+      return this.createdClassLoader;
+   }
+   
+   /**
+    * Returns the class loader that has been created by {@link #create(LoaderRepository)}.
+    * Can only be called after {@link #createdClassLoader} has been invoked.
+    * 
+    * @return the created class loader
+    */
+   ClassLoader getCreatedClassLoader()
+   {
+      return this.createdClassLoader;
+   }
+   
+
+   /**
+    * Creates a class loader and adds it to {@code globalRepository}.
+    * Will be called only once.
+    * 
+    * @param globalRepository the global loader repository
+    * @return                 the created class loader
+    * @throws Exception       if an unexpected error occurs
+    */
+   protected abstract ClassLoader internalCreate(LoaderRepository repository) throws Exception;
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/UCLInfo.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/URLClassLoaderInfo.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/URLClassLoaderInfo.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/URLClassLoaderInfo.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.classpool.ucl.support;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import org.jboss.mx.loading.LoaderRepository;
+
+/**
+ * Creates a URLClassLoader.
+ * 
+ * @author <a href="mailto:flavia.rainone at jboss.org">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class URLClassLoaderInfo extends UCLInfo
+{
+   private ClassLoader parent;
+   
+   /**
+    * Constructor.
+    * 
+    * @param url the classpath of the classloader
+    */
+   public URLClassLoaderInfo(URL url)
+   {
+      this(url, null);
+   }
+   
+   /**
+    * Constructor.
+    * 
+    * @param url    the classpath of the classloader
+    * @param parent the parent of the classloader
+    */
+   public URLClassLoaderInfo(URL url, ClassLoader parent)
+   {
+      super(url);
+      this.parent = parent;
+   }
+
+   @Override
+   protected ClassLoader internalCreate(LoaderRepository repository) throws Exception
+   {
+      return new URLClassLoader(new URL[] {url}, parent);
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/URLClassLoaderInfo.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/a/A.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/a/A.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/a/A.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -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.classpool.ucl.support.excluded.a;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+public class A
+{
+
+}


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/a/A.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/b/B.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/b/B.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/b/B.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -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.classpool.ucl.support.excluded.b;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+public class B
+{
+
+}


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/b/B.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/c/C.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/c/C.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/c/C.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -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.classpool.ucl.support.excluded.c;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+public class C
+{
+
+}


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/support/excluded/c/C.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/CtClassCreationTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/CtClassCreationTestCase.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/CtClassCreationTestCase.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,233 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.classpool.ucl.test;
+
+import static org.jboss.test.classpool.ucl.support.SupportArchives.JAR_A_1_URL;
+import static org.jboss.test.classpool.ucl.support.SupportArchives.JAR_B_1_URL;
+import static org.jboss.test.classpool.ucl.support.SupportArchives.JAR_C_1_URL;
+import static org.jboss.test.classpool.ucl.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.ucl.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.ucl.support.SupportClasses.PACKAGE_A;
+import static org.jboss.test.classpool.ucl.support.SupportClasses.PACKAGE_B;
+
+import java.util.ArrayList;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+
+import org.jboss.test.classpool.support.ClassFactory;
+import org.jboss.test.classpool.support.ClassPoolTestScenario;
+import org.jboss.test.classpool.support.TestScenario;
+import org.jboss.test.classpool.ucl.support.GlobalUCLInfo;
+import org.jboss.test.classpool.ucl.support.UCLFactory;
+import org.jboss.test.classpool.ucl.support.UCLInfo;
+import org.jboss.test.classpool.ucl.support.URLClassLoaderInfo;
+
+/**
+ * Tests creation of CtClasses using ClassPools for UCLs.
+ * 
+ * @author <a href="mailto:flavia.rainone at jboss.org">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class CtClassCreationTestCase extends UclClassPoolTest<CtClass, ClassPool>
+{
+   public CtClassCreationTestCase(String name)
+   {
+      super(name);
+   }
+
+   @Override
+   protected TestScenario<CtClass, ClassPool, UCLInfo> getTestScenario()
+   {
+      return new ClassPoolTestScenario<UCLInfo>(new UCLFactory());
+   }
+   
+   public void testGeneratingClassInNonDelegatingPool() throws Exception
+   {
+      final String PARENT = "parent.Parent";
+      final String CHILD = "child.Child";
+      ClassPool parent = testScenario.createLoader(new URLClassLoaderInfo(JAR_B_1_URL));
+      ClassPool global = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL,
+            testScenario.getClassLoader(parent)));
+      ClassPool child = testScenario.createLoader(new URLClassLoaderInfo(JAR_C_1_URL,
+            testScenario.getClassLoader(global)));
+      
+      testScenario.cannotLoadClass(parent, PARENT);
+      testScenario.cannotLoadClass(global, PARENT);
+      testScenario.cannotLoadClass(child, PARENT);
+      testScenario.cannotLoadClass(child, CHILD);
+      
+      CtClass parentClass = parent.makeClass(PARENT);
+      
+      CtClass childClass = child.makeClass(CHILD);
+      childClass.setSuperclass(parentClass);
+      
+      CtClass parentFromParent = parent.getCtClass(PARENT);
+      assertSame(parentClass, parentFromParent);
+      
+      CtClass childFromChild = child.getCtClass(CHILD);
+      assertSame(childClass, childFromChild);
+      
+      testScenario.cannotLoadClass(global, CHILD);
+      
+      CtClass parentFromChildA = childClass.getSuperclass();
+      assertSame(parentClass, parentFromChildA);
+      
+      CtClass parentFromChildB = child.getCtClass(PARENT);
+      assertSame(parent, parentFromChildB.getClassPool());
+      assertSame(parentClass, parentFromChildB);
+      
+      Class<?> parentClazz = parentClass.toClass();
+      assertSame(parent.getClassLoader(), parentClazz.getClassLoader());
+      
+      Class<?> childClazz = childClass.toClass();
+      assertSame(child.getClassLoader(), childClazz.getClassLoader());
+      
+      Class<?> parentClazzFromParent = parent.getClassLoader().loadClass(PARENT);
+      assertSame(parentClazz, parentClazzFromParent);
+      
+      Class<?> parentClazzFromChild = parent.getClassLoader().loadClass(PARENT);
+      assertSame(parentClazz, parentClazzFromChild);
+      
+      Class<?> childClazzFromChild = child.getClassLoader().loadClass(CHILD);
+      assertSame(childClazz, childClazzFromChild);
+
+      child.getClassLoader().loadClass(CLASS_A);
+   }
+   
+   public void testGeneratingClassInDelegatingPool() throws Exception
+   {
+      ClassPool globalA = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL));
+      ClassPool globalB = testScenario.createLoader(new GlobalUCLInfo(JAR_B_1_URL));
+      ClassPool child = testScenario.createLoader(new URLClassLoaderInfo(JAR_C_1_URL,
+            testScenario.getClassLoader(globalA)));
+      final String A_CLASS = "a.Clazz";
+      final String B_CLASS = "b.Clazz";
+      
+      testScenario.cannotLoadClass(globalA, A_CLASS);
+      testScenario.cannotLoadClass(globalB, A_CLASS);
+      testScenario.cannotLoadClass(child, A_CLASS);
+      testScenario.cannotLoadClass(globalA, B_CLASS);
+      testScenario.cannotLoadClass(globalB, B_CLASS);
+      testScenario.cannotLoadClass(child, B_CLASS);
+      
+      CtClass a = globalA.makeClass(A_CLASS);
+      CtClass b = globalB.makeClass(B_CLASS);
+      
+      CtClass aFromA = globalA.getCtClass(A_CLASS);
+      assertSame(a, aFromA);
+      assertSame(globalA, aFromA.getClassPool());
+
+      CtClass aFromB = globalB.get(A_CLASS);
+      assertSame(a, aFromB);
+
+      CtClass bFromA = globalA.get(B_CLASS);
+      assertSame(b, bFromA);
+      assertSame(globalB, bFromA.getClassPool());
+
+      CtClass bFromB = globalB.get(B_CLASS);
+      assertSame(b, bFromB);
+
+      CtClass aFromChild = child.get(A_CLASS);
+      assertSame(a, aFromChild);
+
+      CtClass bFromChild = child.get(B_CLASS);
+      assertSame(b, bFromChild);
+      
+      Class<?> clazzA = a.toClass();
+      assertSame(globalA.getClassLoader(), clazzA.getClassLoader());
+      
+      Class<?> clazzB = b.toClass();
+      assertSame(globalB.getClassLoader(), clazzB.getClassLoader());
+      
+      Class<?> clazzAFromA = globalA.getClassLoader().loadClass(A_CLASS);
+      assertSame(clazzA, clazzAFromA);
+      
+      Class<?> clazzAFromB = globalB.getClassLoader().loadClass(A_CLASS);
+      assertSame(clazzA, clazzAFromB);
+      
+      Class<?> clazzAFromChild = child.getClassLoader().loadClass(A_CLASS);
+      assertSame(clazzA, clazzAFromChild);
+      
+      Class<?> clazzBFromA = globalA.getClassLoader().loadClass(B_CLASS);
+      assertSame(clazzB, clazzBFromA);
+      
+      Class<?> clazzBFromB = globalB.getClassLoader().loadClass(B_CLASS);
+      assertSame(clazzB, clazzBFromB);
+      Class<?> clazzBFromChild = child.getClassLoader().loadClass(B_CLASS);
+      assertSame(clazzB, clazzBFromChild);
+   }
+   
+
+   public void testCreateClassInSamePackage() throws Exception
+   {
+      ClassPool globalPoolA = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL));
+      ClassPool globalPoolB = testScenario.createLoader(new GlobalUCLInfo(JAR_B_1_URL));
+      
+      ClassLoader loaderA = globalPoolA.getClassLoader();
+      ClassLoader loaderB = globalPoolB.getClassLoader();
+      
+      Class<?> classA = loaderA.loadClass(CLASS_A);
+      Class<?> classB = loaderB.loadClass(CLASS_B);
+      
+      Object createdA = ClassFactory.create(classA, loaderA);
+      Object createdB = ClassFactory.create(classB, loaderB);
+      
+      Class<?> createdClassA = createdA.getClass();
+      Class<?> createdClassB = createdB.getClass();
+      
+      assertTrue(classA.isAssignableFrom(createdClassA));
+      assertTrue(classB.isAssignableFrom(createdClassB));
+      assertTrue(createdClassA.getName().startsWith(PACKAGE_A));
+      assertTrue(createdClassB.getName().startsWith(PACKAGE_B));
+      
+      assertSame(createdClassA, loaderA.loadClass(createdClassA.getName()));
+      assertSame(createdClassB, loaderA.loadClass(createdClassB.getName()));
+      assertSame(createdClassA, loaderB.loadClass(createdClassA.getName()));
+      assertSame(createdClassB, loaderB.loadClass(createdClassB.getName()));
+   }
+   
+   public void testCreatedClassForSystemClass() throws Exception
+   {
+      ClassPool globalPoolA = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL));
+      ClassPool globalPoolB = testScenario.createLoader(new GlobalUCLInfo(JAR_B_1_URL));
+      
+      ClassLoader loaderA = globalPoolA.getClassLoader();
+      ClassLoader loaderB = globalPoolB.getClassLoader();
+      
+      Object createdA = ClassFactory.create(ArrayList.class, loaderA);
+      Object createdB = ClassFactory.create(ArrayList.class, loaderB);
+      
+      Class<?> createdClassA = createdA.getClass();
+      Class<?> createdClassB = createdB.getClass();
+      
+      assertTrue(ArrayList.class.isAssignableFrom(createdClassA));
+      assertTrue(ArrayList.class.isAssignableFrom(createdClassB));
+      assertTrue(createdClassA.getName().startsWith(ClassFactory.PACKAGE));
+      assertTrue(createdClassB.getName().startsWith(ClassFactory.PACKAGE));
+      
+      assertSame(createdClassA, loaderA.loadClass(createdClassA.getName()));
+      assertSame(createdClassB, loaderA.loadClass(createdClassB.getName()));
+      assertSame(createdClassA, loaderB.loadClass(createdClassA.getName()));
+      assertSame(createdClassB, loaderB.loadClass(createdClassB.getName()));
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/CtClassCreationTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositoryClassPoolTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositoryClassPoolTestCase.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositoryClassPoolTestCase.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.classpool.ucl.test;
+
+import static org.jboss.test.classpool.ucl.support.SupportArchives.JAR_A_1_URL;
+import static org.jboss.test.classpool.ucl.support.SupportArchives.JAR_A_2_URL;
+import static org.jboss.test.classpool.ucl.support.SupportArchives.JAR_B_1_URL;
+import static org.jboss.test.classpool.ucl.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.ucl.support.SupportClasses.CLASS_B;
+
+import java.net.URL;
+
+import javassist.ClassPool;
+import javassist.CtClass;
+
+import org.jboss.test.classpool.support.ClassPoolTestScenario;
+import org.jboss.test.classpool.support.TestScenario;
+import org.jboss.test.classpool.ucl.support.GlobalUCLInfo;
+import org.jboss.test.classpool.ucl.support.ParentLastURLClassLoaderInfo;
+import org.jboss.test.classpool.ucl.support.UCLFactory;
+import org.jboss.test.classpool.ucl.support.UCLInfo;
+
+/**
+ * Executes the UCL Loader tests against a class pool test scenario.
+ * 
+ * @author <a href="mailto:flavia.rainone at jboss.org">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class RepositoryClassPoolTestCase extends RepositoryTest<CtClass, ClassPool>
+{
+   public RepositoryClassPoolTestCase(String name)
+   {
+      super(name);
+   }
+
+   @Override
+   protected TestScenario<CtClass, ClassPool, UCLInfo> getTestScenario()
+   {
+      return new ClassPoolTestScenario<UCLInfo>(new UCLFactory());
+   }
+   
+   // FIXME JBREFLECT-83
+   @Override
+   public void testUclWithParentClassLoaderAndSameClassInDomain() {}
+   
+   // FIXME JBREFLECT-83
+   @Override
+   public void testUclLoaderOrdering() {}
+   
+   // parent last class loaders only work for class pools, but not for sanity test cases
+   public void testURLChildOfGlobalUcParentLast() throws Exception
+   {
+      ClassPool globalPool = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL));
+      ClassLoader globalClassLoader = testScenario.getClassLoader(globalPool);
+      ClassPool childPoolA = createParentLastURLClassPool(JAR_B_1_URL, globalClassLoader);
+
+      //Try loading A from child first
+      CtClass aFromA = testScenario.loadClass(childPoolA, globalPool, CLASS_A);/*childPoolA.get(CLASS_A);
+      assertSame(globalPool, aFromA.getClassPool());*/
+      
+      //Try loading A from global
+      CtClass aFromGlobal = testScenario.loadClass(globalPool, CLASS_A);/*globalPool.get(CLASS_A);*/
+      assertSame(aFromA, aFromGlobal);
+      
+      //Try loading B from A
+      CtClass bFromA = childPoolA.get(CLASS_B);
+      assertSame(childPoolA, bFromA.getClassPool());
+      
+      //Should get the child copy
+      /* TODO why can't I use JAR_A1_URL instead?*/
+      ClassPool childPoolB = createParentLastURLClassPool(JAR_A_2_URL, globalClassLoader);
+      CtClass aFromB = childPoolB.get(CLASS_A);
+      assertSame(childPoolB, aFromB.getClassPool());
+   }
+
+   private ClassPool createParentLastURLClassPool(URL url, ClassLoader parent) throws Exception
+   {
+      ClassPool pool = testScenario.createLoader(new ParentLastURLClassLoaderInfo(url, parent));
+      pool.childFirstLookup = true;
+      return pool;
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositoryClassPoolTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositorySanityTestCase.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositorySanityTestCase.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositorySanityTestCase.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.classpool.ucl.test;
+
+import org.jboss.test.classpool.support.SanityTestScenario;
+import org.jboss.test.classpool.support.TestScenario;
+import org.jboss.test.classpool.ucl.support.UCLFactory;
+import org.jboss.test.classpool.ucl.support.UCLInfo;
+
+/**
+ * Executes the UCL Loader tests against a sanity test scenario (for class loader behavior
+ * sanity checking).
+ * 
+ * @author <a href="mailto:flavia.rainone at jboss.org">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public class RepositorySanityTestCase extends RepositoryTest<Class<?>, ClassLoader>
+{
+   public RepositorySanityTestCase(String name)
+   {
+      super(name);
+   }
+
+   @Override
+   protected TestScenario<Class<?>, ClassLoader, UCLInfo> getTestScenario()
+   {
+      return new SanityTestScenario<UCLInfo>(new UCLFactory());
+   }
+}


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositorySanityTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositoryTest.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositoryTest.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositoryTest.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,259 @@
+/*
+ * 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.classpool.ucl.test;
+
+import static org.jboss.test.classpool.ucl.support.SupportArchives.JAR_A_1_URL;
+import static org.jboss.test.classpool.ucl.support.SupportArchives.JAR_A_2_URL;
+import static org.jboss.test.classpool.ucl.support.SupportArchives.JAR_B_1_URL;
+import static org.jboss.test.classpool.ucl.support.SupportArchives.JAR_B_2_URL;
+import static org.jboss.test.classpool.ucl.support.SupportArchives.JAR_C_1_URL;
+import static org.jboss.test.classpool.ucl.support.SupportClasses.CLASS_A;
+import static org.jboss.test.classpool.ucl.support.SupportClasses.CLASS_B;
+import static org.jboss.test.classpool.ucl.support.SupportClasses.CLASS_C;
+
+import org.jboss.test.classpool.ucl.support.ChildUCLInfo;
+import org.jboss.test.classpool.ucl.support.GlobalUCLInfo;
+import org.jboss.test.classpool.ucl.support.UCLInfo;
+import org.jboss.test.classpool.ucl.support.URLClassLoaderInfo;
+
+/**
+ * Test that asserts UnifiedClassLoaders behaviour.
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public abstract class RepositoryTest<C, L> extends UclClassPoolTest< C, L>
+{
+   public RepositoryTest(String name)
+   {
+      super(name);
+   }
+
+   public void testGlobalScope() throws Exception
+   {
+      UCLInfo uclInfoA = new GlobalUCLInfo(JAR_A_1_URL);
+      L loaderA = testScenario.createLoader(uclInfoA);
+      UCLInfo uclInfoB = new GlobalUCLInfo(JAR_B_1_URL);
+      L loaderB = testScenario.createLoader(uclInfoB);
+      //Call twice to ensure that we hit the cache
+      accessGlobalScope(loaderA, loaderB);
+      accessGlobalScope(loaderA, loaderB);
+      
+      testScenario.destroyLoader(uclInfoB);
+      testScenario.loadClass(loaderA, CLASS_A);
+      testScenario.cannotLoadClass(loaderA, CLASS_B);
+   }
+
+   
+   public void testChildDomain() throws Exception
+   {
+      L loaderA = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL));
+      L loaderB = testScenario.createLoader(new GlobalUCLInfo(JAR_B_1_URL));
+      L loaderC = testScenario.createLoader(new ChildUCLInfo(JAR_C_1_URL, false));
+      //Call twice to ensure that we hit the cache
+      accessChildDomain(loaderA, loaderB, loaderC);
+      accessChildDomain(loaderA, loaderB, loaderC);
+   }
+
+   public void testSiblingDomains() throws Exception
+   {
+      L loaderA = testScenario.createLoader(new ChildUCLInfo(JAR_A_1_URL, true));
+      L loaderB = testScenario.createLoader(new ChildUCLInfo(JAR_B_1_URL, false));
+
+      testScenario.loadClass(loaderA, CLASS_A);
+      testScenario.loadClass(loaderB, CLASS_B);
+      testScenario.cannotLoadClass(loaderA, CLASS_B);
+      testScenario.cannotLoadClass(loaderB, CLASS_A);
+   }
+
+   public void testChildWithNewClassesInParent() throws Exception
+   {
+      L scopedLoader = testScenario.createLoader(new ChildUCLInfo(JAR_B_1_URL, true));
+      testScenario.cannotLoadClass(scopedLoader, CLASS_A);
+      L globalLoader = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL));
+      C aFromChild = testScenario.loadClass(scopedLoader, globalLoader, CLASS_A);
+      C aFromParent = testScenario.loadClass(globalLoader, CLASS_A);
+      assertSame(aFromChild, aFromParent);
+      
+      C aFromChild2 = testScenario.loadClass(scopedLoader, globalLoader, CLASS_A);
+      assertSame(aFromChild, aFromChild2);
+   }
+   
+   public void testChildOverrideWithParentDelegation() throws Exception
+   {
+      L globalLoader = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL));
+      L scopedLoader = testScenario.createLoader(new ChildUCLInfo(JAR_A_2_URL, true));
+      
+      C aFromParent = testScenario.loadClass(globalLoader, CLASS_A);
+      C aFromChild = testScenario.loadClass(scopedLoader, globalLoader, CLASS_A);
+      assertSame(aFromParent, aFromChild);
+   }
+
+   public void testChildOverrideWithNoParentDelegation() throws Exception
+   {
+      L globalLoader = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL));
+      L scopedLoader = testScenario.createLoader(new ChildUCLInfo(JAR_A_2_URL, false));
+      
+      C aFromParent = testScenario.loadClass(globalLoader, CLASS_A);
+      C aFromChild = testScenario.loadClass(scopedLoader, CLASS_A);
+      assertNotSame(aFromParent, aFromChild);
+   }
+   
+   public void testURLChildOfGlobalUclParentFirst() throws Exception
+   {
+      L globalLoader = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL));
+      ClassLoader globalClassLoader = testScenario.getClassLoader(globalLoader);
+      L childLoaderA = testScenario.createLoader(new URLClassLoaderInfo(JAR_B_1_URL, globalClassLoader));
+      
+      //Try loading A from child first
+      C aFromA = testScenario.loadClass(childLoaderA, globalLoader, CLASS_A);
+      
+      //Try loading A from global
+      C aFromGlobal = testScenario.loadClass(globalLoader, CLASS_A);
+      assertSame(aFromA, aFromGlobal);
+      
+      //Try loading B from A
+      testScenario.loadClass(childLoaderA, CLASS_B);
+      
+      L childLoaderB = testScenario.createLoader(new URLClassLoaderInfo(JAR_A_2_URL, globalClassLoader));
+      
+      //Should get the cached copy from the parent
+      C aFromB = testScenario.loadClass(childLoaderB, globalLoader, CLASS_A);
+      assertSame(aFromA, aFromB);
+   }
+
+   public void testUndeploySibling() throws Exception
+   {
+      L loaderA = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL));
+      testScenario.cannotLoadClass(loaderA, CLASS_B);
+      
+      UCLInfo uclInfoB = new GlobalUCLInfo(JAR_B_1_URL);
+      L loaderB = testScenario.createLoader(uclInfoB);
+      
+      testScenario.loadClass(loaderA, loaderB, CLASS_B);
+      testScenario.destroyLoader(uclInfoB);
+      testScenario.cannotLoadClass(loaderA, CLASS_B);
+   }
+
+   /* FIXME test doesn't work
+   public void testUndeployParentDomainClassLoader() throws Exception
+   {
+      L loaderA = testScenario.createLoader(new GlobalCLInfo(JAR_A_1_URL));
+      testScenario.cannotLoadClass(loaderA, CLASS_B);
+      
+      L childLoader = testScenario.createLoader(new ChildCLInfo(JAR_C_1_URL, true));
+      testScenario.cannotLoadClass(childLoader, CLASS_B);
+      
+      UCLInfo uclInfoB = new GlobalCLInfo(JAR_B_1_URL);
+      L loaderB = testScenario.createLoader(uclInfoB);
+      
+      C bFromChild = testScenario.loadClass(childLoader, loaderB, CLASS_B);
+      C bFromA = testScenario.loadClass(loaderA, loaderB, CLASS_B);
+      assertSame(bFromA, bFromChild);
+      
+      testScenario.destroyLoader(uclInfoB);
+      testScenario.cannotLoadClass(loaderA, CLASS_B);
+      testScenario.cannotLoadClass(childLoader, CLASS_B);
+   }*/
+   
+   public void testUclWithParentClassLoader() throws Exception
+   {
+      L parentLoader = testScenario.createLoader(new URLClassLoaderInfo(JAR_B_1_URL));
+      L globalLoader = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL,
+            testScenario.getClassLoader(parentLoader)));
+      
+      C aFromGlobal = testScenario.loadClass(globalLoader, CLASS_A);
+      C aFromGlobal2 = testScenario.loadClass(globalLoader, CLASS_A);
+      assertSame(aFromGlobal, aFromGlobal2);
+      
+      C bFromGlobal = testScenario.loadClass(globalLoader, parentLoader, CLASS_B);
+      C bFromGlobal2 = testScenario.loadClass(globalLoader, parentLoader, CLASS_B);
+      assertSame(bFromGlobal, bFromGlobal2);
+      
+      C bFromParent = testScenario.loadClass(parentLoader, CLASS_B);
+      C bFromParent2 = testScenario.loadClass(parentLoader, CLASS_B);
+      assertSame(bFromParent, bFromParent2);
+      assertSame(bFromGlobal, bFromParent);
+   }
+
+   
+   public void testUclWithParentClassLoaderAndSameClassInDomain() throws Exception
+   {
+      L parentLoader = testScenario.createLoader(new URLClassLoaderInfo(JAR_B_1_URL));
+      L globalLoaderA = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL,
+            testScenario.getClassLoader(parentLoader)));
+      
+      C aFromGlobal = testScenario.loadClass(globalLoaderA, CLASS_A);
+      C aFromGlobal2 = testScenario.loadClass(globalLoaderA, CLASS_A);
+      assertSame(aFromGlobal, aFromGlobal2);
+      
+      L globalLoaderB = testScenario.createLoader(new GlobalUCLInfo(JAR_B_2_URL));
+      C bFromGlobal = testScenario.loadClass(globalLoaderA, globalLoaderB, CLASS_B);
+      C bFromGlobal2 = testScenario.loadClass(globalLoaderA, globalLoaderB, CLASS_B);
+      assertSame(bFromGlobal, bFromGlobal2);
+      
+      C bFromParent = testScenario.loadClass(parentLoader, CLASS_B);
+      C bFromParent2 = testScenario.loadClass(parentLoader, CLASS_B);
+      assertSame(bFromParent, bFromParent2);
+      
+      assertNotSame(bFromGlobal, bFromParent);
+   }
+   
+   public void testUclLoaderOrdering() throws Exception
+   {
+      L globalLoaderA = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL));
+      L globalLoaderB = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL));
+      L globalLoaderC = testScenario.createLoader(new GlobalUCLInfo(JAR_A_1_URL));
+      
+      C aFromA = testScenario.loadClass(globalLoaderA, CLASS_A);
+      C aFromB = testScenario.loadClass(globalLoaderB, globalLoaderA, CLASS_A);
+      C aFromC = testScenario.loadClass(globalLoaderC, globalLoaderA, CLASS_A);
+      assertSame(aFromA, aFromB);
+      assertSame(aFromA, aFromC);
+   }
+
+   private void accessGlobalScope(L loaderA, L loaderB) throws Exception
+   {
+      C aFromA = testScenario.loadClass(loaderA, CLASS_A);
+      C bFromA = testScenario.loadClass(loaderA, loaderB, CLASS_B);
+      C aFromB = testScenario.loadClass(loaderB, loaderA, CLASS_A);
+      C bFromB = testScenario.loadClass(loaderB, CLASS_B);
+      assertSame(aFromA, aFromB);
+      assertSame(bFromA, bFromB);
+   }
+   
+   private void accessChildDomain(L loaderA, L loaderB, L loaderC)
+   throws Exception
+   {
+      C aFromA = testScenario.loadClass(loaderA, CLASS_A);
+      C bFromB = testScenario.loadClass(loaderB, CLASS_B);
+      C aFromC = testScenario.loadClass(loaderC, loaderA, CLASS_A);
+      C bFromC = testScenario.loadClass(loaderC, loaderB, CLASS_B);
+      assertSame(aFromA, aFromC);
+      assertSame(bFromB, bFromC);
+
+      testScenario.loadClass(loaderC, CLASS_C);
+      testScenario.cannotLoadClass(loaderA, CLASS_C);
+      testScenario.cannotLoadClass(loaderB, CLASS_C);
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/RepositoryTest.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTest.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTest.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTest.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,124 @@
+/*
+ * 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.classpool.ucl.test;
+
+import java.io.File;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+
+import org.jboss.classpool.plugins.ucl.UclDelegatingClassPoolFactory;
+import org.jboss.classpool.spi.ClassPoolRepository;
+import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.test.AbstractTestCaseWithSetup;
+import org.jboss.test.AbstractTestDelegate;
+import org.jboss.test.classpool.support.TestScenario;
+import org.jboss.test.classpool.ucl.support.SupportClasses;
+import org.jboss.test.classpool.ucl.support.UCLInfo;
+
+/**
+ * Super class of UCL tests.
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @author <a href="flavia.rainone at jboss.com">Flavia Rainone</a>
+ * @version $Revision$
+ */
+public abstract class UclClassPoolTest<C, L> extends AbstractTestCaseWithSetup
+{
+   static
+   {
+      try
+      {
+         ClassPoolRepository.getInstance().setClassPoolFactory(
+               new UclDelegatingClassPoolFactory(new File(".")));
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+   
+   protected TestScenario<C, L, UCLInfo> testScenario; 
+   
+   protected abstract TestScenario<C, L, UCLInfo> getTestScenario();
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      //enableTrace("org.jboss.classpool.ucl");
+      super.setUp();
+      this.testScenario = getTestScenario();
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      try
+      {
+         this.testScenario.destroyLoaders();
+      }
+      finally
+      {
+         super.tearDown();
+      }
+   }
+   
+
+   public UclClassPoolTest(String name)
+   {
+      super(name);
+      System.setProperty("javax.management.builder.initial", "org.jboss.mx.server.MBeanServerBuilderImpl");
+      MBeanServer server = MBeanServerFactory.createMBeanServer();
+      MBeanServerLocator.setJBoss(server);
+   }
+
+   public static AbstractTestDelegate getDelegate(Class<?> clazz) throws Exception
+   {
+      AbstractTestDelegate delegate = new UclClassPoolTestDelegate(clazz);
+      String property = "false"; //System.getProperty("jboss.aop.secure", "false"); // TODO this value was true
+      boolean enableSecurity = Boolean.valueOf(property).booleanValue();
+      delegate.enableSecurity = enableSecurity;
+      return delegate;
+   }
+
+   /**
+    * The test classes should not be on the launcher classpath
+    */
+   public void testClassesNotOnClasspath()
+   {
+      assertCannotLoadClass(this.getClass().getClassLoader(), SupportClasses.CLASS_A);
+      assertCannotLoadClass(this.getClass().getClassLoader(), SupportClasses.CLASS_B);
+      assertCannotLoadClass(this.getClass().getClassLoader(), SupportClasses.CLASS_C);
+   }
+   
+   private void assertCannotLoadClass(ClassLoader cl, String className)
+   {
+      try
+      {
+         cl.loadClass(className);
+         fail("Should not have been able to load " + className);
+      }
+      catch(Exception expected)
+      {
+      }
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTest.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTestDelegate.java
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTestDelegate.java	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTestDelegate.java	2009-12-11 13:53:12 UTC (rev 97737)
@@ -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.classpool.ucl.test;
+
+import org.jboss.test.AbstractTestDelegate;
+
+/**
+ * Delegate of UclClassPoolTest.
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision$
+ */
+public class UclClassPoolTestDelegate extends AbstractTestDelegate
+{
+   public UclClassPoolTestDelegate(Class<?> clazz)
+   {
+      super(clazz);
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/java/org/jboss/test/classpool/ucl/test/UclClassPoolTestDelegate.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/jboss-classpool/trunk/ucl/src/test/resources/log4j.xml
===================================================================
--- projects/jboss-classpool/trunk/ucl/src/test/resources/log4j.xml	                        (rev 0)
+++ projects/jboss-classpool/trunk/ucl/src/test/resources/log4j.xml	2009-12-11 13:53:12 UTC (rev 97737)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+        
+  <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
+    <layout class="org.apache.log4j.SimpleLayout"/>
+  </appender>
+
+  <root>
+    <priority value ="debug" />
+    <appender-ref ref="ConsoleAppender"/>
+  </root>
+
+</log4j:configuration> 


Property changes on: projects/jboss-classpool/trunk/ucl/src/test/resources/log4j.xml
___________________________________________________________________
Name: svn:executable
   + *




More information about the jboss-cvs-commits mailing list