[jboss-cvs] JBossAS SVN: r83485 - in projects/jboss-cl/tags: 2.0.2.GA and 11 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jan 27 08:22:11 EST 2009


Author: alesj
Date: 2009-01-27 08:22:11 -0500 (Tue, 27 Jan 2009)
New Revision: 83485

Added:
   projects/jboss-cl/tags/2.0.2.GA/
   projects/jboss-cl/tags/2.0.2.GA/build/pom.xml
   projects/jboss-cl/tags/2.0.2.GA/classloader/pom.xml
   projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/plugins/loader/ClassLoaderToLoaderAdapter.java
   projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java
   projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderSource.java
   projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/pom.xml
   projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java
   projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/metadata/test/GeneratedClassesUnitTestCase.java
   projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/src/test/resources/classes/
   projects/jboss-cl/tags/2.0.2.GA/classloading/pom.xml
   projects/jboss-cl/tags/2.0.2.GA/classloading/src/main/java/org/jboss/classloading/spi/dependency/ClassLoadingSpace.java
   projects/jboss-cl/tags/2.0.2.GA/classloading/src/main/java/org/jboss/classloading/spi/dependency/Module.java
   projects/jboss-cl/tags/2.0.2.GA/classloading/src/test/java/org/jboss/test/classloading/dependency/test/ModuleClassLoadingUnitTestCase.java
   projects/jboss-cl/tags/2.0.2.GA/pom.xml
Removed:
   projects/jboss-cl/tags/2.0.2.GA/build/pom.xml
   projects/jboss-cl/tags/2.0.2.GA/classloader/pom.xml
   projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/plugins/loader/ClassLoaderToLoaderAdapter.java
   projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java
   projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderSource.java
   projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/pom.xml
   projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java
   projects/jboss-cl/tags/2.0.2.GA/classloading/pom.xml
   projects/jboss-cl/tags/2.0.2.GA/classloading/src/main/java/org/jboss/classloading/spi/dependency/ClassLoadingSpace.java
   projects/jboss-cl/tags/2.0.2.GA/classloading/src/main/java/org/jboss/classloading/spi/dependency/Module.java
   projects/jboss-cl/tags/2.0.2.GA/classloading/src/test/java/org/jboss/test/classloading/dependency/test/ModuleClassLoadingUnitTestCase.java
   projects/jboss-cl/tags/2.0.2.GA/pom.xml
Log:
[maven-release-plugin]  copy for tag 2.0.2.GA

Copied: projects/jboss-cl/tags/2.0.2.GA (from rev 83468, projects/jboss-cl/branches/Branch_2_0)

Deleted: projects/jboss-cl/tags/2.0.2.GA/build/pom.xml
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/build/pom.xml	2009-01-27 11:39:59 UTC (rev 83468)
+++ projects/jboss-cl/tags/2.0.2.GA/build/pom.xml	2009-01-27 13:22:11 UTC (rev 83485)
@@ -1,58 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <parent>
-    <groupId>org.jboss.cl</groupId>
-    <artifactId>jboss-cl</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>org.jboss.cl</groupId>
-  <artifactId>jboss-cl-dist</artifactId>
-  <version>2.0.2-SNAPSHOT</version>
-  <packaging>pom</packaging>
-  <name>JBoss ClassLoader Distribution Build</name>
-  <url>http://www.jboss.org/jbossmc</url>
-  <description>JBoss ClassLoader Distribution Build</description>
-
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-assembly-plugin</artifactId>
-        <version>2.2-beta-2</version>
-        <executions>
-          <execution>
-            <id>make-assembly</id>
-            <phase>package</phase>
-            <goals>
-              <goal>attached</goal>
-            </goals>
-            <configuration>
-              <finalName>jboss-cl-${project.version}</finalName>
-              <descriptors>
-                <descriptor>src/assembly/dist.xml</descriptor>
-                <descriptor>src/assembly/dist-with-deps.xml</descriptor>
-                <descriptor>src/assembly/src.xml</descriptor>
-              </descriptors>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-  
-  <dependencies>
-      <dependency>
-        <groupId>org.jboss.cl</groupId>
-        <artifactId>jboss-classloader</artifactId>
-      </dependency>
-      <dependency>
-        <groupId>org.jboss.cl</groupId>
-        <artifactId>jboss-classloading</artifactId>
-      </dependency>
-      <dependency>
-        <groupId>org.jboss.cl</groupId>
-        <artifactId>jboss-classloading-vfs</artifactId>
-      </dependency>
-  </dependencies>
-  
-</project>
\ No newline at end of file

Copied: projects/jboss-cl/tags/2.0.2.GA/build/pom.xml (from rev 83484, projects/jboss-cl/branches/Branch_2_0/build/pom.xml)
===================================================================
--- projects/jboss-cl/tags/2.0.2.GA/build/pom.xml	                        (rev 0)
+++ projects/jboss-cl/tags/2.0.2.GA/build/pom.xml	2009-01-27 13:22:11 UTC (rev 83485)
@@ -0,0 +1,58 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.jboss.cl</groupId>
+    <artifactId>jboss-cl</artifactId>
+    <version>2.0.2.GA</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.jboss.cl</groupId>
+  <artifactId>jboss-cl-dist</artifactId>
+  <version>2.0.2.GA</version>
+  <packaging>pom</packaging>
+  <name>JBoss ClassLoader Distribution Build</name>
+  <url>http://www.jboss.org/jbossmc</url>
+  <description>JBoss ClassLoader Distribution Build</description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-assembly-plugin</artifactId>
+        <version>2.2-beta-2</version>
+        <executions>
+          <execution>
+            <id>make-assembly</id>
+            <phase>package</phase>
+            <goals>
+              <goal>attached</goal>
+            </goals>
+            <configuration>
+              <finalName>jboss-cl-${project.version}</finalName>
+              <descriptors>
+                <descriptor>src/assembly/dist.xml</descriptor>
+                <descriptor>src/assembly/dist-with-deps.xml</descriptor>
+                <descriptor>src/assembly/src.xml</descriptor>
+              </descriptors>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  
+  <dependencies>
+      <dependency>
+        <groupId>org.jboss.cl</groupId>
+        <artifactId>jboss-classloader</artifactId>
+      </dependency>
+      <dependency>
+        <groupId>org.jboss.cl</groupId>
+        <artifactId>jboss-classloading</artifactId>
+      </dependency>
+      <dependency>
+        <groupId>org.jboss.cl</groupId>
+        <artifactId>jboss-classloading-vfs</artifactId>
+      </dependency>
+  </dependencies>
+  
+</project>
\ No newline at end of file

Deleted: projects/jboss-cl/tags/2.0.2.GA/classloader/pom.xml
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloader/pom.xml	2009-01-27 11:39:59 UTC (rev 83468)
+++ projects/jboss-cl/tags/2.0.2.GA/classloader/pom.xml	2009-01-27 13:22:11 UTC (rev 83485)
@@ -1,87 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <parent>
-    <groupId>org.jboss.cl</groupId>
-    <artifactId>jboss-cl</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-  <artifactId>jboss-classloader</artifactId>
-  <packaging>jar</packaging>
-  <name>JBoss ClassLoader</name>
-  <url>http://www.jboss.org/jbossmc</url>
-  <description>JBoss ClassLoader</description>
-
-  <!-- Do not add version information here, use ../pom.xml instead -->
-  <dependencyManagement>
-    <dependencies>
-      <dependency>
-        <groupId>org.jboss.test</groupId>
-        <artifactId>jboss-test</artifactId>
-        <version>${version.org.jboss.test}</version>
-        <scope>compile</scope>
-      </dependency>
-      <dependency>
-        <groupId>junit</groupId>
-        <artifactId>junit</artifactId>
-        <version>${version.junit}</version>
-        <scope>compile</scope>
-      </dependency>
-    </dependencies>
-  </dependencyManagement>
-  
-  <dependencies>
-    <!-- Global dependencies -->
-    <dependency>
-      <groupId>org.jboss.integration</groupId>
-      <artifactId>jboss-classloading-spi</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-common-core</artifactId>
-        </exclusion>
-      </exclusions>
-     </dependency>
-     
-    <dependency>
-      <groupId>org.jboss.logging</groupId>
-      <artifactId>jboss-logging-spi</artifactId>
-     </dependency>
-     
-    <dependency>
-      <groupId>org.jboss</groupId>
-      <artifactId>jboss-common-core</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>jboss</groupId>
-          <artifactId>jboss-common-logging-spi</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>apache-httpclient</groupId>
-          <artifactId>commons-httpclient</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>apache-slide</groupId>
-          <artifactId>webdavlib</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>apache-xerces</groupId>
-          <artifactId>xml-apis</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    
-    <!-- Test dependencies -->
-    <dependency>
-      <groupId>org.jboss.test</groupId>
-      <artifactId>jboss-test</artifactId>
-      <optional>true</optional>
-    </dependency>
-    
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <optional>true</optional>
-    </dependency>
-    
-  </dependencies>  
-</project>
\ No newline at end of file

Copied: projects/jboss-cl/tags/2.0.2.GA/classloader/pom.xml (from rev 83484, projects/jboss-cl/branches/Branch_2_0/classloader/pom.xml)
===================================================================
--- projects/jboss-cl/tags/2.0.2.GA/classloader/pom.xml	                        (rev 0)
+++ projects/jboss-cl/tags/2.0.2.GA/classloader/pom.xml	2009-01-27 13:22:11 UTC (rev 83485)
@@ -0,0 +1,87 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.jboss.cl</groupId>
+    <artifactId>jboss-cl</artifactId>
+    <version>2.0.2.GA</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>jboss-classloader</artifactId>
+  <packaging>jar</packaging>
+  <name>JBoss ClassLoader</name>
+  <url>http://www.jboss.org/jbossmc</url>
+  <description>JBoss ClassLoader</description>
+
+  <!-- Do not add version information here, use ../pom.xml instead -->
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.jboss.test</groupId>
+        <artifactId>jboss-test</artifactId>
+        <version>${version.org.jboss.test}</version>
+        <scope>compile</scope>
+      </dependency>
+      <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>${version.junit}</version>
+        <scope>compile</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+  
+  <dependencies>
+    <!-- Global dependencies -->
+    <dependency>
+      <groupId>org.jboss.integration</groupId>
+      <artifactId>jboss-classloading-spi</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-common-core</artifactId>
+        </exclusion>
+      </exclusions>
+     </dependency>
+     
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-spi</artifactId>
+     </dependency>
+     
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-common-core</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>jboss</groupId>
+          <artifactId>jboss-common-logging-spi</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>apache-httpclient</groupId>
+          <artifactId>commons-httpclient</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>apache-slide</groupId>
+          <artifactId>webdavlib</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>apache-xerces</groupId>
+          <artifactId>xml-apis</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <!-- Test dependencies -->
+    <dependency>
+      <groupId>org.jboss.test</groupId>
+      <artifactId>jboss-test</artifactId>
+      <optional>true</optional>
+    </dependency>
+    
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <optional>true</optional>
+    </dependency>
+    
+  </dependencies>  
+</project>
\ No newline at end of file

Deleted: projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/plugins/loader/ClassLoaderToLoaderAdapter.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/plugins/loader/ClassLoaderToLoaderAdapter.java	2009-01-27 11:39:59 UTC (rev 83468)
+++ projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/plugins/loader/ClassLoaderToLoaderAdapter.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -1,218 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2007, 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.classloader.plugins.loader;
-
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.Enumeration;
-import java.util.Set;
-
-import org.jboss.classloader.spi.Loader;
-import org.jboss.classloader.spi.base.BaseClassLoaderSource;
-import org.jboss.logging.Logger;
-
-/**
- * ClassLoaderToLoaderAdapter.
- * 
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class ClassLoaderToLoaderAdapter extends BaseClassLoaderSource implements Loader
-{
-   /** The log */
-   private static final Logger log = Logger.getLogger(ClassLoaderToLoaderAdapter.class);
-   
-   /** The access control context of the creator of this adapter */
-   private AccessControlContext accessControlContext;
-   
-   /** The get package method */
-   private static Method getPackage;
-   
-   /** The get packages method */
-   private static Method getPackages;
-   
-   static
-   {
-      AccessController.doPrivileged(new PrivilegedAction<Object>()
-      {
-         public Object run()
-         {
-            try
-            {
-               getPackage = ClassLoader.class.getDeclaredMethod("getPackage", String.class);
-               getPackage.setAccessible(true);
-            }
-            catch (Exception e)
-            {
-               log.warn("Unable to set accessible on ClassLoader.getPackage()", e);
-            }
-            try
-            {
-               getPackages = ClassLoader.class.getDeclaredMethod("getPackages");
-               getPackages.setAccessible(true);
-            }
-            catch (Exception e)
-            {
-               log.warn("Unable to set accessible on ClassLoader.getPackages()", e);
-            }
-            return null;
-         }
-      });
-   }
-   
-   /**
-    * Create a new ClassLoaderToLoaderAdapter.
-    * 
-    * @param classLoader the classloader
-    */
-   public ClassLoaderToLoaderAdapter(ClassLoader classLoader)
-   {
-      super(classLoader);
-      accessControlContext = AccessController.getContext();
-   }
-
-   public URL getResource(final String name)
-   {
-      final ClassLoader classLoader = getClassLoader();
-      URL url;
-      SecurityManager sm = System.getSecurityManager();
-      if (sm != null)
-      {
-         url = AccessController.doPrivileged(new PrivilegedAction<URL>()
-         {
-            public URL run()
-            {
-               return classLoader.getResource(name);
-            }
-         }, accessControlContext);
-         
-      }
-      else
-      {
-         url = classLoader.getResource(name);
-      }
-      
-      if (log.isTraceEnabled())
-      {
-         if (url != null)
-            log.trace("Resource " + name + " found in " + classLoader);
-         else
-            log.trace("Resource " + name + " NOT found in " + classLoader);
-      }
-      return url;
-   }
-
-   public void getResources(final String name, Set<URL> urls) throws IOException
-   {
-      final ClassLoader classLoader = getClassLoader();
-      Enumeration<URL> enumeration;
-      SecurityManager sm = System.getSecurityManager();
-      if (sm != null)
-      {
-         try
-         {
-            enumeration = AccessController.doPrivileged(new PrivilegedExceptionAction<Enumeration<URL>>()
-            {
-               public Enumeration<URL> run() throws Exception
-               {
-                  return classLoader.getResources(name);
-               }
-            }, accessControlContext);
-         }
-         catch (PrivilegedActionException e)
-         {
-            Exception e1 = e.getException();
-            if (e1 instanceof RuntimeException)
-               throw (RuntimeException) e1;
-            if (e1 instanceof IOException)
-               throw (IOException) e1;
-            IOException e2 = new IOException("Unexpected error");
-            e2.initCause(e1);
-            throw e2;
-         }
-      }
-      else
-      {
-         enumeration = classLoader.getResources(name);
-      }
-      while (enumeration.hasMoreElements())
-         urls.add(enumeration.nextElement());
-   }
-
-   public Class<?> loadClass(String className)
-   {
-      final ClassLoader classLoader = getClassLoader();
-      try
-      {
-         return Class.forName(className, false, classLoader);
-      }
-      catch (ClassNotFoundException e)
-      {
-         return null;
-      }
-   }
-
-   public Package getPackage(String name)
-   {
-      final ClassLoader classLoader = getClassLoader();
-      if  (getPackage == null)
-         return null;
-
-      try
-      {
-         return (Package) getPackage.invoke(classLoader, new Object[] { name });
-      }
-      catch (Exception e)
-      {
-         log.warn("Unexpected error retrieving package " + name + " from classloader " + classLoader, e);
-         return null;
-      }
-   }
-
-   public void getPackages(Set<Package> packages)
-   {
-      final ClassLoader classLoader = getClassLoader();
-      if  (getPackages == null)
-         return;
-
-      try
-      {
-         getPackages.invoke(classLoader);
-      }
-      catch (Exception e)
-      {
-         log.warn("Unexpected error retrieving packages from classloader " + classLoader, e);
-      }
-   }
-
-   @Override
-   public String toString()
-   {
-      return getClassLoader().toString();
-   }
-}

Copied: projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/plugins/loader/ClassLoaderToLoaderAdapter.java (from rev 83469, projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/plugins/loader/ClassLoaderToLoaderAdapter.java)
===================================================================
--- projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/plugins/loader/ClassLoaderToLoaderAdapter.java	                        (rev 0)
+++ projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/plugins/loader/ClassLoaderToLoaderAdapter.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -0,0 +1,218 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.classloader.plugins.loader;
+
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.Enumeration;
+import java.util.Set;
+
+import org.jboss.classloader.spi.Loader;
+import org.jboss.classloader.spi.base.BaseClassLoaderSource;
+import org.jboss.logging.Logger;
+
+/**
+ * ClassLoaderToLoaderAdapter.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoaderToLoaderAdapter extends BaseClassLoaderSource implements Loader
+{
+   /** The log */
+   private static final Logger log = Logger.getLogger(ClassLoaderToLoaderAdapter.class);
+   
+   /** The access control context of the creator of this adapter */
+   private AccessControlContext accessControlContext;
+   
+   /** The get package method */
+   private static Method getPackage;
+   
+   /** The get packages method */
+   private static Method getPackages;
+   
+   static
+   {
+      AccessController.doPrivileged(new PrivilegedAction<Object>()
+      {
+         public Object run()
+         {
+            try
+            {
+               getPackage = ClassLoader.class.getDeclaredMethod("getPackage", String.class);
+               getPackage.setAccessible(true);
+            }
+            catch (Exception e)
+            {
+               log.warn("Unable to set accessible on ClassLoader.getPackage()", e);
+            }
+            try
+            {
+               getPackages = ClassLoader.class.getDeclaredMethod("getPackages");
+               getPackages.setAccessible(true);
+            }
+            catch (Exception e)
+            {
+               log.warn("Unable to set accessible on ClassLoader.getPackages()", e);
+            }
+            return null;
+         }
+      });
+   }
+   
+   /**
+    * Create a new ClassLoaderToLoaderAdapter.
+    * 
+    * @param classLoader the classloader
+    */
+   public ClassLoaderToLoaderAdapter(ClassLoader classLoader)
+   {
+      super(classLoader);
+      accessControlContext = AccessController.getContext();
+   }
+
+   public URL getResource(final String name)
+   {
+      final ClassLoader classLoader = getClassLoader();
+      URL url;
+      SecurityManager sm = System.getSecurityManager();
+      if (sm != null)
+      {
+         url = AccessController.doPrivileged(new PrivilegedAction<URL>()
+         {
+            public URL run()
+            {
+               return classLoader.getResource(name);
+            }
+         }, accessControlContext);
+         
+      }
+      else
+      {
+         url = classLoader.getResource(name);
+      }
+      
+      if (log.isTraceEnabled())
+      {
+         if (url != null)
+            log.trace("Resource " + name + " found in " + classLoader);
+         else
+            log.trace("Resource " + name + " NOT found in " + classLoader);
+      }
+      return url;
+   }
+
+   public void getResources(final String name, Set<URL> urls) throws IOException
+   {
+      final ClassLoader classLoader = getClassLoader();
+      Enumeration<URL> enumeration;
+      SecurityManager sm = System.getSecurityManager();
+      if (sm != null)
+      {
+         try
+         {
+            enumeration = AccessController.doPrivileged(new PrivilegedExceptionAction<Enumeration<URL>>()
+            {
+               public Enumeration<URL> run() throws Exception
+               {
+                  return classLoader.getResources(name);
+               }
+            }, accessControlContext);
+         }
+         catch (PrivilegedActionException e)
+         {
+            Exception e1 = e.getException();
+            if (e1 instanceof RuntimeException)
+               throw (RuntimeException) e1;
+            if (e1 instanceof IOException)
+               throw (IOException) e1;
+            IOException e2 = new IOException("Unexpected error");
+            e2.initCause(e1);
+            throw e2;
+         }
+      }
+      else
+      {
+         enumeration = classLoader.getResources(name);
+      }
+      while (enumeration.hasMoreElements())
+         urls.add(enumeration.nextElement());
+   }
+
+   public Class<?> loadClass(String className)
+   {
+      final ClassLoader classLoader = getClassLoader();
+      try
+      {
+         return Class.forName(className, false, classLoader);
+      }
+      catch (ClassNotFoundException e)
+      {
+         return null;
+      }
+   }
+
+   public Package getPackage(String name)
+   {
+      final ClassLoader classLoader = getClassLoader();
+      if (getPackage == null)
+         return null;
+
+      try
+      {
+         return (Package) getPackage.invoke(classLoader, name);
+      }
+      catch (Exception e)
+      {
+         log.warn("Unexpected error retrieving package " + name + " from classloader " + classLoader, e);
+         return null;
+      }
+   }
+
+   public void getPackages(Set<Package> packages)
+   {
+      final ClassLoader classLoader = getClassLoader();
+      if (getPackages == null)
+         return;
+
+      try
+      {
+         getPackages.invoke(classLoader);
+      }
+      catch (Exception e)
+      {
+         log.warn("Unexpected error retrieving packages from classloader " + classLoader, e);
+      }
+   }
+
+   @Override
+   public String toString()
+   {
+      return getClassLoader().toString();
+   }
+}

Deleted: projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java	2009-01-27 11:39:59 UTC (rev 83468)
+++ projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -1,1435 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2007, 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.classloader.spi.base;
-
-import java.io.IOException;
-import java.net.URL;
-import java.security.ProtectionDomain;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.jboss.classloader.plugins.ClassLoaderUtils;
-import org.jboss.classloader.spi.ClassLoaderPolicy;
-import org.jboss.classloader.spi.DelegateLoader;
-import org.jboss.classloader.spi.Loader;
-import org.jboss.logging.Logger;
-
-/**
- * BaseClassLoaderDomain.<p>
- * 
- * This class hides some of the implementation details and allows
- * package access to the protected methods.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public abstract class BaseClassLoaderDomain implements Loader
-{
-   /** The log */
-   private static final Logger log = Logger.getLogger(BaseClassLoaderDomain.class);
-
-   /** The classloader system to which we belong */
-   private BaseClassLoaderSystem system;
-   
-   /** The classloaders  in the order they were registered */
-   private List<ClassLoaderInformation> classLoaders = new CopyOnWriteArrayList<ClassLoaderInformation>();
-
-   /** The classloader information by classloader */
-   private Map<ClassLoader, ClassLoaderInformation> infos = new ConcurrentHashMap<ClassLoader, ClassLoaderInformation>();
-   
-   /** The classloaders by package name */
-   private Map<String, List<ClassLoaderInformation>> classLoadersByPackageName = new ConcurrentHashMap<String, List<ClassLoaderInformation>>();
-   
-   /** The global class cache */
-   private Map<String, Loader> globalClassCache = new ConcurrentHashMap<String, Loader>();
-   
-   /** The global class black list */
-   private Map<String, String> globalClassBlackList = new ConcurrentHashMap<String, String>();
-   
-   /** The global resource cache */
-   private Map<String, URL> globalResourceCache = new ConcurrentHashMap<String, URL>();
-   
-   /** The global resource black list */
-   private Map<String, String> globalResourceBlackList = new ConcurrentHashMap<String, String>();
-   
-   /** Keep track of the added order */
-   private int order = 0;
-   
-   /**
-    * Flush the internal caches
-    */
-   public void flushCaches()
-   {
-      globalClassCache.clear();
-      globalClassBlackList.clear();
-      globalResourceCache.clear();
-      globalResourceBlackList.clear();
-   }
-
-   public int getClassBlackListSize()
-   {
-      return globalClassBlackList.size();
-   }
-
-   public int getClassCacheSize()
-   {
-      return globalClassCache.size();
-   }
-
-   public int getResourceBlackListSize()
-   {
-      return globalClassBlackList.size();
-   }
-
-   public int getResourceCacheSize()
-   {
-      return globalClassCache.size();
-   }
-   
-   public Set<String> listClassBlackList()
-   {
-      return Collections.unmodifiableSet(globalClassBlackList.keySet());
-   }
-
-   public Map<String, String> listClassCache()
-   {
-      Map<String, String> result = new HashMap<String, String>(globalClassCache.size());
-      for (Map.Entry<String, Loader> entry : globalClassCache.entrySet())
-         result.put(entry.getKey(), entry.getValue().toString());
-      return result;
-   }
-
-   public Set<String> listResourceBlackList()
-   {
-      return Collections.unmodifiableSet(globalResourceBlackList.keySet());
-   }
-
-   public Map<String, URL> listResourceCache()
-   {
-      return Collections.unmodifiableMap(globalResourceCache);
-   }
-
-   /**
-    * Get the classloader system
-    * 
-    * @return the classloader system
-    */
-   protected synchronized BaseClassLoaderSystem getClassLoaderSystem()
-   {
-      return system;
-   }
-   
-   /**
-    * Get the classloader system
-    * 
-    * @param system the classloader system
-    */
-   synchronized void setClassLoaderSystem(BaseClassLoaderSystem system)
-   {
-      if (system == null)
-         shutdownDomain();
-      this.system = system;
-   }
-
-   /**
-    * Shutdown the domain<p>
-    * 
-    * The default implementation just unregisters all classloaders
-    */
-   protected void shutdownDomain()
-   {
-      log.debug(toString() + " shutdown!");
-
-      // Unregister all classloaders
-      while (true)
-      {
-         Iterator<ClassLoaderInformation> iterator = classLoaders.iterator();
-         if (iterator.hasNext() == false)
-            break;
-
-         while (iterator.hasNext())
-         {
-            ClassLoaderInformation info = iterator.next();
-            if (info != null)
-               unregisterClassLoader(info.getClassLoader());
-         }
-      }
-      
-      flushCaches();
-   }
-   
-   /**
-    * Whether the domain has classloaders
-    * 
-    * @return true when the domain has classloaders
-    */
-   public boolean hasClassLoaders()
-   {
-      return classLoaders.isEmpty() == false;
-   }
-   
-   /**
-    * Whether to use load class for parent
-    * 
-    * @return true to load class on the parent loader
-    */
-   public abstract boolean isUseLoadClassForParent();
-   
-   /**
-    * Transform the byte code<p>
-    * 
-    * By default, this delegates to the classloader system
-    * 
-    * @param classLoader the classloader
-    * @param className the class name
-    * @param byteCode the byte code
-    * @param protectionDomain the protection domain
-    * @return the transformed byte code
-    * @throws Exception for any error
-    */
-   protected byte[] transform(ClassLoader classLoader, String className, byte[] byteCode, ProtectionDomain protectionDomain) throws Exception
-   {
-      BaseClassLoaderSystem system = getClassLoaderSystem();
-      if (system != null)
-         return system.transform(classLoader, className, byteCode, protectionDomain);
-      return byteCode;
-   }
-
-   /**
-    * Load a class from the domain
-    * 
-    * @param classLoader the classloader
-    * @param name the class name
-    * @param allExports whether we should look at all exports
-    * @return the class
-    * @throws ClassNotFoundException for any error
-    */
-   protected Class<?> loadClass(BaseClassLoader classLoader, String name, boolean allExports) throws ClassNotFoundException
-   {
-      boolean trace = log.isTraceEnabled();
-
-      boolean findInParent = (isUseLoadClassForParent() == false);
-      
-      // Should we directly load from the parent?
-      if (findInParent == false)
-      {
-         Class<?> clazz = loadClassBefore(name);
-         if (clazz != null)
-            return clazz;
-      }
-      
-      String path = ClassLoaderUtils.classNameToPath(name);
-      
-      Loader loader = findLoader(classLoader, path, allExports, findInParent);
-      if (loader != null)
-      {
-         Thread thread = Thread.currentThread();
-         ClassLoadingTask task = new ClassLoadingTask(name, classLoader, thread);
-         ClassLoaderManager.scheduleTask(task, loader, false);
-         return ClassLoaderManager.process(thread, task);
-      }
-      
-      // Should we directly load from the parent?
-      if (findInParent == false)
-      {
-         Class<?> clazz = loadClassAfter(name);
-         if (clazz != null)
-            return clazz;
-      }
-
-      // Finally see whether this is the JDK assuming it can load its classes from any classloader
-      if (classLoader != null)
-      {
-         BaseClassLoaderPolicy policy = classLoader.getPolicy();
-         ClassLoader hack = policy.isJDKRequest(name);
-         if (hack != null)
-         {
-            if (trace)
-               log.trace(this + " trying to load " + name + " using hack " + hack);
-            Class<?> result = Class.forName(name, false, hack);
-            if (result != null)
-            {
-               if (trace)
-                  log.trace(this + " loaded from hack " + hack + " " + ClassLoaderUtils.classToString(result));
-               return result;
-            }
-         }
-      }
-      
-      // Didn't find it
-      return null;
-   }
-
-   /**
-    * Find a loader for a class
-    * 
-    * @param name the class resource name
-    * @return the loader
-    */
-   protected Loader findLoader(String name)
-   {
-      return findLoader(null, name, true, true);
-   }
-
-   /**
-    * Find a loader for a class
-    * 
-    * @param classLoader the classloader
-    * @param name the class resource name
-    * @param allExports whether we should look at all exports
-    * @return the loader
-    */
-   Loader findLoader(BaseClassLoader classLoader, String name, boolean allExports, boolean findInParent)
-   {
-      boolean trace = log.isTraceEnabled();
-      if (trace)
-         log.trace(this + " findLoader " + name + " classLoader=" + classLoader + " allExports=" + allExports + " findInParent=" + findInParent);
-      
-      if (getClassLoaderSystem() == null)
-         throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
-      
-      // Try the before attempt (e.g. from the parent)
-      Loader loader = null;
-      if (findInParent)
-         loader = findBeforeLoader(name);
-      if (loader != null)
-         return loader;
-
-      // Work out the rules
-      ClassLoaderInformation info = null;
-      BaseClassLoaderPolicy policy;
-      if (classLoader != null)
-      {
-         info = infos.get(classLoader);
-         policy = classLoader.getPolicy();
-         if (policy.isImportAll())
-            allExports = true;
-      }
-
-      // Next we try the old "big ball of mud" model      
-      if (allExports)
-      {
-         loader = findLoaderInExports(classLoader, name, trace);
-         if (loader != null)
-            return loader;
-      }
-      else if (trace)
-         log.trace(this + " not loading " + name + " from all exports");
-      
-      // Next we try the imports
-      if (info != null)
-      {
-         loader = findLoaderInImports(info, name, trace);
-         if (loader != null)
-            return loader;
-      }
-
-      // Next use any requesting classloader, this will look at everything not just what it exports
-      if (classLoader != null)
-      {
-         if (trace)
-            log.trace(this + " trying to load " + name + " from requesting " + classLoader);
-         if (classLoader.getResourceLocally(name) != null)
-            return classLoader.getLoader();
-      }
-
-      // Try the after attempt (e.g. from the parent)
-      if (findInParent)
-         return findAfterLoader(name);
-      
-      return null;
-   }
-   
-   /**
-    * Load a resource from the domain
-    * 
-    * @param classLoader the classloader
-    * @param name the resource name
-    * @param allExports whether we should look at all exports
-    * @return the url
-    */
-   URL getResource(BaseClassLoader classLoader, String name, boolean allExports)
-   {
-      boolean trace = log.isTraceEnabled();
-
-      // Try the classloader first
-      if (classLoader != null)
-      {
-         if (trace)
-            log.trace(this + " trying to get resource " + name + " from requesting " + classLoader);
-         URL result = classLoader.getResourceLocally(name);
-         if (result != null)
-         {
-            if (trace)
-               log.trace(this + " got resource from requesting " + classLoader + " " + result);
-            return result;
-         }
-      }
-
-      if (getClassLoaderSystem() == null)
-         throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
-
-      // Try the before attempt
-      URL result = beforeGetResource(name);
-      if (result != null)
-         return result;
-
-      // Work out the rules
-      ClassLoaderInformation info = null;
-      BaseClassLoaderPolicy policy;
-      if (classLoader != null)
-      {
-         policy = classLoader.getPolicy();
-         info = infos.get(classLoader);
-         if (policy.isImportAll())
-            allExports = true;
-      }
-
-      // Next we try the old "big ball of mud" model      
-      if (allExports)
-      {
-         result = getResourceFromExports(classLoader, name, trace);
-         if (result != null)
-            return result;
-      }
-      else if (trace)
-         log.trace(this + " not getting resource " + name + " from all exports");
-      
-      // Next we try the imports
-      if (info != null)
-      {
-         result = getResourceFromImports(info, name, trace);
-         if (result != null)
-            return result;
-      }
-
-      // Try the after attempt
-      result = afterGetResource(name);
-      if (result != null)
-         return result;
-      
-      // Didn't find it
-      return null;
-   }
-   
-   /**
-    * Load resources from the domain
-    * 
-    * @param classLoader the classloader
-    * @param name the resource name
-    * @param allExports whether we should look at all exports
-    * @param urls the urls to add to
-    * @throws IOException for any error
-    */
-   void getResources(BaseClassLoader classLoader, String name, Set<URL> urls, boolean allExports) throws IOException
-   {
-      boolean trace = log.isTraceEnabled();
-
-      if (getClassLoaderSystem() == null)
-         throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
-
-      // Try the before attempt
-      beforeGetResources(name, urls);
-
-      // Work out the rules
-      ClassLoaderInformation info = null;
-      BaseClassLoaderPolicy policy;
-      if (classLoader != null)
-      {
-         policy = classLoader.getPolicy();
-         info = infos.get(classLoader);
-         if (policy.isImportAll())
-            allExports = true;
-      }
-
-      // Next we try the old "big ball of mud" model      
-      if (allExports)
-         getResourcesFromExports(classLoader, name, urls, trace);
-      else if (trace)
-         log.trace(this + " not getting resource " + name + " from all exports");
-      
-      // Next we try the imports
-      if (info != null)
-         getResourcesFromImports(info, name, urls, trace);
-
-      // Finally use any requesting classloader
-      if (classLoader != null)
-      {
-         if (trace)
-            log.trace(this + " trying to get resources " + name + " from requesting " + classLoader);
-         classLoader.getResourcesLocally(name, urls);
-      }
-
-      // Try the after attempt
-      afterGetResources(name, urls);
-   }
-   
-   /**
-    * Load a package from the domain
-    * 
-    * @param classLoader the classloader
-    * @param name the resource name
-    * @param allExports whether we should look at all exports
-    * @return the package
-    */
-   Package getPackage(BaseClassLoader classLoader, String name, boolean allExports)
-   {
-      boolean trace = log.isTraceEnabled();
-
-      if (getClassLoaderSystem() == null)
-         throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
-
-      // Try the before attempt
-      Package result = beforeGetPackage(name);
-      if (result != null)
-         return result;
-
-      // Work out the rules
-      ClassLoaderInformation info = null;
-      BaseClassLoaderPolicy policy;
-      if (classLoader != null)
-      {
-         policy = classLoader.getPolicy();
-         info = infos.get(classLoader);
-         if (policy.isImportAll())
-            allExports = true;
-      }
-
-      // Next we try the old "big ball of mud" model      
-      if (allExports)
-      {
-         result = getPackageFromExports(classLoader, name, trace);
-         if (result != null)
-            return result;
-      }
-      else if (trace)
-         log.trace(this + " not getting package " + name + " from all exports");
-      
-      // Next we try the imports
-      if (info != null)
-      {
-         result = getPackageFromImports(info, name, trace);
-         if (result != null)
-            return result;
-      }
-
-      // Finally use any requesting classloader
-      if (classLoader != null)
-      {
-         if (trace)
-            log.trace(this + " trying to get package " + name + " from requesting " + classLoader);
-         result = classLoader.getPackageLocally(name);
-         if (result != null)
-         {
-            if (trace)
-               log.trace(this + " got package from requesting " + classLoader + " " + result);
-            return result;
-         }
-      }
-
-      // Try the after attempt
-      result = afterGetPackage(name);
-      if (result != null)
-         return result;
-      
-      // Didn't find it
-      return null;
-   }
-   
-   /**
-    * Load packages from the domain
-    * 
-    * @param classLoader the classloader
-    * @param name the package name
-    * @param allExports whether we should look at all exports
-    * @param packages the packages to add to
-    */
-   void getPackages(BaseClassLoader classLoader, Set<Package> packages, boolean allExports)
-   {
-      boolean trace = log.isTraceEnabled();
-
-      if (getClassLoaderSystem() == null)
-         throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
-
-      // Try the before attempt
-      beforeGetPackages(packages);
-
-      // Work out the rules
-      ClassLoaderInformation info = null;
-      BaseClassLoaderPolicy policy;
-      if (classLoader != null)
-      {
-         policy = classLoader.getPolicy();
-         info = infos.get(classLoader);
-         if (policy.isImportAll())
-            allExports = true;
-      }
-
-      // Next we try the old "big ball of mud" model      
-      if (allExports)
-         getPackagesFromExports(classLoader, packages, trace);
-      else if (trace)
-         log.trace(this + " not getting packages from all exports");
-      
-      // Next we try the imports
-      if (info != null)
-         getPackagesFromImports(info, packages, trace);
-
-      // Finally use any requesting classloader
-      if (classLoader != null)
-      {
-         if (trace)
-            log.trace(this + " trying to get packages from requesting " + classLoader);
-         classLoader.getPackagesLocally(packages);
-      }
-
-      // Try the after attempt
-      afterGetPackages(packages);
-   }
-   
-   /**
-    * Find a loader for class in exports
-    * 
-    * @param classLoader the classloader
-    * @param name the class resource name
-    * @param trace whether trace is enabled
-    * @return the loader
-    */
-   private Loader findLoaderInExports(BaseClassLoader classLoader, String name, boolean trace)
-   {
-      Loader loader = globalClassCache.get(name);
-      if (loader != null)
-      {
-         if (trace)
-            log.trace(this + " found in global class cache " + name);
-
-         return loader;
-      }
-
-      if (globalClassBlackList.containsKey(name))
-      {
-         if (trace)
-            log.trace(this + " class is black listed " + name);
-         return null;
-      }
-      boolean canCache = true;
-      boolean canBlackList = true;
-      
-      String packageName = ClassLoaderUtils.getResourcePackageName(name);
-      List<ClassLoaderInformation> list = classLoadersByPackageName.get(packageName);
-      if (trace)
-         log.trace(this + " trying to load " + name + " from all exports of package " + packageName + " " + list);
-      if (list != null && list.isEmpty() == false)
-      {
-         for (ClassLoaderInformation info : list)
-         {
-            BaseDelegateLoader exported = info.getExported();
-            
-            // See whether the policies allow caching/blacklisting
-            BaseClassLoaderPolicy loaderPolicy = exported.getPolicy();
-            if (loaderPolicy == null || loaderPolicy.isCacheable() == false)
-               canCache = false;
-            if (loaderPolicy == null || loaderPolicy.isBlackListable() == false)
-               canBlackList = false;
-
-            if (exported.getResource(name) != null)
-            {
-               if (canCache)
-                  globalClassCache.put(name, exported);
-               return exported;
-            }
-         }
-      }
-      // Here is not found in the exports so can we blacklist it?
-      if (canBlackList)
-         globalClassBlackList.put(name, name);
-      
-      return null;
-   }
-   
-   /**
-    * Load a resource from the exports
-    * 
-    * @param classLoader the classloader
-    * @param name the resource name
-    * @param trace whether trace is enabled
-    * @return the url
-    */
-   private URL getResourceFromExports(BaseClassLoader classLoader, String name, boolean trace)
-   {
-      URL result = globalResourceCache.get(name);
-      if (result != null)
-      {
-         if (trace)
-            log.trace(this + " got resource from cache " + name);
-      }
-      
-      if (globalResourceBlackList.containsKey(name))
-      {
-         if (trace)
-            log.trace(this + " resource is black listed, not looking at exports " + name);
-         return null;
-      }
-      boolean canCache = true;
-      boolean canBlackList = true;
-      
-      String packageName = ClassLoaderUtils.getResourcePackageName(name);
-      List<ClassLoaderInformation> list = classLoadersByPackageName.get(packageName);
-      if (trace)
-         log.trace(this + " trying to get resource " + name + " from all exports " + list);
-      if (list != null && list.isEmpty() == false)
-      {
-         for (ClassLoaderInformation info : list)
-         {
-            BaseDelegateLoader loader = info.getExported();
-            
-            // See whether the policies allow caching/blacklisting
-            BaseClassLoaderPolicy loaderPolicy = loader.getPolicy();
-            if (loaderPolicy == null || loaderPolicy.isCacheable() == false)
-               canCache = false;
-            if (loaderPolicy == null || loaderPolicy.isBlackListable() == false)
-               canBlackList = false;
-
-            result = loader.getResource(name);
-            if (result != null)
-            {
-               if (canCache)
-                  globalResourceCache.put(name, result);
-               return result;
-            }
-         }
-      }
-      // Here is not found in the exports so can we blacklist it?
-      if (canBlackList)
-         globalResourceBlackList.put(name, name);
-      return null;
-   }
-   
-   /**
-    * Load resources from the exports
-    * 
-    * @param classLoader the classloader
-    * @param name the resource name
-    * @param urls the urls to add to
-    * @param trace whether trace is enabled
-    * @throws IOException for any error
-    */
-   void getResourcesFromExports(BaseClassLoader classLoader, String name, Set<URL> urls, boolean trace) throws IOException
-   {
-      String packageName = ClassLoaderUtils.getResourcePackageName(name);
-      List<ClassLoaderInformation> list = classLoadersByPackageName.get(packageName);
-      if (trace)
-         log.trace(this + " trying to get resources " + name + " from all exports " + list);
-      if (list != null && list.isEmpty() == false)
-      {
-         for (ClassLoaderInformation info : list)
-         {
-            BaseDelegateLoader loader = info.getExported();
-            loader.getResources(name, urls);
-         }
-      }
-   }
-   
-   /**
-    * Load a package from the exports
-    * 
-    * @param classLoader the classloader
-    * @param name the package name
-    * @param trace whether trace is enabled
-    * @return the package
-    */
-   private Package getPackageFromExports(BaseClassLoader classLoader, String name, boolean trace)
-   {
-      List<ClassLoaderInformation> list = classLoadersByPackageName.get(name);
-      if (trace)
-         log.trace(this + " trying to get package " + name + " from all exports " + list);
-      if (list != null && list.isEmpty() == false)
-      {
-         for (ClassLoaderInformation info : list)
-         {
-            BaseDelegateLoader loader = info.getExported();
-
-            Package result = loader.getPackage(name);
-            if (result != null)
-               return result;
-         }
-      }
-      return null;
-   }
-   
-   /**
-    * Load packages from the exports
-    * 
-    * @param classLoader the classloader
-    * @param packages the packages to add to
-    * @param trace whether trace is enabled
-    */
-   void getPackagesFromExports(BaseClassLoader classLoader, Set<Package> packages, boolean trace)
-   {
-      List<ClassLoaderInformation> list = classLoaders;
-      if (trace)
-         log.trace(this + " trying to get all packages from all exports " + list);
-      if (list != null && list.isEmpty() == false)
-      {
-         for (ClassLoaderInformation info : list)
-         {
-            BaseDelegateLoader loader = info.getExported();
-            loader.getPackages(packages);
-         }
-      }
-   }
-
-   /**
-    * Find a loader for a class in imports
-    * 
-    * @param info the classloader information
-    * @param name the class resource name
-    * @param trace whether trace is enabled
-    * @return the loader
-    */
-   Loader findLoaderInImports(ClassLoaderInformation info, String name, boolean trace)
-   {
-      List<? extends DelegateLoader> delegates = info.getDelegates();
-      if (delegates == null || delegates.isEmpty())
-      {
-         if (trace)
-            log.trace(this + " not loading " + name + " from imports it has no delegates");
-         return null;
-      }
-
-      Loader loader = info.getCachedLoader(name);
-      if (loader != null)
-      {
-         if (trace)
-            log.trace(this + " found in import cache " + name);
-         return loader;
-      }
-      
-      if (info.isBlackListedClass(name))
-      {
-         if (trace)
-            log.trace(this + " class is black listed in imports " + name);
-         return null;
-      }
-      
-      for (DelegateLoader delegate : delegates)
-      {
-         if (trace)
-            log.trace(this + " trying to load " + name + " from import " + delegate + " for " + info.getClassLoader());
-         if (delegate.getResource(name) != null)
-         {
-            info.cacheLoader(name, delegate);
-            return delegate;
-         }
-      }
-      info.blackListClass(name);
-      return null;
-   }
-   
-   /**
-    * Load a resource from the imports
-    * 
-    * @param info the classloader information
-    * @param name the resource name
-    * @param trace whether trace is enabled
-    * @return the url
-    */
-   private URL getResourceFromImports(ClassLoaderInformation info, String name, boolean trace)
-   {
-      List<? extends DelegateLoader> delegates = info.getDelegates();
-      if (delegates == null || delegates.isEmpty())
-      {
-         if (trace)
-            log.trace(this + " not getting resource " + name + " from imports it has no delegates");
-         return null;
-      }
-
-      URL url = info.getCachedResource(name);
-      if (url != null)
-      {
-         if (trace)
-            log.trace(this + " found resource in import cache " + name);
-         return url;
-      }
-      
-      if (info.isBlackListedResource(name))
-      {
-         if (trace)
-            log.trace(this + " resource is black listed in imports " + name);
-         return null;
-      }
-
-      if (trace)
-         log.trace(this + " trying to get resource " + name + " from imports " + delegates + " for " + info.getClassLoader());
-
-      for (DelegateLoader delegate : delegates)
-      {
-         URL result = delegate.getResource(name);
-         if (result != null)
-         {
-            info.cacheResource(name, result);
-            return result;
-         }
-      }
-      info.blackListResource(name);
-      return null;
-   }
-   
-   /**
-    * Load resources from the imports
-    * 
-    * @param info the classloader info
-    * @param name the resource name
-    * @param urls the urls to add to
-    * @param trace whether trace is enabled
-    * @throws IOException for any error
-    */
-   void getResourcesFromImports(ClassLoaderInformation info, String name, Set<URL> urls, boolean trace) throws IOException
-   {
-      List<? extends DelegateLoader> delegates = info.getDelegates();
-      if (delegates == null || delegates.isEmpty())
-      {
-         if (trace)
-            log.trace(this + " not getting resource " + name + " from imports it has no delegates");
-         return;
-      }
-      if (trace)
-         log.trace(this + " trying to get resources " + name + " from imports " + delegates + " for " + info.getClassLoader());
-      for (DelegateLoader delegate : delegates)
-         delegate.getResources(name, urls);
-   }
-   
-   /**
-    * Load a package from the imports
-    * 
-    * @param info the classloader information
-    * @param name the pacakge name
-    * @param trace whether trace is enabled
-    * @return the package
-    */
-   private Package getPackageFromImports(ClassLoaderInformation info, String name, boolean trace)
-   {
-      List<? extends DelegateLoader> delegates = info.getDelegates();
-      if (delegates == null || delegates.isEmpty())
-      {
-         if (trace)
-            log.trace(this + " not getting package " + name + " from imports it has no delegates");
-         return null;
-      }
-
-      if (trace)
-         log.trace(this + " trying to get package " + name + " from imports " + delegates + " for " + info.getClassLoader());
-
-      for (DelegateLoader delegate : delegates)
-      {
-         Package result = delegate.getPackage(name);
-         if (result != null)
-            return result;
-      }
-      return null;
-   }
-   
-   /**
-    * Load packages from the imports
-    * 
-    * @param info the classloader info
-    * @param packages the packages to add to
-    * @param trace whether trace is enabled
-    */
-   void getPackagesFromImports(ClassLoaderInformation info, Set<Package> packages, boolean trace)
-   {
-      List<? extends DelegateLoader> delegates = info.getDelegates();
-      if (delegates == null || delegates.isEmpty())
-      {
-         if (trace)
-            log.trace(this + " not getting all packages from imports it has no delegates");
-         return;
-      }
-      if (trace)
-         log.trace(this + " trying to get all pacakges from imports " + delegates + " for " + info.getClassLoader());
-      for (DelegateLoader delegate : delegates)
-         delegate.getPackages(packages);
-   }
-
-   /**
-    * Invoked before classloading is attempted to allow a preload attempt, e.g. from the parent
-    * 
-    * @param name the class name
-    * @return the loader if found or null otherwise
-    */
-   protected abstract Class<?> loadClassBefore(String name);
-   
-   /**
-    * Invoked after classloading is attempted to allow a postload attempt, e.g. from the parent
-    * 
-    * @param name the class name
-    * @return the loader if found or null otherwise
-    */
-   protected abstract Class<?> loadClassAfter(String name);
-
-   /**
-    * Invoked before classloading is attempted to allow a preload attempt, e.g. from the parent
-    * 
-    * @param name the class resource name
-    * @return the loader if found or null otherwise
-    */
-   protected abstract Loader findBeforeLoader(String name);
-   
-   /**
-    * Invoked after classloading is attempted to allow a postload attempt, e.g. from the parent
-    * 
-    * @param name the class resource name
-    * @return the loader if found or null otherwise
-    */
-   protected abstract Loader findAfterLoader(String name);
-   
-   /**
-    * Invoked before getResources is attempted to allow a preload attempt, e.g. from the parent
-    * 
-    * @param name the resource name
-    * @param urls the urls to add to
-    * @throws IOException for any error
-    */
-   protected abstract void beforeGetResources(String name,  Set<URL> urls) throws IOException;
-   
-   /**
-    * Invoked after getResources is attempted to allow a postload attempt, e.g. from the parent
-    * 
-    * @param name the resource name
-    * @param urls the urls to add to
-    * @throws IOException for any error
-    */
-   protected abstract void afterGetResources(String name, Set<URL> urls) throws IOException;
-   
-   /**
-    * Invoked before getResource is attempted to allow a preload attempt, e.g. from the parent
-    * 
-    * @param name the resource name
-    * @return the url if found or null otherwise
-    */
-   protected abstract URL beforeGetResource(String name);
-   
-   /**
-    * Invoked after getResource is attempted to allow a postload attempt, e.g. from the parent
-    * 
-    * @param name the resource name
-    * @return the url if found or null otherwise
-    */
-   protected abstract URL afterGetResource(String name);
-   
-   /**
-    * Invoked before getPackages is attempted to allow a preload attempt, e.g. from the parent
-    * 
-    * @param packages the packages to add to
-    */
-   protected abstract void beforeGetPackages(Set<Package> packages);
-   
-   /**
-    * Invoked after getPackages is attempted to allow a postload attempt, e.g. from the parent
-    * 
-    * @param packages the packages to add to
-    */
-   protected abstract void afterGetPackages(Set<Package> packages);
-   
-   /**
-    * Invoked before getPackage is attempted to allow a preload attempt, e.g. from the parent
-    * 
-    * @param name the package name
-    * @return the package if found or null otherwise
-    */
-   protected abstract Package beforeGetPackage(String name);
-   
-   /**
-    * Invoked after getPackage is attempted to allow a postload attempt, e.g. from the parent
-    * 
-    * @param name the package name
-    * @return the url if found or null otherwise
-    */
-   protected abstract Package afterGetPackage(String name);
-   
-   public Class<?> loadClass(String name)
-   {
-      try
-      {
-         return loadClass(null, name, true);
-      }
-      catch (ClassNotFoundException e)
-      {
-         return null;
-      }
-   }
-   
-   /**
-    * Load a class from the domain
-    * 
-    * @param classLoader the classloader
-    * @param name the class name
-    * @return the class
-    * @throws ClassNotFoundException for any error
-    */
-   Class<?> loadClass(BaseClassLoader classLoader, String name) throws ClassNotFoundException
-   {
-      return loadClass(classLoader, name, false);
-   }
-   
-   public URL getResource(String name)
-   {
-      return getResource(null, name, true);
-   }
-   
-   /**
-    * Get a resource from the domain
-    * 
-    * @param classLoader the classloader
-    * @param name the resource name
-    * @return the url
-    */
-   URL getResource(BaseClassLoader classLoader, String name)
-   {
-      return getResource(classLoader, name, false);
-   }
-   
-   public void getResources(String name, Set<URL> urls) throws IOException
-   {
-      getResources(null, name, urls, true);
-   }
-   
-   /**
-    * Get a resource from the domain
-    * 
-    * @param classLoader the classloader
-    * @param name the resource name
-    * @param urls the urls to add to
-    * @throws IOException for any error
-    */
-   void getResources(BaseClassLoader classLoader, String name, Set<URL> urls) throws IOException
-   {
-      getResources(classLoader, name, urls, false);
-   }
-   
-   public Package getPackage(String name)
-   {
-      return getPackage(null, name, true);
-   }
-   
-   /**
-    * Get a package from the specified classloader
-    * 
-    * @param classLoader the classloader
-    * @param name the package name
-    * @return the package
-    */
-   Package getPackage(BaseClassLoader classLoader, String name)
-   {
-      return getPackage(classLoader, name, false);
-   }
-   
-   public void getPackages(Set<Package> packages)
-   {
-      getPackages(null, packages, true);
-   }
-   
-   /**
-    * Get the packages from a specified classloader 
-    * 
-    * @param classLoader the classloader
-    * @param packages the packages
-    */
-   void getPackages(BaseClassLoader classLoader, Set<Package> packages)
-   {
-      getPackages(classLoader, packages, false);
-   }
-
-   /**
-    * A long version of toString()
-    * 
-    * @return the long string
-    */
-   public String toLongString()
-   {
-      StringBuilder builder = new StringBuilder();
-      builder.append(getClass().getSimpleName());
-      builder.append("@").append(Integer.toHexString(System.identityHashCode(this)));
-      builder.append("{");
-      toLongString(builder);
-      builder.append('}');
-      return builder.toString();
-   }
-   
-   /**
-    * For subclasses to add information for toLongString()
-    * 
-    * @param builder the builder
-    */
-   protected void toLongString(StringBuilder builder)
-   {
-   }
-   
-   /**
-    * Invoked before adding a classloader policy 
-    * 
-    * @param classLoader the classloader
-    * @param policy the classloader policy
-    */
-   protected void beforeRegisterClassLoader(ClassLoader classLoader, ClassLoaderPolicy policy)
-   {
-      // nothing
-   }
-
-   /**
-    * Invoked after adding a classloader policy 
-    * 
-    * @param classLoader the classloader
-    * @param policy the classloader policy
-    */
-   protected void afterRegisterClassLoader(ClassLoader classLoader, ClassLoaderPolicy policy)
-   {
-      // nothing
-   }
-   
-   /**
-    * Invoked before adding a classloader policy 
-    * 
-    * @param classLoader the classloader
-    * @param policy the classloader policy
-    */
-   protected void beforeUnregisterClassLoader(ClassLoader classLoader, ClassLoaderPolicy policy)
-   {
-      // nothing
-   }
-   
-   /**
-    * Invoked after adding a classloader policy 
-    * 
-    * @param classLoader the classloader
-    * @param policy the classloader policy
-    */
-   protected void afterUnregisterClassLoader(ClassLoader classLoader, ClassLoaderPolicy policy)
-   {
-      // nothing
-   }
-
-   /**
-    * Get the parent classloader
-    * 
-    * @return the parent classloader
-    */
-   protected ClassLoader getParentClassLoader()
-   {
-      return getClass().getClassLoader();
-   }
-
-   /**
-    * Register a classloader 
-    * 
-    * @param classLoader the classloader
-    */
-   void registerClassLoader(BaseClassLoader classLoader)
-   {
-      log.debug(this + " registerClassLoader " + classLoader.toString());
-
-      if (getClassLoaderSystem() == null)
-         throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
-      
-      ClassLoaderPolicy policy = classLoader.getPolicy();
-      BaseDelegateLoader exported = policy.getExported();
-      if (exported != null && exported.getPolicy() == null)
-         throw new IllegalStateException("The exported delegate " + exported + " is too lazy for " + policy.toLongString());
-      
-      try
-      {
-         beforeRegisterClassLoader(classLoader, policy);
-      }
-      catch (Throwable t)
-      {
-         log.warn("Error in beforeRegisterClassLoader: " + this + " classLoader=" + classLoader.toLongString(), t);
-      }
-      
-      BaseClassLoaderPolicy basePolicy = classLoader.getPolicy();
-      basePolicy.setClassLoaderDomain(this);
-
-      synchronized (classLoaders)
-      {
-         // Create the information
-         ClassLoaderInformation info = new ClassLoaderInformation(classLoader, policy, order++);
-         classLoaders.add(info);
-         infos.put(classLoader, info);
-
-         // Index the packages
-         String[] packageNames = policy.getPackageNames();
-         if (packageNames != null && info.getExported() != null)
-         {
-            for (String packageName : packageNames)
-            {
-               List<ClassLoaderInformation> list = classLoadersByPackageName.get(packageName);
-               if (list == null)
-               {
-                  list = new CopyOnWriteArrayList<ClassLoaderInformation>();
-                  classLoadersByPackageName.put(packageName, list);
-               }
-               list.add(info);
-               log.trace("Registered " + policy + " as providing package=" + packageName);
-            }
-         }
-         
-         flushCaches();
-      }
-
-      try
-      {
-         afterRegisterClassLoader(classLoader, classLoader.getPolicy());
-      }
-      catch (Throwable t)
-      {
-         log.warn("Error in afterRegisterClassLoader: " + this + " classLoader=" + classLoader.toLongString(), t);
-      }
-   }
-   
-   /**
-    * Remove a classloader 
-    * 
-    * @param classLoader the classloader
-    */
-   void unregisterClassLoader(BaseClassLoader classLoader)
-   {
-      log.debug(this + " unregisterClassLoader " + classLoader.toString());
-
-      try
-      {
-         beforeUnregisterClassLoader(classLoader, classLoader.getPolicy());
-      }
-      catch (Throwable t)
-      {
-         log.warn("Error in beforeUnegisterClassLoader: " + this + " classLoader=" + classLoader.toLongString(), t);
-      }
-
-      BaseClassLoaderPolicy policy = classLoader.getPolicy();
-      policy.unsetClassLoaderDomain(this);
-
-      synchronized (classLoaders)
-      {
-         // Remove the classloader
-         ClassLoaderInformation info = infos.remove(classLoader);
-         classLoaders.remove(info);
-         
-         // Remove the package index
-         String[] packageNames = policy.getPackageNames();
-         if (packageNames != null && info.getExported() != null)
-         {
-            for (String packageName : packageNames)
-            {
-               List<ClassLoaderInformation> list = classLoadersByPackageName.get(packageName);
-               if (list != null)
-               {
-                  list.remove(info);
-                  log.trace("Unregistered " + policy + " as providing package=" + packageName);
-                  if (list.isEmpty())
-                     classLoadersByPackageName.remove(packageName);
-               }
-            }
-         }
-
-         flushCaches();
-      }
-
-      try
-      {
-         afterUnregisterClassLoader(classLoader, classLoader.getPolicy());
-      }
-      catch (Throwable t)
-      {
-         log.warn("Error in afterUnegisterClassLoader: " + this + " classLoader=" + classLoader.toLongString(), t);
-      }
-   }
-
-   /**
-    * Get all the classloaders
-    * 
-    * @return the list of classloaders
-    */
-   protected List<ClassLoader> getAllClassLoaders()
-   {
-      List<ClassLoader> result = new ArrayList<ClassLoader>();
-      for (ClassLoaderInformation info : classLoaders)
-         result.add(info.getClassLoader());
-      return result;
-   }
-
-   /**
-    * Get a map of packages to classloader
-    * 
-    * @return a map of packages to a list of classloaders for that package
-    */
-   protected Map<String, List<ClassLoader>> getClassLoadersByPackage()
-   {
-      HashMap<String, List<ClassLoader>> result = new HashMap<String, List<ClassLoader>>();
-      for (Entry<String, List<ClassLoaderInformation>> entry : classLoadersByPackageName.entrySet())
-      {
-         List<ClassLoader> cls = new ArrayList<ClassLoader>();
-         for (ClassLoaderInformation info : entry.getValue())
-            cls.add(info.getClassLoader());
-         result.put(entry.getKey(), cls);
-      }
-      return result;
-   }
-
-   protected List<ClassLoader> getClassLoaders(String packageName)
-   {
-      if (packageName == null)
-         throw new IllegalArgumentException("Null package name");
-      
-      List<ClassLoader> result = new ArrayList<ClassLoader>();
-      List<ClassLoaderInformation> infos = classLoadersByPackageName.get(packageName);
-      if (infos != null)
-      {
-         for (ClassLoaderInformation info : infos)
-            result.add(info.getClassLoader());
-      }
-      return result;
-   }
-
-   /**
-    * Cleans the entry with the given name from the blackList
-    *
-    * @param name the name of the resource to clear from the blackList
-    */
-   protected void clearBlackList(String name)
-   {
-      if (globalClassBlackList != null)
-      {
-         globalClassBlackList.remove(name);
-      }
-      if (globalResourceBlackList != null)
-      {
-         globalResourceBlackList.remove(name);
-      }
-   }
-   
-}

Copied: projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java (from rev 83469, projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java)
===================================================================
--- projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java	                        (rev 0)
+++ projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderDomain.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -0,0 +1,1435 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.classloader.spi.base;
+
+import java.io.IOException;
+import java.net.URL;
+import java.security.ProtectionDomain;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.DelegateLoader;
+import org.jboss.classloader.spi.Loader;
+import org.jboss.logging.Logger;
+
+/**
+ * BaseClassLoaderDomain.<p>
+ * 
+ * This class hides some of the implementation details and allows
+ * package access to the protected methods.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class BaseClassLoaderDomain implements Loader
+{
+   /** The log */
+   private static final Logger log = Logger.getLogger(BaseClassLoaderDomain.class);
+
+   /** The classloader system to which we belong */
+   private BaseClassLoaderSystem system;
+   
+   /** The classloaders  in the order they were registered */
+   private List<ClassLoaderInformation> classLoaders = new CopyOnWriteArrayList<ClassLoaderInformation>();
+
+   /** The classloader information by classloader */
+   private Map<ClassLoader, ClassLoaderInformation> infos = new ConcurrentHashMap<ClassLoader, ClassLoaderInformation>();
+   
+   /** The classloaders by package name */
+   private Map<String, List<ClassLoaderInformation>> classLoadersByPackageName = new ConcurrentHashMap<String, List<ClassLoaderInformation>>();
+   
+   /** The global class cache */
+   private Map<String, Loader> globalClassCache = new ConcurrentHashMap<String, Loader>();
+   
+   /** The global class black list */
+   private Map<String, String> globalClassBlackList = new ConcurrentHashMap<String, String>();
+   
+   /** The global resource cache */
+   private Map<String, URL> globalResourceCache = new ConcurrentHashMap<String, URL>();
+   
+   /** The global resource black list */
+   private Map<String, String> globalResourceBlackList = new ConcurrentHashMap<String, String>();
+   
+   /** Keep track of the added order */
+   private int order = 0;
+   
+   /**
+    * Flush the internal caches
+    */
+   public void flushCaches()
+   {
+      globalClassCache.clear();
+      globalClassBlackList.clear();
+      globalResourceCache.clear();
+      globalResourceBlackList.clear();
+   }
+
+   public int getClassBlackListSize()
+   {
+      return globalClassBlackList.size();
+   }
+
+   public int getClassCacheSize()
+   {
+      return globalClassCache.size();
+   }
+
+   public int getResourceBlackListSize()
+   {
+      return globalClassBlackList.size();
+   }
+
+   public int getResourceCacheSize()
+   {
+      return globalClassCache.size();
+   }
+   
+   public Set<String> listClassBlackList()
+   {
+      return Collections.unmodifiableSet(globalClassBlackList.keySet());
+   }
+
+   public Map<String, String> listClassCache()
+   {
+      Map<String, String> result = new HashMap<String, String>(globalClassCache.size());
+      for (Map.Entry<String, Loader> entry : globalClassCache.entrySet())
+         result.put(entry.getKey(), entry.getValue().toString());
+      return result;
+   }
+
+   public Set<String> listResourceBlackList()
+   {
+      return Collections.unmodifiableSet(globalResourceBlackList.keySet());
+   }
+
+   public Map<String, URL> listResourceCache()
+   {
+      return Collections.unmodifiableMap(globalResourceCache);
+   }
+
+   /**
+    * Get the classloader system
+    * 
+    * @return the classloader system
+    */
+   protected synchronized BaseClassLoaderSystem getClassLoaderSystem()
+   {
+      return system;
+   }
+   
+   /**
+    * Get the classloader system
+    * 
+    * @param system the classloader system
+    */
+   synchronized void setClassLoaderSystem(BaseClassLoaderSystem system)
+   {
+      if (system == null)
+         shutdownDomain();
+      this.system = system;
+   }
+
+   /**
+    * Shutdown the domain<p>
+    * 
+    * The default implementation just unregisters all classloaders
+    */
+   protected void shutdownDomain()
+   {
+      log.debug(toString() + " shutdown!");
+
+      // Unregister all classloaders
+      while (true)
+      {
+         Iterator<ClassLoaderInformation> iterator = classLoaders.iterator();
+         if (iterator.hasNext() == false)
+            break;
+
+         while (iterator.hasNext())
+         {
+            ClassLoaderInformation info = iterator.next();
+            if (info != null)
+               unregisterClassLoader(info.getClassLoader());
+         }
+      }
+      
+      flushCaches();
+   }
+   
+   /**
+    * Whether the domain has classloaders
+    * 
+    * @return true when the domain has classloaders
+    */
+   public boolean hasClassLoaders()
+   {
+      return classLoaders.isEmpty() == false;
+   }
+   
+   /**
+    * Whether to use load class for parent
+    * 
+    * @return true to load class on the parent loader
+    */
+   public abstract boolean isUseLoadClassForParent();
+   
+   /**
+    * Transform the byte code<p>
+    * 
+    * By default, this delegates to the classloader system
+    * 
+    * @param classLoader the classloader
+    * @param className the class name
+    * @param byteCode the byte code
+    * @param protectionDomain the protection domain
+    * @return the transformed byte code
+    * @throws Exception for any error
+    */
+   protected byte[] transform(ClassLoader classLoader, String className, byte[] byteCode, ProtectionDomain protectionDomain) throws Exception
+   {
+      BaseClassLoaderSystem system = getClassLoaderSystem();
+      if (system != null)
+         return system.transform(classLoader, className, byteCode, protectionDomain);
+      return byteCode;
+   }
+
+   /**
+    * Load a class from the domain
+    * 
+    * @param classLoader the classloader
+    * @param name the class name
+    * @param allExports whether we should look at all exports
+    * @return the class
+    * @throws ClassNotFoundException for any error
+    */
+   protected Class<?> loadClass(BaseClassLoader classLoader, String name, boolean allExports) throws ClassNotFoundException
+   {
+      boolean trace = log.isTraceEnabled();
+
+      boolean findInParent = (isUseLoadClassForParent() == false);
+      
+      // Should we directly load from the parent?
+      if (findInParent == false)
+      {
+         Class<?> clazz = loadClassBefore(name);
+         if (clazz != null)
+            return clazz;
+      }
+      
+      String path = ClassLoaderUtils.classNameToPath(name);
+      
+      Loader loader = findLoader(classLoader, path, allExports, findInParent);
+      if (loader != null)
+      {
+         Thread thread = Thread.currentThread();
+         ClassLoadingTask task = new ClassLoadingTask(name, classLoader, thread);
+         ClassLoaderManager.scheduleTask(task, loader, false);
+         return ClassLoaderManager.process(thread, task);
+      }
+      
+      // Should we directly load from the parent?
+      if (findInParent == false)
+      {
+         Class<?> clazz = loadClassAfter(name);
+         if (clazz != null)
+            return clazz;
+      }
+
+      // Finally see whether this is the JDK assuming it can load its classes from any classloader
+      if (classLoader != null)
+      {
+         BaseClassLoaderPolicy policy = classLoader.getPolicy();
+         ClassLoader hack = policy.isJDKRequest(name);
+         if (hack != null)
+         {
+            if (trace)
+               log.trace(this + " trying to load " + name + " using hack " + hack);
+            Class<?> result = Class.forName(name, false, hack);
+            if (result != null)
+            {
+               if (trace)
+                  log.trace(this + " loaded from hack " + hack + " " + ClassLoaderUtils.classToString(result));
+               return result;
+            }
+         }
+      }
+      
+      // Didn't find it
+      return null;
+   }
+
+   /**
+    * Find a loader for a class
+    * 
+    * @param name the class resource name
+    * @return the loader
+    */
+   protected Loader findLoader(String name)
+   {
+      return findLoader(null, name, true, true);
+   }
+
+   /**
+    * Find a loader for a class
+    * 
+    * @param classLoader the classloader
+    * @param name the class resource name
+    * @param allExports whether we should look at all exports
+    * @param findInParent should we try the parent
+    * @return the loader
+    */
+   Loader findLoader(BaseClassLoader classLoader, String name, boolean allExports, boolean findInParent)
+   {
+      boolean trace = log.isTraceEnabled();
+      if (trace)
+         log.trace(this + " findLoader " + name + " classLoader=" + classLoader + " allExports=" + allExports + " findInParent=" + findInParent);
+      
+      if (getClassLoaderSystem() == null)
+         throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
+      
+      // Try the before attempt (e.g. from the parent)
+      Loader loader = null;
+      if (findInParent)
+         loader = findBeforeLoader(name);
+      if (loader != null)
+         return loader;
+
+      // Work out the rules
+      ClassLoaderInformation info = null;
+      BaseClassLoaderPolicy policy;
+      if (classLoader != null)
+      {
+         info = infos.get(classLoader);
+         policy = classLoader.getPolicy();
+         if (policy.isImportAll())
+            allExports = true;
+      }
+
+      // Next we try the old "big ball of mud" model      
+      if (allExports)
+      {
+         loader = findLoaderInExports(classLoader, name, trace);
+         if (loader != null)
+            return loader;
+      }
+      else if (trace)
+         log.trace(this + " not loading " + name + " from all exports");
+      
+      // Next we try the imports
+      if (info != null)
+      {
+         loader = findLoaderInImports(info, name, trace);
+         if (loader != null)
+            return loader;
+      }
+
+      // Next use any requesting classloader, this will look at everything not just what it exports
+      if (classLoader != null)
+      {
+         if (trace)
+            log.trace(this + " trying to load " + name + " from requesting " + classLoader);
+         if (classLoader.getResourceLocally(name) != null)
+            return classLoader.getLoader();
+      }
+
+      // Try the after attempt (e.g. from the parent)
+      if (findInParent)
+         return findAfterLoader(name);
+      
+      return null;
+   }
+   
+   /**
+    * Load a resource from the domain
+    * 
+    * @param classLoader the classloader
+    * @param name the resource name
+    * @param allExports whether we should look at all exports
+    * @return the url
+    */
+   URL getResource(BaseClassLoader classLoader, String name, boolean allExports)
+   {
+      boolean trace = log.isTraceEnabled();
+
+      // Try the classloader first
+      if (classLoader != null)
+      {
+         if (trace)
+            log.trace(this + " trying to get resource " + name + " from requesting " + classLoader);
+         URL result = classLoader.getResourceLocally(name);
+         if (result != null)
+         {
+            if (trace)
+               log.trace(this + " got resource from requesting " + classLoader + " " + result);
+            return result;
+         }
+      }
+
+      if (getClassLoaderSystem() == null)
+         throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
+
+      // Try the before attempt
+      URL result = beforeGetResource(name);
+      if (result != null)
+         return result;
+
+      // Work out the rules
+      ClassLoaderInformation info = null;
+      BaseClassLoaderPolicy policy;
+      if (classLoader != null)
+      {
+         policy = classLoader.getPolicy();
+         info = infos.get(classLoader);
+         if (policy.isImportAll())
+            allExports = true;
+      }
+
+      // Next we try the old "big ball of mud" model      
+      if (allExports)
+      {
+         result = getResourceFromExports(classLoader, name, trace);
+         if (result != null)
+            return result;
+      }
+      else if (trace)
+         log.trace(this + " not getting resource " + name + " from all exports");
+      
+      // Next we try the imports
+      if (info != null)
+      {
+         result = getResourceFromImports(info, name, trace);
+         if (result != null)
+            return result;
+      }
+
+      // Try the after attempt
+      result = afterGetResource(name);
+      if (result != null)
+         return result;
+      
+      // Didn't find it
+      return null;
+   }
+   
+   /**
+    * Load resources from the domain
+    * 
+    * @param classLoader the classloader
+    * @param name the resource name
+    * @param allExports whether we should look at all exports
+    * @param urls the urls to add to
+    * @throws IOException for any error
+    */
+   void getResources(BaseClassLoader classLoader, String name, Set<URL> urls, boolean allExports) throws IOException
+   {
+      boolean trace = log.isTraceEnabled();
+
+      if (getClassLoaderSystem() == null)
+         throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
+
+      // Try the before attempt
+      beforeGetResources(name, urls);
+
+      // Work out the rules
+      ClassLoaderInformation info = null;
+      BaseClassLoaderPolicy policy;
+      if (classLoader != null)
+      {
+         policy = classLoader.getPolicy();
+         info = infos.get(classLoader);
+         if (policy.isImportAll())
+            allExports = true;
+      }
+
+      // Next we try the old "big ball of mud" model      
+      if (allExports)
+         getResourcesFromExports(classLoader, name, urls, trace);
+      else if (trace)
+         log.trace(this + " not getting resource " + name + " from all exports");
+      
+      // Next we try the imports
+      if (info != null)
+         getResourcesFromImports(info, name, urls, trace);
+
+      // Finally use any requesting classloader
+      if (classLoader != null)
+      {
+         if (trace)
+            log.trace(this + " trying to get resources " + name + " from requesting " + classLoader);
+         classLoader.getResourcesLocally(name, urls);
+      }
+
+      // Try the after attempt
+      afterGetResources(name, urls);
+   }
+   
+   /**
+    * Load a package from the domain
+    * 
+    * @param classLoader the classloader
+    * @param name the resource name
+    * @param allExports whether we should look at all exports
+    * @return the package
+    */
+   Package getPackage(BaseClassLoader classLoader, String name, boolean allExports)
+   {
+      boolean trace = log.isTraceEnabled();
+
+      if (getClassLoaderSystem() == null)
+         throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
+
+      // Try the before attempt
+      Package result = beforeGetPackage(name);
+      if (result != null)
+         return result;
+
+      // Work out the rules
+      ClassLoaderInformation info = null;
+      BaseClassLoaderPolicy policy;
+      if (classLoader != null)
+      {
+         policy = classLoader.getPolicy();
+         info = infos.get(classLoader);
+         if (policy.isImportAll())
+            allExports = true;
+      }
+
+      // Next we try the old "big ball of mud" model      
+      if (allExports)
+      {
+         result = getPackageFromExports(classLoader, name, trace);
+         if (result != null)
+            return result;
+      }
+      else if (trace)
+         log.trace(this + " not getting package " + name + " from all exports");
+      
+      // Next we try the imports
+      if (info != null)
+      {
+         result = getPackageFromImports(info, name, trace);
+         if (result != null)
+            return result;
+      }
+
+      // Finally use any requesting classloader
+      if (classLoader != null)
+      {
+         if (trace)
+            log.trace(this + " trying to get package " + name + " from requesting " + classLoader);
+         result = classLoader.getPackageLocally(name);
+         if (result != null)
+         {
+            if (trace)
+               log.trace(this + " got package from requesting " + classLoader + " " + result);
+            return result;
+         }
+      }
+
+      // Try the after attempt
+      result = afterGetPackage(name);
+      if (result != null)
+         return result;
+      
+      // Didn't find it
+      return null;
+   }
+   
+   /**
+    * Load packages from the domain
+    * 
+    * @param classLoader the classloader
+    * @param packages the packages to add to
+    * @param allExports whether we should look at all exports
+    */
+   void getPackages(BaseClassLoader classLoader, Set<Package> packages, boolean allExports)
+   {
+      boolean trace = log.isTraceEnabled();
+
+      if (getClassLoaderSystem() == null)
+         throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
+
+      // Try the before attempt
+      beforeGetPackages(packages);
+
+      // Work out the rules
+      ClassLoaderInformation info = null;
+      BaseClassLoaderPolicy policy;
+      if (classLoader != null)
+      {
+         policy = classLoader.getPolicy();
+         info = infos.get(classLoader);
+         if (policy.isImportAll())
+            allExports = true;
+      }
+
+      // Next we try the old "big ball of mud" model      
+      if (allExports)
+         getPackagesFromExports(classLoader, packages, trace);
+      else if (trace)
+         log.trace(this + " not getting packages from all exports");
+      
+      // Next we try the imports
+      if (info != null)
+         getPackagesFromImports(info, packages, trace);
+
+      // Finally use any requesting classloader
+      if (classLoader != null)
+      {
+         if (trace)
+            log.trace(this + " trying to get packages from requesting " + classLoader);
+         classLoader.getPackagesLocally(packages);
+      }
+
+      // Try the after attempt
+      afterGetPackages(packages);
+   }
+   
+   /**
+    * Find a loader for class in exports
+    * 
+    * @param classLoader the classloader
+    * @param name the class resource name
+    * @param trace whether trace is enabled
+    * @return the loader
+    */
+   private Loader findLoaderInExports(BaseClassLoader classLoader, String name, boolean trace)
+   {
+      Loader loader = globalClassCache.get(name);
+      if (loader != null)
+      {
+         if (trace)
+            log.trace(this + " found in global class cache " + name);
+
+         return loader;
+      }
+
+      if (globalClassBlackList.containsKey(name))
+      {
+         if (trace)
+            log.trace(this + " class is black listed " + name);
+         return null;
+      }
+      boolean canCache = true;
+      boolean canBlackList = true;
+      
+      String packageName = ClassLoaderUtils.getResourcePackageName(name);
+      List<ClassLoaderInformation> list = classLoadersByPackageName.get(packageName);
+      if (trace)
+         log.trace(this + " trying to load " + name + " from all exports of package " + packageName + " " + list);
+      if (list != null && list.isEmpty() == false)
+      {
+         for (ClassLoaderInformation info : list)
+         {
+            BaseDelegateLoader exported = info.getExported();
+            
+            // See whether the policies allow caching/blacklisting
+            BaseClassLoaderPolicy loaderPolicy = exported.getPolicy();
+            if (loaderPolicy == null || loaderPolicy.isCacheable() == false)
+               canCache = false;
+            if (loaderPolicy == null || loaderPolicy.isBlackListable() == false)
+               canBlackList = false;
+
+            if (exported.getResource(name) != null)
+            {
+               if (canCache)
+                  globalClassCache.put(name, exported);
+               return exported;
+            }
+         }
+      }
+      // Here is not found in the exports so can we blacklist it?
+      if (canBlackList)
+         globalClassBlackList.put(name, name);
+      
+      return null;
+   }
+   
+   /**
+    * Load a resource from the exports
+    * 
+    * @param classLoader the classloader
+    * @param name the resource name
+    * @param trace whether trace is enabled
+    * @return the url
+    */
+   private URL getResourceFromExports(BaseClassLoader classLoader, String name, boolean trace)
+   {
+      URL result = globalResourceCache.get(name);
+      if (result != null)
+      {
+         if (trace)
+            log.trace(this + " got resource from cache " + name);
+      }
+      
+      if (globalResourceBlackList.containsKey(name))
+      {
+         if (trace)
+            log.trace(this + " resource is black listed, not looking at exports " + name);
+         return null;
+      }
+      boolean canCache = true;
+      boolean canBlackList = true;
+      
+      String packageName = ClassLoaderUtils.getResourcePackageName(name);
+      List<ClassLoaderInformation> list = classLoadersByPackageName.get(packageName);
+      if (trace)
+         log.trace(this + " trying to get resource " + name + " from all exports " + list);
+      if (list != null && list.isEmpty() == false)
+      {
+         for (ClassLoaderInformation info : list)
+         {
+            BaseDelegateLoader loader = info.getExported();
+            
+            // See whether the policies allow caching/blacklisting
+            BaseClassLoaderPolicy loaderPolicy = loader.getPolicy();
+            if (loaderPolicy == null || loaderPolicy.isCacheable() == false)
+               canCache = false;
+            if (loaderPolicy == null || loaderPolicy.isBlackListable() == false)
+               canBlackList = false;
+
+            result = loader.getResource(name);
+            if (result != null)
+            {
+               if (canCache)
+                  globalResourceCache.put(name, result);
+               return result;
+            }
+         }
+      }
+      // Here is not found in the exports so can we blacklist it?
+      if (canBlackList)
+         globalResourceBlackList.put(name, name);
+      return null;
+   }
+   
+   /**
+    * Load resources from the exports
+    * 
+    * @param classLoader the classloader
+    * @param name the resource name
+    * @param urls the urls to add to
+    * @param trace whether trace is enabled
+    * @throws IOException for any error
+    */
+   void getResourcesFromExports(BaseClassLoader classLoader, String name, Set<URL> urls, boolean trace) throws IOException
+   {
+      String packageName = ClassLoaderUtils.getResourcePackageName(name);
+      List<ClassLoaderInformation> list = classLoadersByPackageName.get(packageName);
+      if (trace)
+         log.trace(this + " trying to get resources " + name + " from all exports " + list);
+      if (list != null && list.isEmpty() == false)
+      {
+         for (ClassLoaderInformation info : list)
+         {
+            BaseDelegateLoader loader = info.getExported();
+            loader.getResources(name, urls);
+         }
+      }
+   }
+   
+   /**
+    * Load a package from the exports
+    * 
+    * @param classLoader the classloader
+    * @param name the package name
+    * @param trace whether trace is enabled
+    * @return the package
+    */
+   private Package getPackageFromExports(BaseClassLoader classLoader, String name, boolean trace)
+   {
+      List<ClassLoaderInformation> list = classLoadersByPackageName.get(name);
+      if (trace)
+         log.trace(this + " trying to get package " + name + " from all exports " + list);
+      if (list != null && list.isEmpty() == false)
+      {
+         for (ClassLoaderInformation info : list)
+         {
+            BaseDelegateLoader loader = info.getExported();
+
+            Package result = loader.getPackage(name);
+            if (result != null)
+               return result;
+         }
+      }
+      return null;
+   }
+   
+   /**
+    * Load packages from the exports
+    * 
+    * @param classLoader the classloader
+    * @param packages the packages to add to
+    * @param trace whether trace is enabled
+    */
+   void getPackagesFromExports(BaseClassLoader classLoader, Set<Package> packages, boolean trace)
+   {
+      List<ClassLoaderInformation> list = classLoaders;
+      if (trace)
+         log.trace(this + " trying to get all packages from all exports " + list);
+      if (list != null && list.isEmpty() == false)
+      {
+         for (ClassLoaderInformation info : list)
+         {
+            BaseDelegateLoader loader = info.getExported();
+            loader.getPackages(packages);
+         }
+      }
+   }
+
+   /**
+    * Find a loader for a class in imports
+    * 
+    * @param info the classloader information
+    * @param name the class resource name
+    * @param trace whether trace is enabled
+    * @return the loader
+    */
+   Loader findLoaderInImports(ClassLoaderInformation info, String name, boolean trace)
+   {
+      List<? extends DelegateLoader> delegates = info.getDelegates();
+      if (delegates == null || delegates.isEmpty())
+      {
+         if (trace)
+            log.trace(this + " not loading " + name + " from imports it has no delegates");
+         return null;
+      }
+
+      Loader loader = info.getCachedLoader(name);
+      if (loader != null)
+      {
+         if (trace)
+            log.trace(this + " found in import cache " + name);
+         return loader;
+      }
+      
+      if (info.isBlackListedClass(name))
+      {
+         if (trace)
+            log.trace(this + " class is black listed in imports " + name);
+         return null;
+      }
+      
+      for (DelegateLoader delegate : delegates)
+      {
+         if (trace)
+            log.trace(this + " trying to load " + name + " from import " + delegate + " for " + info.getClassLoader());
+         if (delegate.getResource(name) != null)
+         {
+            info.cacheLoader(name, delegate);
+            return delegate;
+         }
+      }
+      info.blackListClass(name);
+      return null;
+   }
+   
+   /**
+    * Load a resource from the imports
+    * 
+    * @param info the classloader information
+    * @param name the resource name
+    * @param trace whether trace is enabled
+    * @return the url
+    */
+   private URL getResourceFromImports(ClassLoaderInformation info, String name, boolean trace)
+   {
+      List<? extends DelegateLoader> delegates = info.getDelegates();
+      if (delegates == null || delegates.isEmpty())
+      {
+         if (trace)
+            log.trace(this + " not getting resource " + name + " from imports it has no delegates");
+         return null;
+      }
+
+      URL url = info.getCachedResource(name);
+      if (url != null)
+      {
+         if (trace)
+            log.trace(this + " found resource in import cache " + name);
+         return url;
+      }
+      
+      if (info.isBlackListedResource(name))
+      {
+         if (trace)
+            log.trace(this + " resource is black listed in imports " + name);
+         return null;
+      }
+
+      if (trace)
+         log.trace(this + " trying to get resource " + name + " from imports " + delegates + " for " + info.getClassLoader());
+
+      for (DelegateLoader delegate : delegates)
+      {
+         URL result = delegate.getResource(name);
+         if (result != null)
+         {
+            info.cacheResource(name, result);
+            return result;
+         }
+      }
+      info.blackListResource(name);
+      return null;
+   }
+   
+   /**
+    * Load resources from the imports
+    * 
+    * @param info the classloader info
+    * @param name the resource name
+    * @param urls the urls to add to
+    * @param trace whether trace is enabled
+    * @throws IOException for any error
+    */
+   void getResourcesFromImports(ClassLoaderInformation info, String name, Set<URL> urls, boolean trace) throws IOException
+   {
+      List<? extends DelegateLoader> delegates = info.getDelegates();
+      if (delegates == null || delegates.isEmpty())
+      {
+         if (trace)
+            log.trace(this + " not getting resource " + name + " from imports it has no delegates");
+         return;
+      }
+      if (trace)
+         log.trace(this + " trying to get resources " + name + " from imports " + delegates + " for " + info.getClassLoader());
+      for (DelegateLoader delegate : delegates)
+         delegate.getResources(name, urls);
+   }
+   
+   /**
+    * Load a package from the imports
+    * 
+    * @param info the classloader information
+    * @param name the pacakge name
+    * @param trace whether trace is enabled
+    * @return the package
+    */
+   private Package getPackageFromImports(ClassLoaderInformation info, String name, boolean trace)
+   {
+      List<? extends DelegateLoader> delegates = info.getDelegates();
+      if (delegates == null || delegates.isEmpty())
+      {
+         if (trace)
+            log.trace(this + " not getting package " + name + " from imports it has no delegates");
+         return null;
+      }
+
+      if (trace)
+         log.trace(this + " trying to get package " + name + " from imports " + delegates + " for " + info.getClassLoader());
+
+      for (DelegateLoader delegate : delegates)
+      {
+         Package result = delegate.getPackage(name);
+         if (result != null)
+            return result;
+      }
+      return null;
+   }
+   
+   /**
+    * Load packages from the imports
+    * 
+    * @param info the classloader info
+    * @param packages the packages to add to
+    * @param trace whether trace is enabled
+    */
+   void getPackagesFromImports(ClassLoaderInformation info, Set<Package> packages, boolean trace)
+   {
+      List<? extends DelegateLoader> delegates = info.getDelegates();
+      if (delegates == null || delegates.isEmpty())
+      {
+         if (trace)
+            log.trace(this + " not getting all packages from imports it has no delegates");
+         return;
+      }
+      if (trace)
+         log.trace(this + " trying to get all pacakges from imports " + delegates + " for " + info.getClassLoader());
+      for (DelegateLoader delegate : delegates)
+         delegate.getPackages(packages);
+   }
+
+   /**
+    * Invoked before classloading is attempted to allow a preload attempt, e.g. from the parent
+    * 
+    * @param name the class name
+    * @return the loader if found or null otherwise
+    */
+   protected abstract Class<?> loadClassBefore(String name);
+   
+   /**
+    * Invoked after classloading is attempted to allow a postload attempt, e.g. from the parent
+    * 
+    * @param name the class name
+    * @return the loader if found or null otherwise
+    */
+   protected abstract Class<?> loadClassAfter(String name);
+
+   /**
+    * Invoked before classloading is attempted to allow a preload attempt, e.g. from the parent
+    * 
+    * @param name the class resource name
+    * @return the loader if found or null otherwise
+    */
+   protected abstract Loader findBeforeLoader(String name);
+   
+   /**
+    * Invoked after classloading is attempted to allow a postload attempt, e.g. from the parent
+    * 
+    * @param name the class resource name
+    * @return the loader if found or null otherwise
+    */
+   protected abstract Loader findAfterLoader(String name);
+   
+   /**
+    * Invoked before getResources is attempted to allow a preload attempt, e.g. from the parent
+    * 
+    * @param name the resource name
+    * @param urls the urls to add to
+    * @throws IOException for any error
+    */
+   protected abstract void beforeGetResources(String name,  Set<URL> urls) throws IOException;
+   
+   /**
+    * Invoked after getResources is attempted to allow a postload attempt, e.g. from the parent
+    * 
+    * @param name the resource name
+    * @param urls the urls to add to
+    * @throws IOException for any error
+    */
+   protected abstract void afterGetResources(String name, Set<URL> urls) throws IOException;
+   
+   /**
+    * Invoked before getResource is attempted to allow a preload attempt, e.g. from the parent
+    * 
+    * @param name the resource name
+    * @return the url if found or null otherwise
+    */
+   protected abstract URL beforeGetResource(String name);
+   
+   /**
+    * Invoked after getResource is attempted to allow a postload attempt, e.g. from the parent
+    * 
+    * @param name the resource name
+    * @return the url if found or null otherwise
+    */
+   protected abstract URL afterGetResource(String name);
+   
+   /**
+    * Invoked before getPackages is attempted to allow a preload attempt, e.g. from the parent
+    * 
+    * @param packages the packages to add to
+    */
+   protected abstract void beforeGetPackages(Set<Package> packages);
+   
+   /**
+    * Invoked after getPackages is attempted to allow a postload attempt, e.g. from the parent
+    * 
+    * @param packages the packages to add to
+    */
+   protected abstract void afterGetPackages(Set<Package> packages);
+   
+   /**
+    * Invoked before getPackage is attempted to allow a preload attempt, e.g. from the parent
+    * 
+    * @param name the package name
+    * @return the package if found or null otherwise
+    */
+   protected abstract Package beforeGetPackage(String name);
+   
+   /**
+    * Invoked after getPackage is attempted to allow a postload attempt, e.g. from the parent
+    * 
+    * @param name the package name
+    * @return the url if found or null otherwise
+    */
+   protected abstract Package afterGetPackage(String name);
+   
+   public Class<?> loadClass(String name)
+   {
+      try
+      {
+         return loadClass(null, name, true);
+      }
+      catch (ClassNotFoundException e)
+      {
+         return null;
+      }
+   }
+   
+   /**
+    * Load a class from the domain
+    * 
+    * @param classLoader the classloader
+    * @param name the class name
+    * @return the class
+    * @throws ClassNotFoundException for any error
+    */
+   Class<?> loadClass(BaseClassLoader classLoader, String name) throws ClassNotFoundException
+   {
+      return loadClass(classLoader, name, false);
+   }
+   
+   public URL getResource(String name)
+   {
+      return getResource(null, name, true);
+   }
+   
+   /**
+    * Get a resource from the domain
+    * 
+    * @param classLoader the classloader
+    * @param name the resource name
+    * @return the url
+    */
+   URL getResource(BaseClassLoader classLoader, String name)
+   {
+      return getResource(classLoader, name, false);
+   }
+   
+   public void getResources(String name, Set<URL> urls) throws IOException
+   {
+      getResources(null, name, urls, true);
+   }
+   
+   /**
+    * Get a resource from the domain
+    * 
+    * @param classLoader the classloader
+    * @param name the resource name
+    * @param urls the urls to add to
+    * @throws IOException for any error
+    */
+   void getResources(BaseClassLoader classLoader, String name, Set<URL> urls) throws IOException
+   {
+      getResources(classLoader, name, urls, false);
+   }
+   
+   public Package getPackage(String name)
+   {
+      return getPackage(null, name, true);
+   }
+   
+   /**
+    * Get a package from the specified classloader
+    * 
+    * @param classLoader the classloader
+    * @param name the package name
+    * @return the package
+    */
+   Package getPackage(BaseClassLoader classLoader, String name)
+   {
+      return getPackage(classLoader, name, false);
+   }
+   
+   public void getPackages(Set<Package> packages)
+   {
+      getPackages(null, packages, true);
+   }
+   
+   /**
+    * Get the packages from a specified classloader 
+    * 
+    * @param classLoader the classloader
+    * @param packages the packages
+    */
+   void getPackages(BaseClassLoader classLoader, Set<Package> packages)
+   {
+      getPackages(classLoader, packages, false);
+   }
+
+   /**
+    * A long version of toString()
+    * 
+    * @return the long string
+    */
+   public String toLongString()
+   {
+      StringBuilder builder = new StringBuilder();
+      builder.append(getClass().getSimpleName());
+      builder.append("@").append(Integer.toHexString(System.identityHashCode(this)));
+      builder.append("{");
+      toLongString(builder);
+      builder.append('}');
+      return builder.toString();
+   }
+   
+   /**
+    * For subclasses to add information for toLongString()
+    * 
+    * @param builder the builder
+    */
+   protected void toLongString(StringBuilder builder)
+   {
+   }
+   
+   /**
+    * Invoked before adding a classloader policy 
+    * 
+    * @param classLoader the classloader
+    * @param policy the classloader policy
+    */
+   protected void beforeRegisterClassLoader(ClassLoader classLoader, ClassLoaderPolicy policy)
+   {
+      // nothing
+   }
+
+   /**
+    * Invoked after adding a classloader policy 
+    * 
+    * @param classLoader the classloader
+    * @param policy the classloader policy
+    */
+   protected void afterRegisterClassLoader(ClassLoader classLoader, ClassLoaderPolicy policy)
+   {
+      // nothing
+   }
+   
+   /**
+    * Invoked before adding a classloader policy 
+    * 
+    * @param classLoader the classloader
+    * @param policy the classloader policy
+    */
+   protected void beforeUnregisterClassLoader(ClassLoader classLoader, ClassLoaderPolicy policy)
+   {
+      // nothing
+   }
+   
+   /**
+    * Invoked after adding a classloader policy 
+    * 
+    * @param classLoader the classloader
+    * @param policy the classloader policy
+    */
+   protected void afterUnregisterClassLoader(ClassLoader classLoader, ClassLoaderPolicy policy)
+   {
+      // nothing
+   }
+
+   /**
+    * Get the parent classloader
+    * 
+    * @return the parent classloader
+    */
+   protected ClassLoader getParentClassLoader()
+   {
+      return getClass().getClassLoader();
+   }
+
+   /**
+    * Register a classloader 
+    * 
+    * @param classLoader the classloader
+    */
+   void registerClassLoader(BaseClassLoader classLoader)
+   {
+      log.debug(this + " registerClassLoader " + classLoader.toString());
+
+      if (getClassLoaderSystem() == null)
+         throw new IllegalStateException("Domain is not registered with a classloader system: " + toLongString());
+      
+      ClassLoaderPolicy policy = classLoader.getPolicy();
+      BaseDelegateLoader exported = policy.getExported();
+      if (exported != null && exported.getPolicy() == null)
+         throw new IllegalStateException("The exported delegate " + exported + " is too lazy for " + policy.toLongString());
+      
+      try
+      {
+         beforeRegisterClassLoader(classLoader, policy);
+      }
+      catch (Throwable t)
+      {
+         log.warn("Error in beforeRegisterClassLoader: " + this + " classLoader=" + classLoader.toLongString(), t);
+      }
+      
+      BaseClassLoaderPolicy basePolicy = classLoader.getPolicy();
+      basePolicy.setClassLoaderDomain(this);
+
+      synchronized (classLoaders)
+      {
+         // Create the information
+         ClassLoaderInformation info = new ClassLoaderInformation(classLoader, policy, order++);
+         classLoaders.add(info);
+         infos.put(classLoader, info);
+
+         // Index the packages
+         String[] packageNames = policy.getPackageNames();
+         if (packageNames != null && info.getExported() != null)
+         {
+            for (String packageName : packageNames)
+            {
+               List<ClassLoaderInformation> list = classLoadersByPackageName.get(packageName);
+               if (list == null)
+               {
+                  list = new CopyOnWriteArrayList<ClassLoaderInformation>();
+                  classLoadersByPackageName.put(packageName, list);
+               }
+               list.add(info);
+               log.trace("Registered " + policy + " as providing package=" + packageName);
+            }
+         }
+         
+         flushCaches();
+      }
+
+      try
+      {
+         afterRegisterClassLoader(classLoader, classLoader.getPolicy());
+      }
+      catch (Throwable t)
+      {
+         log.warn("Error in afterRegisterClassLoader: " + this + " classLoader=" + classLoader.toLongString(), t);
+      }
+   }
+   
+   /**
+    * Remove a classloader 
+    * 
+    * @param classLoader the classloader
+    */
+   void unregisterClassLoader(BaseClassLoader classLoader)
+   {
+      log.debug(this + " unregisterClassLoader " + classLoader.toString());
+
+      try
+      {
+         beforeUnregisterClassLoader(classLoader, classLoader.getPolicy());
+      }
+      catch (Throwable t)
+      {
+         log.warn("Error in beforeUnegisterClassLoader: " + this + " classLoader=" + classLoader.toLongString(), t);
+      }
+
+      BaseClassLoaderPolicy policy = classLoader.getPolicy();
+      policy.unsetClassLoaderDomain(this);
+
+      synchronized (classLoaders)
+      {
+         // Remove the classloader
+         ClassLoaderInformation info = infos.remove(classLoader);
+         classLoaders.remove(info);
+         
+         // Remove the package index
+         String[] packageNames = policy.getPackageNames();
+         if (packageNames != null && info.getExported() != null)
+         {
+            for (String packageName : packageNames)
+            {
+               List<ClassLoaderInformation> list = classLoadersByPackageName.get(packageName);
+               if (list != null)
+               {
+                  list.remove(info);
+                  log.trace("Unregistered " + policy + " as providing package=" + packageName);
+                  if (list.isEmpty())
+                     classLoadersByPackageName.remove(packageName);
+               }
+            }
+         }
+
+         flushCaches();
+      }
+
+      try
+      {
+         afterUnregisterClassLoader(classLoader, classLoader.getPolicy());
+      }
+      catch (Throwable t)
+      {
+         log.warn("Error in afterUnegisterClassLoader: " + this + " classLoader=" + classLoader.toLongString(), t);
+      }
+   }
+
+   /**
+    * Get all the classloaders
+    * 
+    * @return the list of classloaders
+    */
+   protected List<ClassLoader> getAllClassLoaders()
+   {
+      List<ClassLoader> result = new ArrayList<ClassLoader>();
+      for (ClassLoaderInformation info : classLoaders)
+         result.add(info.getClassLoader());
+      return result;
+   }
+
+   /**
+    * Get a map of packages to classloader
+    * 
+    * @return a map of packages to a list of classloaders for that package
+    */
+   protected Map<String, List<ClassLoader>> getClassLoadersByPackage()
+   {
+      HashMap<String, List<ClassLoader>> result = new HashMap<String, List<ClassLoader>>();
+      for (Entry<String, List<ClassLoaderInformation>> entry : classLoadersByPackageName.entrySet())
+      {
+         List<ClassLoader> cls = new ArrayList<ClassLoader>();
+         for (ClassLoaderInformation info : entry.getValue())
+            cls.add(info.getClassLoader());
+         result.put(entry.getKey(), cls);
+      }
+      return result;
+   }
+
+   protected List<ClassLoader> getClassLoaders(String packageName)
+   {
+      if (packageName == null)
+         throw new IllegalArgumentException("Null package name");
+      
+      List<ClassLoader> result = new ArrayList<ClassLoader>();
+      List<ClassLoaderInformation> infos = classLoadersByPackageName.get(packageName);
+      if (infos != null)
+      {
+         for (ClassLoaderInformation info : infos)
+            result.add(info.getClassLoader());
+      }
+      return result;
+   }
+
+   /**
+    * Cleans the entry with the given name from the blackList
+    *
+    * @param name the name of the resource to clear from the blackList
+    */
+   protected void clearBlackList(String name)
+   {
+      if (globalClassBlackList != null)
+      {
+         globalClassBlackList.remove(name);
+      }
+      if (globalResourceBlackList != null)
+      {
+         globalResourceBlackList.remove(name);
+      }
+   }
+   
+}

Deleted: projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderSource.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderSource.java	2009-01-27 11:39:59 UTC (rev 83468)
+++ projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderSource.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -1,56 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2007, 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.classloader.spi.base;
-
-/**
- * BaseClassLoaderSource.
- * 
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class BaseClassLoaderSource
-{
-   /** The classloader */
-   private ClassLoader classLoader;
-
-   /**
-    * Create a new BaseClassLoaderSource.
-    * 
-    * @param classLoader the classloader
-    */
-   public BaseClassLoaderSource(ClassLoader classLoader)
-   {
-      if (classLoader == null)
-         throw new IllegalArgumentException("Null classLoader");
-      this.classLoader = classLoader;
-   }
-   
-   /**
-    * Get the classloader
-    * 
-    * @return the classloader
-    */
-   protected ClassLoader getClassLoader()
-   {
-      return classLoader;
-   }
-}

Copied: projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderSource.java (from rev 83469, projects/jboss-cl/branches/Branch_2_0/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderSource.java)
===================================================================
--- projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderSource.java	                        (rev 0)
+++ projects/jboss-cl/tags/2.0.2.GA/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoaderSource.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.classloader.spi.base;
+
+/**
+ * BaseClassLoaderSource.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class BaseClassLoaderSource
+{
+   /** The classloader */
+   private ClassLoader classLoader;
+
+   /**
+    * Create a new BaseClassLoaderSource.
+    * 
+    * @param classLoader the classloader
+    */
+   public BaseClassLoaderSource(ClassLoader classLoader)
+   {
+      if (classLoader == null)
+         throw new IllegalArgumentException("Null classLoader");
+      this.classLoader = classLoader;
+   }
+   
+   /**
+    * Get the classloader
+    * 
+    * @return the classloader
+    */
+   protected ClassLoader getClassLoader()
+   {
+      return classLoader;
+   }
+}

Deleted: projects/jboss-cl/tags/2.0.2.GA/classloading/pom.xml
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading/pom.xml	2009-01-27 11:39:59 UTC (rev 83468)
+++ projects/jboss-cl/tags/2.0.2.GA/classloading/pom.xml	2009-01-27 13:22:11 UTC (rev 83485)
@@ -1,126 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <parent>
-    <groupId>org.jboss.cl</groupId>
-    <artifactId>jboss-cl</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-  <artifactId>jboss-classloading</artifactId>
-  <packaging>jar</packaging>
-  <name>JBoss ClassLoading</name>
-  <url>http://www.jboss.org/jbossmc</url>
-  <description>JBoss ClassLoading</description>
-  
-  <!-- Do not add version information here, use ../pom.xml instead -->
-  <dependencies>
-  
-    <!-- Global dependencies -->
-    <dependency>
-      <groupId>org.jboss</groupId>
-      <artifactId>jboss-common-core</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.logging</groupId>
-      <artifactId>jboss-logging-spi</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.cl</groupId>
-      <artifactId>jboss-classloader</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.microcontainer</groupId>
-      <artifactId>jboss-dependency</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-common-core</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>jboss</groupId>
-          <artifactId>jboss-common-logging-spi</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.microcontainer</groupId>
-      <artifactId>jboss-kernel</artifactId>
-      <optional>true</optional>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss.microcontainer</groupId>
-          <artifactId>jboss-dependency</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-common-core</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>jboss</groupId>
-          <artifactId>jboss-common-logging-spi</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jbossxb</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss</groupId>
-      <artifactId>jbossxb</artifactId>
-      <optional>true</optional>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-reflect</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-common-core</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>jboss</groupId>
-          <artifactId>jboss-common-logging-spi</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.man</groupId>
-      <artifactId>jboss-managed</artifactId>
-      <optional>true</optional>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-reflect</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-common-core</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>jboss</groupId>
-          <artifactId>jboss-common-logging-spi</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    
-    <!-- Test dependencies -->
-    <dependency>
-      <groupId>org.jboss.test</groupId>
-      <artifactId>jboss-test</artifactId>
-      <scope>test</scope>
-    </dependency>
-    
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
-    
-  </dependencies>  
-</project>
\ No newline at end of file

Copied: projects/jboss-cl/tags/2.0.2.GA/classloading/pom.xml (from rev 83484, projects/jboss-cl/branches/Branch_2_0/classloading/pom.xml)
===================================================================
--- projects/jboss-cl/tags/2.0.2.GA/classloading/pom.xml	                        (rev 0)
+++ projects/jboss-cl/tags/2.0.2.GA/classloading/pom.xml	2009-01-27 13:22:11 UTC (rev 83485)
@@ -0,0 +1,126 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.jboss.cl</groupId>
+    <artifactId>jboss-cl</artifactId>
+    <version>2.0.2.GA</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>jboss-classloading</artifactId>
+  <packaging>jar</packaging>
+  <name>JBoss ClassLoading</name>
+  <url>http://www.jboss.org/jbossmc</url>
+  <description>JBoss ClassLoading</description>
+  
+  <!-- Do not add version information here, use ../pom.xml instead -->
+  <dependencies>
+  
+    <!-- Global dependencies -->
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-common-core</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-spi</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.cl</groupId>
+      <artifactId>jboss-classloader</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-dependency</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-common-core</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>jboss</groupId>
+          <artifactId>jboss-common-logging-spi</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-kernel</artifactId>
+      <optional>true</optional>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss.microcontainer</groupId>
+          <artifactId>jboss-dependency</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-common-core</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>jboss</groupId>
+          <artifactId>jboss-common-logging-spi</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jbossxb</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jbossxb</artifactId>
+      <optional>true</optional>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-reflect</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-common-core</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>jboss</groupId>
+          <artifactId>jboss-common-logging-spi</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.man</groupId>
+      <artifactId>jboss-managed</artifactId>
+      <optional>true</optional>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-reflect</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-common-core</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>jboss</groupId>
+          <artifactId>jboss-common-logging-spi</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <!-- Test dependencies -->
+    <dependency>
+      <groupId>org.jboss.test</groupId>
+      <artifactId>jboss-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
+  </dependencies>  
+</project>
\ No newline at end of file

Deleted: projects/jboss-cl/tags/2.0.2.GA/classloading/src/main/java/org/jboss/classloading/spi/dependency/ClassLoadingSpace.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading/src/main/java/org/jboss/classloading/spi/dependency/ClassLoadingSpace.java	2009-01-27 11:39:59 UTC (rev 83468)
+++ projects/jboss-cl/tags/2.0.2.GA/classloading/src/main/java/org/jboss/classloading/spi/dependency/ClassLoadingSpace.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -1,346 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2007, 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.classloading.spi.dependency;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.jboss.classloading.spi.metadata.Requirement;
-import org.jboss.logging.Logger;
-
-/**
- * ClassLoadingSpace. This class does two stage join/resolve<p>
- *
- * join - work out a module's capabilities/requirements and validate they are not inconsistent with what is already there
- * resolve - resolve new requirements and potentially join with other spaces
- * unjoin - remove a module from the space
- * unresolve - work out the new state after a module splits
- *
- * TODO JBCL-25 handle split packages
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class ClassLoadingSpace
-{
-   /** The log */
-   private static final Logger log = Logger.getLogger(ClassLoadingSpace.class);
-
-   /** Whether trace is enabled */
-   private static boolean trace = log.isTraceEnabled();
-
-   /** The modules */
-   private Map<Module, Module> modules = new ConcurrentHashMap<Module, Module>();
-
-   /** The modules by package */
-   private Map<String, Module> modulesByPackage = new ConcurrentHashMap<String, Module>();
-
-   /** The requirements for all modules */
-   private Map<Module, List<RequirementDependencyItem>> requirements = new ConcurrentHashMap<Module, List<RequirementDependencyItem>>();
-
-   /**
-    * Get an unmodifiable set of the collections
-    *
-    * @return the modules
-    */
-   public Set<Module> getModules()
-   {
-      return Collections.unmodifiableSet(modules.keySet());
-   }
-
-   /**
-    * Join and resolve a module
-    *
-    * @param module the module to add
-    * @throws IllegalArgumentException for a null module
-    */
-   synchronized void joinAndResolve(Module module)
-   {
-      if (module == null)
-         throw new IllegalArgumentException("Null module");
-
-      trace = log.isTraceEnabled();
-
-      join(module);
-      try
-      {
-         resolve(module);
-      }
-      catch (Throwable t)
-      {
-         split(module);
-         if (t instanceof RuntimeException)
-            throw (RuntimeException) t;
-         if (t instanceof Error)
-            throw (Error) t;
-         throw new RuntimeException(modules + " could not join " + this, t);
-      }
-   }
-
-   /**
-    * Join with a set of modules
-    *
-    * @param modules the modules
-    * @throws IllegalArgumentException for null modules
-    */
-   synchronized void joinAndResolve(Set<Module> modules)
-   {
-      if (modules == null)
-         throw new IllegalArgumentException("Null modules");
-
-      Map<Module, ClassLoadingSpace> previous = new HashMap<Module, ClassLoadingSpace>();
-      try
-      {
-         for (Module module : modules)
-         {
-            ClassLoadingSpace space = module.getClassLoadingSpace();
-            join(module);
-            previous.put(module, space);
-            resolve(module);
-         }
-      }
-      catch (Throwable t)
-      {
-         // Revert the previous joins
-         for (Entry<Module, ClassLoadingSpace> entry : previous.entrySet())
-         {
-            Module module = entry.getKey();
-            ClassLoadingSpace space = entry.getValue();
-
-            split(module);
-            try
-            {
-               space.join(module);
-            }
-            catch (Throwable t2)
-            {
-               log.error(module + " could not join " + space, t);
-               throw new RuntimeException("BUG: " + module + " could not rejoin " + space + " after failing to join " + this, t2);
-            }
-         }
-         if (t instanceof RuntimeException)
-            throw (RuntimeException) t;
-         if (t instanceof Error)
-            throw (Error) t;
-         throw new RuntimeException(modules + " could not join " + this, t);
-      }
-   }
-
-   /**
-    * Join with a classloading space
-    *
-    * @param space the classloading space
-    * @throws IllegalArgumentException for null space
-    */
-   void joinAndResolve(ClassLoadingSpace space)
-   {
-      if (space == null)
-         throw new IllegalArgumentException("Null space");
-      if (space == this)
-         return;
-
-      int ourSize = getModules().size();
-      int otherSize = space.getModules().size();
-
-      if (ourSize >= otherSize)
-         joinAndResolve(space.getModules());
-      else
-         space.joinAndResolve(getModules());
-   }
-
-   /**
-    * Split with a module
-    *
-    * @param module the module to remove
-    * @throws IllegalArgumentException for a null module
-    * @throws IllegalStateException if the module is not associated with this classloading space
-    */
-   synchronized void split(Module module)
-   {
-      if (module == null)
-         throw new IllegalArgumentException("Null module");
-
-      ClassLoadingSpace other = module.getClassLoadingSpace();
-      if (other != this)
-         throw new IllegalStateException(module + " has the wrong classloading space: expected=" + this + " was " + other);
-
-      unjoin(module);
-      unresolve(module);
-   }
-
-   /**
-    * Join with a module
-    *
-    * @param module the module to add
-    * @throws IllegalArgumentException for a null module
-    */
-   synchronized void join(Module module)
-   {
-      if (module == null)
-         throw new IllegalArgumentException("Null module");
-      // Nothing to do
-      ClassLoadingSpace other = module.getClassLoadingSpace();
-      if (other == this)
-         return;
-
-      if (trace)
-         log.trace(module + " joining " + this);
-
-      // The packages exported by this module (excluding optional packages)
-      List<String> exportedPackages = module.determinePackageNames(false);
-
-      // Check there are no conflicting packages
-      if (exportedPackages != null && exportedPackages.isEmpty() == false)
-      {
-         for (String exportedPackage : exportedPackages)
-         {
-            Module otherModule = modulesByPackage.get(exportedPackage);
-            // TODO JBCL-22 ERRORS
-            if (otherModule != null)
-               throw new IllegalStateException(module + " cannot be added because it is exports package " + exportedPackage + " which conflicts with " + otherModule);
-         }
-      }
-
-      // Check our requirements are consistent with the other requirements
-      List<RequirementDependencyItem> moduleDependencies = module.getDependencies();
-      if (requirements.isEmpty() == false)
-      {
-         if (moduleDependencies != null && moduleDependencies.isEmpty() == false)
-         {
-            for (RequirementDependencyItem dependency : moduleDependencies)
-            {
-               Requirement requirement = dependency.getRequirement();
-               for (Entry<Module, List<RequirementDependencyItem>> entry : requirements.entrySet())
-               {
-                  Module otherModule = entry.getKey();
-                  List<RequirementDependencyItem> dependencies = entry.getValue();
-                  for (RequirementDependencyItem otherDependency : dependencies)
-                  {
-                     Requirement otherRequirement = otherDependency.getRequirement();
-                     // TODO JBCL-22 ERRORS
-                     if (requirement.isConsistent(otherRequirement) == false)
-                        throw new IllegalStateException(module + " has a requirement " + requirement + " which is inconsistent with " + otherRequirement + " from " + otherModule);
-                  }
-               }
-            }
-         }
-      }
-
-      // Update the exported packages
-      if (exportedPackages != null && exportedPackages.isEmpty() == false)
-      {
-         for (String exportedPackage : exportedPackages)
-            modulesByPackage.put(exportedPackage, module);
-      }
-
-      // Remember the module requirements
-      if (moduleDependencies != null && moduleDependencies.isEmpty() == false)
-         requirements.put(module, moduleDependencies);
-
-      // Remove from any previous space
-      if (other != null)
-         other.split(module);
-
-      // This module is now part of our space
-      modules.put(module, module);
-      module.setClassLoadingSpace(this);
-   }
-
-   /**
-    * Unjoin a module
-    *
-    * @param module the module to remove
-    */
-   private void unjoin(Module module)
-   {
-      if (trace)
-         log.trace(module + " unjoining " + this);
-
-      // Remove the exported packages for this module
-      List<String> packageNames = module.determinePackageNames(false);
-      if (packageNames != null)
-      {
-         for (String packageName : packageNames)
-         {
-            Module removed = modulesByPackage.remove(packageName);
-            if (removed != module)
-               throw new IllegalStateException("BUG: Removed module " + removed + " for package " + packageName + " is not the expected module: " + module);
-         }
-      }
-
-      // Remove the module requirements from the classloading space
-      requirements.remove(module);
-
-      // No longer part of this classloading space
-      modules.remove(module);
-      module.setClassLoadingSpace(null);
-   }
-
-   /**
-    * Resolve a module
-    *
-    * @param module the module to resolve
-    */
-   synchronized void resolve(Module module)
-   {
-      if (trace)
-         log.trace(module + " resolving " + this);
-
-      List<RequirementDependencyItem> moduleDependencies = requirements.get(module);
-      if (moduleDependencies != null)
-      {
-         for (RequirementDependencyItem dependency : moduleDependencies)
-         {
-            if (dependency.isResolved() == false)
-            {
-               Module otherModule = module.resolveModule(dependency, false);
-               if (otherModule != null)
-               {
-                  // Do we need to join with another classloading space?
-                  ClassLoadingSpace space = otherModule.getClassLoadingSpace();
-                  if (space != null && space != this)
-                  {
-                     space.joinAndResolve(this);
-                  }
-               }
-            }
-         }
-      }
-   }
-
-   /**
-    * Unresolve a module
-    *
-    * @param module the module to resolve
-    */
-   private void unresolve(Module module)
-   {
-      if (trace)
-         log.trace(module + " unresolving " + this);
-
-      // Nothing yet. Could try to split classloading spaces if they now have disjoint subsets?
-   }
-}

Copied: projects/jboss-cl/tags/2.0.2.GA/classloading/src/main/java/org/jboss/classloading/spi/dependency/ClassLoadingSpace.java (from rev 83469, projects/jboss-cl/branches/Branch_2_0/classloading/src/main/java/org/jboss/classloading/spi/dependency/ClassLoadingSpace.java)
===================================================================
--- projects/jboss-cl/tags/2.0.2.GA/classloading/src/main/java/org/jboss/classloading/spi/dependency/ClassLoadingSpace.java	                        (rev 0)
+++ projects/jboss-cl/tags/2.0.2.GA/classloading/src/main/java/org/jboss/classloading/spi/dependency/ClassLoadingSpace.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -0,0 +1,346 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.classloading.spi.dependency;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.logging.Logger;
+
+/**
+ * ClassLoadingSpace. This class does two stage join/resolve<p>
+ * 
+ * join - work out a module's capabilities/requirements and validate they are not inconsistent with what is already there
+ * resolve - resolve new requirements and potentially join with other spaces
+ * unjoin - remove a module from the space
+ * unresolve - work out the new state after a module splits
+ * 
+ * TODO JBCL-25 handle split packages
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassLoadingSpace
+{
+   /** The log */
+   private static final Logger log = Logger.getLogger(ClassLoadingSpace.class);
+
+   /** Whether trace is enabled */
+   private static boolean trace = log.isTraceEnabled();
+   
+   /** The modules */
+   private Map<Module, Module> modules = new ConcurrentHashMap<Module, Module>();
+
+   /** The modules by package */
+   private Map<String, Module> modulesByPackage = new ConcurrentHashMap<String, Module>();
+   
+   /** The requirements for all modules */
+   private Map<Module, List<RequirementDependencyItem>> requirements = new ConcurrentHashMap<Module, List<RequirementDependencyItem>>();
+   
+   /**
+    * Get an unmodifiable set of the collections
+    * 
+    * @return the modules
+    */
+   public Set<Module> getModules()
+   {
+      return Collections.unmodifiableSet(modules.keySet());
+   }
+   
+   /**
+    * Join and resolve a module
+    * 
+    * @param module the module to add
+    * @throws IllegalArgumentException for a null module
+    */
+   synchronized void joinAndResolve(Module module)
+   {
+      if (module == null)
+         throw new IllegalArgumentException("Null module");
+
+      trace = log.isTraceEnabled();
+   
+      join(module);
+      try
+      {
+         resolve(module);
+      }
+      catch (Throwable t)
+      {
+         split(module);
+         if (t instanceof RuntimeException)
+            throw (RuntimeException) t;
+         if (t instanceof Error)
+            throw (Error) t;
+         throw new RuntimeException(modules + " could not join " + this, t);
+      }
+   }
+   
+   /**
+    * Join with a set of modules
+    * 
+    * @param modules the modules
+    * @throws IllegalArgumentException for null modules
+    */
+   synchronized void joinAndResolve(Set<Module> modules)
+   {
+      if (modules == null)
+         throw new IllegalArgumentException("Null modules");
+
+      Map<Module, ClassLoadingSpace> previous = new HashMap<Module, ClassLoadingSpace>();
+      try
+      {
+         for (Module module : modules)
+         {
+            ClassLoadingSpace space = module.getClassLoadingSpace();
+            join(module);
+            previous.put(module, space);
+            resolve(module);
+         }
+      }
+      catch (Throwable t)
+      {
+         // Revert the previous joins
+         for (Entry<Module, ClassLoadingSpace> entry : previous.entrySet())
+         {
+            Module module = entry.getKey();
+            ClassLoadingSpace space = entry.getValue();
+            
+            split(module);
+            try
+            {
+               space.join(module);
+            }
+            catch (Throwable t2)
+            {
+               log.error(module + " could not join " + space, t);
+               throw new RuntimeException("BUG: " + module + " could not rejoin " + space + " after failing to join " + this, t2);
+            }
+         }
+         if (t instanceof RuntimeException)
+            throw (RuntimeException) t;
+         if (t instanceof Error)
+            throw (Error) t;
+         throw new RuntimeException(modules + " could not join " + this, t);
+      }
+   }
+
+   /**
+    * Join with a classloading space
+    * 
+    * @param space the classloading space
+    * @throws IllegalArgumentException for null space
+    */
+   void joinAndResolve(ClassLoadingSpace space)
+   {
+      if (space == null)
+         throw new IllegalArgumentException("Null space");
+      if (space == this)
+         return;
+      
+      int ourSize = getModules().size();
+      int otherSize = space.getModules().size();
+      
+      if (ourSize >= otherSize)
+         joinAndResolve(space.getModules());
+      else
+         space.joinAndResolve(getModules());
+   }
+   
+   /**
+    * Split with a module
+    * 
+    * @param module the module to remove
+    * @throws IllegalArgumentException for a null module
+    * @throws IllegalStateException if the module is not associated with this classloading space
+    */
+   synchronized void split(Module module)
+   {
+      if (module == null)
+         throw new IllegalArgumentException("Null module");
+
+      ClassLoadingSpace other = module.getClassLoadingSpace();
+      if (other != this)
+         throw new IllegalStateException(module + " has the wrong classloading space: expected=" + this + " was " + other);
+
+      unjoin(module);
+      unresolve(module);
+   }
+   
+   /**
+    * Join with a module
+    * 
+    * @param module the module to add
+    * @throws IllegalArgumentException for a null module
+    */
+   synchronized void join(Module module)
+   {
+      if (module == null)
+         throw new IllegalArgumentException("Null module");
+      // Nothing to do
+      ClassLoadingSpace other = module.getClassLoadingSpace();
+      if (other == this)
+         return;
+      
+      if (trace)
+         log.trace(module + " joining " + this);
+
+      // The packages exported by this module (excluding optional packages)
+      List<String> exportedPackages = module.determinePackageNames(false);
+
+      // Check there are no conflicting packages
+      if (exportedPackages != null && exportedPackages.isEmpty() == false)
+      {
+         for (String exportedPackage : exportedPackages)
+         {
+            Module otherModule = modulesByPackage.get(exportedPackage);
+            // TODO JBCL-22 ERRORS
+            if (otherModule != null)
+               throw new IllegalStateException(module + " cannot be added because it is exports package " + exportedPackage + " which conflicts with " + otherModule);
+         }
+      }
+
+      // Check our requirements are consistent with the other requirements
+      List<RequirementDependencyItem> moduleDependencies = module.getDependencies();
+      if (requirements.isEmpty() == false)
+      {
+         if (moduleDependencies != null && moduleDependencies.isEmpty() == false)
+         {
+            for (RequirementDependencyItem dependency : moduleDependencies)
+            {
+               Requirement requirement = dependency.getRequirement();
+               for (Entry<Module, List<RequirementDependencyItem>> entry : requirements.entrySet())
+               {
+                  Module otherModule = entry.getKey();
+                  List<RequirementDependencyItem> dependencies = entry.getValue();
+                  for (RequirementDependencyItem otherDependency : dependencies)
+                  {
+                     Requirement otherRequirement = otherDependency.getRequirement();
+                     // TODO JBCL-22 ERRORS
+                     if (requirement.isConsistent(otherRequirement) == false)
+                        throw new IllegalStateException(module + " has a requirement " + requirement + " which is inconsistent with " + otherRequirement + " from " + otherModule);
+                  }
+               }
+            }
+         }
+      }
+      
+      // Update the exported packages
+      if (exportedPackages != null && exportedPackages.isEmpty() == false)
+      {
+         for (String exportedPackage : exportedPackages)
+            modulesByPackage.put(exportedPackage, module);
+      }
+      
+      // Remember the module requirements
+      if (moduleDependencies != null && moduleDependencies.isEmpty() == false)
+         requirements.put(module, moduleDependencies);
+      
+      // Remove from any previous space
+      if (other != null)
+         other.split(module);
+      
+      // This module is now part of our space
+      modules.put(module, module);
+      module.setClassLoadingSpace(this);
+   }
+   
+   /**
+    * Unjoin a module
+    * 
+    * @param module the module to remove
+    */
+   private void unjoin(Module module)
+   {
+      if (trace)
+         log.trace(module + " unjoining " + this);
+      
+      // Remove the exported packages for this module
+      List<String> packageNames = module.determinePackageNames(false);
+      if (packageNames != null)
+      {
+         for (String packageName : packageNames)
+         {
+            Module removed = modulesByPackage.remove(packageName);
+            if (removed != module)
+               throw new IllegalStateException("BUG: Removed module " + removed + " for package " + packageName + " is not the expected module: " + module);
+         }
+      }
+
+      // Remove the module requirements from the classloading space
+      requirements.remove(module);
+      
+      // No longer part of this classloading space
+      modules.remove(module);
+      module.setClassLoadingSpace(null);
+   }
+   
+   /**
+    * Resolve a module
+    * 
+    * @param module the module to resolve
+    */
+   synchronized void resolve(Module module)
+   {
+      if (trace)
+         log.trace(module + " resolving " + this);
+
+      List<RequirementDependencyItem> moduleDependencies = requirements.get(module);
+      if (moduleDependencies != null)
+      {
+         for (RequirementDependencyItem dependency : moduleDependencies)
+         {
+            if (dependency.isResolved() == false)
+            {
+               Module otherModule = module.resolveModule(dependency, false);
+               if (otherModule != null)
+               {
+                  // Do we need to join with another classloading space?
+                  ClassLoadingSpace space = otherModule.getClassLoadingSpace();
+                  if (space != null && space != this)
+                  {
+                     space.joinAndResolve(this);
+                  }
+               }
+            }
+         }
+      }
+   }
+   
+   /**
+    * Unresolve a module
+    * 
+    * @param module the module to resolve
+    */
+   private void unresolve(Module module)
+   {
+      if (trace)
+         log.trace(module + " unresolving " + this);
+      
+      // Nothing yet. Could try to split classloading spaces if they now have disjoint subsets?
+   }
+}

Deleted: projects/jboss-cl/tags/2.0.2.GA/classloading/src/main/java/org/jboss/classloading/spi/dependency/Module.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading/src/main/java/org/jboss/classloading/spi/dependency/Module.java	2009-01-27 11:39:59 UTC (rev 83468)
+++ projects/jboss-cl/tags/2.0.2.GA/classloading/src/main/java/org/jboss/classloading/spi/dependency/Module.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -1,940 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2007, 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.classloading.spi.dependency;
-
-import java.io.IOException;
-import java.net.URL;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.jboss.classloader.spi.ClassLoaderSystem;
-import org.jboss.classloader.spi.DelegateLoader;
-import org.jboss.classloader.spi.ParentPolicy;
-import org.jboss.classloader.spi.filter.ClassFilter;
-import org.jboss.classloading.spi.helpers.NameAndVersionSupport;
-import org.jboss.classloading.spi.metadata.Capability;
-import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
-import org.jboss.classloading.spi.metadata.ExportAll;
-import org.jboss.classloading.spi.metadata.ExportPackages;
-import org.jboss.classloading.spi.metadata.OptionalPackages;
-import org.jboss.classloading.spi.metadata.Requirement;
-import org.jboss.classloading.spi.visitor.ResourceFilter;
-import org.jboss.classloading.spi.visitor.ResourceVisitor;
-import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.dependency.spi.ControllerState;
-
-/**
- * Module.
- * 
- * @author <a href="adrian at jboss.org">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public abstract class Module extends NameAndVersionSupport
-{
-   /** The modules by classloader */
-   private static Map<ClassLoader, Module> modulesByClassLoader = new ConcurrentHashMap<ClassLoader, Module>();
-   
-   /** The context name */
-   private String contextName;
-   
-   /** Our cached capabilities */
-   private List<Capability> capabilities;
-   
-   /** Our cached requirements */
-   private List<Requirement> requirements;
-
-   /** The controller context */
-   private ControllerContext context;
-
-   /** The domain */
-   private Domain domain;
-
-   /** The classloading space */
-   private ClassLoadingSpace space;
-   
-   /** The requirements */
-   private List<RequirementDependencyItem> requirementDependencies;
-
-   /**
-    * Register a classloader for a module
-    * 
-    * @param module the module
-    * @param classLoader the classloader
-    * @throws IllegalArgumentException for a null parameter
-    */
-   protected static void registerModuleClassLoader(Module module, ClassLoader classLoader)
-   {
-      if (module == null)
-         throw new IllegalArgumentException("Null module");
-      if (classLoader == null)
-         throw new IllegalArgumentException("Null classloader");
-
-      modulesByClassLoader.put(classLoader, module);
-   }
-
-   /**
-    * Register a classloader for a module
-    * 
-    * @param module the module
-    * @param classLoader the classloader
-    * @throws IllegalArgumentException for a null parameter
-    */
-   protected static void unregisterModuleClassLoader(Module module, ClassLoader classLoader)
-   {
-      if (module == null)
-         throw new IllegalArgumentException("Null module");
-      if (classLoader == null)
-         throw new IllegalArgumentException("Null classloader");
-
-      modulesByClassLoader.remove(classLoader);
-   }
-   
-   /**
-    * Create a new Module with the default version
-    *
-    * @param name the name
-    * @throws IllegalArgumentException for a null parameter
-    */
-   public Module(String name)
-   {
-      this(name, name, null);
-   }
-   
-   /**
-    * Create a new Module with the given version
-    *
-    * @param name the name
-    * @param version pass null for the default version
-    * @throws IllegalArgumentException for a null parameter
-    */
-   public Module(String name, Object version)
-   {
-      this(name, name, version);
-   }
-   
-   /**
-    * Create a new Module with the given version
-    *
-    * @param name the name
-    * @param contextName the real name of the module in the controller
-    * @param version pass null for the default version
-    * @throws IllegalArgumentException for a null parameter
-    */
-   public Module(String name, String contextName, Object version)
-   {
-      super(name, version);
-      if (contextName == null)
-         contextName = name + version.toString();
-      this.contextName = contextName;
-   }
-
-   /**
-    * Get the context name
-    * 
-    * @return the context name
-    */
-   public String getContextName()
-   {
-      return contextName;
-   }
-   
-   /**
-    * Get the domain.
-    * 
-    * @return the domain.
-    */
-   Domain getDomain()
-   {
-      return domain;
-   }
-
-   void setDomain(Domain domain)
-   {
-      this.domain = domain;
-   }
-
-   Domain checkDomain()
-   {
-      Domain result = domain;
-      if (result == null)
-         throw new IllegalStateException("Domain is not set for " + this);
-      return result;
-   }
-   
-   /**
-    * Whether this is a valid  module
-    * 
-    * @return true when valid
-    */
-   public boolean isValid()
-   {
-      return domain != null;
-   }
-   
-   /**
-    * Get the domain name.
-    * 
-    * @return the domain name.
-    */
-   public String getDomainName()
-   {
-      return null;
-   }
-
-   /**
-    * Get the determined domain name.
-    * 
-    * @return the determined domain.
-    */
-   public String getDeterminedDomainName()
-   {
-      String domainName = getDomainName();
-      if (domainName == null)
-         domainName = ClassLoaderSystem.DEFAULT_DOMAIN_NAME;
-      return domainName;
-   }
-
-   /**
-    * Get the parent domain name.
-    * 
-    * @return the parent domain name.
-    */
-   public String getParentDomainName()
-   {
-      return null;
-   }
-
-   /**
-    * Get the determined parentDomain name.
-    * 
-    * @return the parentDomain.
-    */
-   public String getDeterminedParentDomainName()
-   {
-      String parentDomain = getParentDomainName();
-      if (parentDomain == null)
-      {
-         if (ClassLoaderSystem.DEFAULT_DOMAIN_NAME.equals(getDeterminedDomainName()) == false)
-            return ClassLoaderSystem.DEFAULT_DOMAIN_NAME;
-      }
-      return parentDomain;
-   }
-
-   /**
-    * Get the classloading space.
-    * 
-    * @return the space.
-    */
-   ClassLoadingSpace getClassLoadingSpace()
-   {
-      return space;
-   }
-
-   /**
-    * Set the classloading space.
-    * 
-    * @param space the space.
-    */
-   void setClassLoadingSpace(ClassLoadingSpace space)
-   {
-      this.space = space;
-   }
-
-   /**
-    * Get the export all for the module
-    * 
-    * @return the export all
-    */
-   public ExportAll getExportAll()
-   {
-      return null;
-   }
-
-   /**
-    * Get a filter for the included packages
-    * 
-    * @return the excluded packages
-    */
-   public ClassFilter getIncluded()
-   {
-      return null;
-   }
-
-   /**
-    * Get a filter for the excluded packages
-    * 
-    * @return the excluded packages
-    */
-   public ClassFilter getExcluded()
-   {
-      return null;
-   }
-
-   /**
-    * Get a filter for the excluded export packages
-    * 
-    * @return the excluded packages
-    */
-   public ClassFilter getExcludedExport()
-   {
-      return null;
-   }
-
-   /**
-    * Get the import all for the module
-    * 
-    * @return the import all
-    */
-   public boolean isImportAll()
-   {
-      return false;
-   }
-
-   /**
-    * Get delegate policy
-    * 
-    * @return the delegation policy
-    */
-   public boolean isJ2seClassLoadingCompliance()
-   {
-      return true;
-   }
-
-   public ParentPolicy getDeterminedParentPolicy()
-   {
-      if (isJ2seClassLoadingCompliance())
-         return ParentPolicy.BEFORE;
-      else
-         return ParentPolicy.AFTER_BUT_ONLY_JAVA_BEFORE;
-   }
-   
-   /**
-    * Whether to cache<p>
-    * 
-    * @return true to cache
-    */
-   protected boolean isCacheable()
-   {
-      return true;
-   }
-
-   /**
-    * Whether to cache misses<p>
-    * 
-    * @return true to cache misses
-    */
-   protected boolean isBlackListable()
-   {
-      return true;
-   }
-
-   /**
-    * Find the module for a classloader
-    * 
-    * @param cl the classloader
-    * @return the module or null if the classloader does not correspond to a registered module classloader
-    */
-   static Module getModuleForClassLoader(ClassLoader cl)
-   {
-      SecurityManager sm = System.getSecurityManager();
-      if (sm != null)
-         sm.checkPermission(new RuntimePermission("getClassLoader"));
-      
-      // Determine the module (if any) for the classloader 
-      if (cl != null)
-         return modulesByClassLoader.get(cl);
-      // Unknown
-      return null;
-   }
-   
-   /**
-    * Find the module that loads a class
-    * 
-    * @param className the class name
-    * @return the module or null if the class is not loaded by a registered module classloader
-    * @throws ClassNotFoundException when the class is not found
-    * @throws IllegalStateException when the module is not associated with a classloader
-    */
-   public Module getModuleForClass(String className) throws ClassNotFoundException
-   {
-      SecurityManager sm = System.getSecurityManager();
-      if (sm != null)
-         sm.checkPermission(new RuntimePermission("getClassLoader"));
-
-      ClassLoader cl = getClassLoaderForClass(className);
-
-      // Determine the module (if any) for the classloader 
-      if (cl != null)
-         return modulesByClassLoader.get(cl);
-      // Unknown
-      return null;
-   }
-
-   /**
-    * Get the classloader for a class name 
-    * 
-    * @param className the class name
-    * @return the class
-    * @throws ClassNotFoundException when the class is not found
-    * @throws IllegalStateException when the module is not associated with a classloader
-    */
-   protected ClassLoader getClassLoaderForClass(String className) throws ClassNotFoundException
-   {
-      // Determine the classloader for this class
-      final Class<?> clazz = loadClass(className);
-      SecurityManager sm = System.getSecurityManager();
-      if (sm != null)
-      {
-         return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
-         {
-            public ClassLoader run()
-            {
-               return clazz.getClassLoader(); 
-            }
-        });
-      }
-      return clazz.getClassLoader();
-   }
-
-   /**
-    * Load a class for this module 
-    * 
-    * @param className the class name
-    * @return the class
-    * @throws ClassNotFoundException when the class is not found
-    * @throws IllegalStateException when the module is not associated with a classloader
-    */
-   public Class<?> loadClass(String className) throws ClassNotFoundException
-   {
-      ClassLoader classLoader = getClassLoader();
-      if (classLoader == null)
-         throw new IllegalStateException("No classloader for this module " + this);
-      return classLoader.loadClass(className);
-   }
-
-   /**
-    * Get a resource for this module 
-    * 
-    * @param resourceName the resource name
-    * @return the class
-    * @throws IllegalStateException when the module is not associated with a classloader
-    */
-   public URL getResource(String resourceName) 
-   {
-      ClassLoader classLoader = getClassLoader();
-      if (classLoader == null)
-         throw new IllegalStateException("No classloader for this module " + this);
-      return classLoader.getResource(resourceName);
-   }
-
-   /**
-    * Get resources for this module 
-    * 
-    * @param resourceName the resource name
-    * @return the class
-    * @throws IOException for an error
-    * @throws IllegalStateException when the module is not associated with a classloader
-    */
-   public Enumeration<URL> getResources(String resourceName) throws IOException
-   {
-      ClassLoader classLoader = getClassLoader();
-      if (classLoader == null)
-         throw new IllegalStateException("No classloader for this module " + this);
-      return classLoader.getResources(resourceName);
-   }
-
-   /**
-    * Get the classloader for this module
-    * 
-    * @return the classloader
-    */
-   protected ClassLoader getClassLoader()
-   {
-      return null;
-   }
-   
-   /**
-    * Visit the resources in this module
-    * using the filter defined on the visitor
-    * 
-    * @param visitor the visitor
-    */
-   public void visit(ResourceVisitor visitor)
-   {
-      if (visitor == null)
-         throw new IllegalArgumentException("Null visitor");
-      visit(visitor, visitor.getFilter());
-   }
-
-   /**
-    * Visit the resources in this module
-    * using the given filter
-    * 
-    * @param visitor the visitor
-    * @param filter the filter
-    */
-   public void visit(ResourceVisitor visitor, ResourceFilter filter)
-   {
-      visit(visitor, filter, null);
-   }
-
-   /**
-    * Visit the resources in this module using the given filter(s)
-    * <p/>
-    * Typically the filter is used to determine which types of files to visit, e.g. .class files.
-    * While the recurseFilter determines which jars/directories to recurse into.
-    *
-    * @param visitor       the visitor
-    * @param filter        the filter
-    * @param recurseFilter the recursion filter (null means recurse into everything)
-    * @param urls the urls we should visit
-    */
-   public void visit(ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter, URL... urls)
-   {
-      throw new UnsupportedOperationException("The module " + getContextName() + " does not support filtering: " + getClass().getName());
-   }
-
-   /**
-    * Get the delegate loaders for this module
-    * 
-    * @return the delegates
-    */
-   public List<? extends DelegateLoader> getDelegates()
-   {
-      if (requirementDependencies == null || requirementDependencies.isEmpty())
-         return null;
-
-      List<DelegateLoader> result = new CopyOnWriteArrayList<DelegateLoader>();
-      List<DelegateLoader> dynamic = new CopyOnWriteArrayList<DelegateLoader>();
-      Set<Module> visited = new HashSet<Module>();
-      addDelegates(this, result, dynamic, visited, false);
-      
-      // Make sure the dynamic delegates are last
-      result.addAll(dynamic);
-      
-      return result;
-   }
-   
-   /**
-    * Get the dependency items
-    * 
-    * @return the depenency items
-    */
-   protected List<RequirementDependencyItem> getRequirementDependencyItems()
-   {
-      return requirementDependencies;
-   }
-
-   /**
-    * Add delegates
-    * 
-    * @param module the module to add delegates from
-    * @param delegates the current list of delegates
-    * @param dynamic the dynamic delegates
-    * @param visited the visited modules
-    * @param reExport whether to only add re-exports
-    */
-   protected void addDelegates(Module module, List<DelegateLoader> delegates, List<DelegateLoader> dynamic, Set<Module> visited, boolean reExport)
-   {
-      // Check whether we already did this module
-      if (visited.contains(module))
-         return;
-      visited.add(module);
-      
-      List<RequirementDependencyItem> dependencies = module.getRequirementDependencyItems();
-      if (dependencies == null || dependencies.isEmpty())
-         return;
-      
-      for (RequirementDependencyItem item : dependencies)
-      {
-         Requirement requirement = item.getRequirement();
-         
-         // If we are looking at everything or this is a re-export
-         if (reExport == false || requirement.isReExport())
-         {
-            // Sanity checks
-            if (item.isResolved() == false)
-               throw new IllegalStateException("Item not resolved: " + item);
-            
-            // Dynamic requirement, create it lazily
-            if (requirement.isDynamic())
-            {
-               DelegateLoader delegate = createLazyDelegateLoader(checkDomain(), item);
-               dynamic.add(delegate);
-               continue;
-            }
-
-            String name = (String) item.getIDependOn();
-            if (name == null)
-            {
-               // Optional requirement, just ignore
-               if (requirement.isOptional())
-                  continue;
-               // Something has gone wrong
-               throw new IllegalStateException("No iDependOn for item: " + item);
-            }
-            Module iDependOnModule = checkDomain().getModule(name);
-            if (iDependOnModule == null)
-               throw new IllegalStateException("Module not found with name: " + name);
-
-            // Determine the delegate loader for the module
-            Module other = item.getModule();
-            DelegateLoader delegate = iDependOnModule.getDelegateLoader(other, requirement);
-
-            // Check for re-export by the module
-            if (requirement.wantReExports())
-               addDelegates(iDependOnModule, delegates, dynamic, visited, true);
-            
-            // We want a module's re-exports (i.e. part of its imports) before the module itself
-            if (delegate != null)
-               delegates.add(delegate);
-         }
-      }
-   }
-
-   /**
-    * Create a lazy delegate loader
-    * 
-    * @param domain the domain
-    * @param item the dependency item
-    * @return the delegate loader
-    */
-   public abstract DelegateLoader createLazyDelegateLoader(Domain domain, RequirementDependencyItem item);
-
-   /**
-    * Get the delegate loader
-    * 
-    * @param requiringModule the requiring module
-    * @param requirement the requirement
-    * @return the delegate loader
-    */
-   public abstract DelegateLoader getDelegateLoader(Module requiringModule, Requirement requirement);
-
-   /**
-    * Get the capabilities.
-    * 
-    * @return the capabilities.
-    */
-   public List<Capability> getCapabilities()
-   {
-      // Have we already worked this out?
-      if (capabilities != null)
-         return capabilities;
-      
-      // Are there any configured ones?
-      List<Capability> capabilities = determineCapabilities();
-      
-      // Use the defaults
-      if (capabilities == null)
-         capabilities = defaultCapabilities();
-      
-      // Cache it
-      this.capabilities = capabilities;
-      return capabilities;
-   }
-
-   /**
-    * Determine the capabilities
-    * 
-    * @return the capabilities
-    */
-   protected List<Capability> determineCapabilities()
-   {
-      return null;
-   }
-
-   /**
-    * Determine the default capabilities.<p>
-    * 
-    * By default it is just the module capability
-    * 
-    * @return the capabilities
-    */
-   protected List<Capability> defaultCapabilities()
-   {
-      List<Capability> capabilities = new CopyOnWriteArrayList<Capability>();
-      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
-      Capability capability = factory.createModule(getName(), getVersion());
-      capabilities.add(capability);
-      return capabilities;
-   }
-
-   /**
-    * Get the package names
-    * 
-    * @return the package names
-    */
-   public String[] getPackageNames()
-   {
-      List<String> packageNames = determinePackageNames(true);
-      return packageNames.toArray(new String[packageNames.size()]);
-   }
-
-   /**
-    * Determine the package names
-    * 
-    * TODO JBCL-23 Better handling of conflicts for optional packages
-    * @param optional whether to include optional packages
-    * @return the package names
-    */
-   public List<String> determinePackageNames(boolean optional)
-   {
-      List<String> packageNames = Collections.emptyList();
-
-      List<Capability> capabilities = getCapabilities();
-      if (capabilities != null && capabilities.isEmpty() == false)
-      {
-         for (Capability capability : capabilities)
-         {
-            if (capability instanceof ExportPackages)
-            {
-               ExportPackages exported = (ExportPackages) capability;
-               Set<String> exportPackages = exported.getPackageNames(this);
-               if (exportPackages != null)
-               {
-                  if (packageNames.isEmpty())
-                     packageNames = new ArrayList<String>();
-                  packageNames.addAll(exportPackages);
-               }
-            }
-         }
-      }
-
-      List<Requirement> requirements = getRequirements();
-      if (requirements != null && requirements.isEmpty() == false)
-      {
-         for (Requirement requirement : getRequirements())
-         {
-            if (requirement instanceof ExportPackages)
-            {
-               ExportPackages exported = (ExportPackages) requirement;
-               Set<String> exportPackages = exported.getPackageNames(this);
-               if (optional || requirement.isOptional() == false)
-               {
-                  if (exportPackages != null && exportPackages.isEmpty() == false)
-                  {
-                     if (packageNames.isEmpty())
-                        packageNames = new ArrayList<String>();
-                     packageNames.addAll(exportPackages);
-                  }
-               }
-            }
-            else if (optional == false && requirement instanceof OptionalPackages)
-            {
-               OptionalPackages exported = (OptionalPackages) requirement;
-               Set<String> optionalPackages = exported.getOptionalPackageNames(this);
-               if (optionalPackages != null && packageNames.isEmpty() == false)
-                  packageNames.removeAll(optionalPackages);
-            }
-         }
-      }
-
-      return packageNames;
-   }
-   
-   /**
-    * Get the state for the classloader
-    * 
-    * @return the state
-    */
-   public ControllerState getClassLoaderState()
-   {
-      return ControllerState.INSTALLED;
-   }
-
-   /**
-    * Get the requirements.
-    * 
-    * @return the requirements.
-    */
-   public List<Requirement> getRequirements()
-   {
-      // Have we already worked this out?
-      if (requirements != null)
-         return requirements;
-      
-      // Are there any configured ones?
-      List<Requirement> requirements = determineRequirements();
-      
-      // Cache it
-      this.requirements = requirements;
-      return requirements;
-   }
-
-   /**
-    * Determine the requirements.
-    * 
-    * @return the requirements.
-    */
-   public List<Requirement> determineRequirements()
-   {
-      return Collections.emptyList();
-   }
-
-   /**
-    * Return a URL where dynamic classes can be stored
-    * 
-    * @return the url or null if there isn't one
-    */
-   public URL getDynamicClassRoot()
-   {
-      return null;
-   }
-   
-   List<RequirementDependencyItem> getDependencies()
-   {
-      return requirementDependencies;
-   }
-   
-   /**
-    * Create the dependencies for the module
-    */
-   protected void createDependencies()
-   {
-      ControllerState classLoaderState = getClassLoaderState();
-      
-      List<Requirement> requirements = getRequirements();
-      if (requirements != null)
-      {
-         requirementDependencies = new ArrayList<RequirementDependencyItem>();
-         for (Requirement requirement : requirements)
-         {
-            RequirementDependencyItem item = new RequirementDependencyItem(this, requirement, classLoaderState);
-            addIDependOn(item);
-            requirementDependencies.add(item);
-         }
-      }
-   }
-
-   /**
-    * Remove dependencies
-    */
-   protected void removeDependencies()
-   {
-      if (requirementDependencies != null && requirementDependencies.isEmpty() == false)
-      {
-         for (RequirementDependencyItem item : requirementDependencies)
-            removeIDependOn(item);
-      }
-      requirementDependencies = null;
-   }
-
-   /**
-    * Get the controller context.
-    * 
-    * @return the controller context.
-    */
-   protected ControllerContext getControllerContext()
-   {
-      return context;
-   }
-
-   /**
-    * Set the controller context
-    * 
-    * @param context the context
-    */
-   protected void setControllerContext(ControllerContext context)
-   {
-      this.context = context;
-   }
-   
-   /**
-    * Add a dependency
-    * 
-    * @param item the dependency item
-    */
-   protected void addIDependOn(RequirementDependencyItem item)
-   {
-      if (context == null)
-         throw new IllegalStateException("No controller context");
-      context.getDependencyInfo().addIDependOn(item);
-   }
-   
-   /**
-    * Remove a dependency
-    * 
-    * @param item the dependency item
-    */
-   protected void removeIDependOn(RequirementDependencyItem item)
-   {
-      if (context == null)
-         throw new IllegalStateException("No controller context");
-      context.getDependencyInfo().removeIDependOn(item);
-   }
-   
-   /**
-    * Resolve a requirement
-    * 
-    * @param dependency the dependency the dependency
-    * @param resolveSpace whether to resolve the module in the classloading space
-    * @return the resolved name or null if not resolved
-    */
-   protected Module resolveModule(RequirementDependencyItem dependency, boolean resolveSpace)
-   {
-      ClassLoadingSpace space = getClassLoadingSpace();
-      if (resolveSpace && space != null)
-         space.resolve(this);
-
-      Requirement requirement = dependency.getRequirement();
-      return checkDomain().resolveModule(this, requirement);
-   }
-   
-   /**
-    * Release the module
-    */
-   public void release()
-   {
-      Domain domain = this.domain;
-      if (domain != null)
-         domain.removeModule(this);
-      reset();
-   }
-   
-   /**
-    * Reset the module
-    */
-   public void reset()
-   {
-      this.capabilities = null;
-      this.requirements = null;
-   }
-
-   @Override
-   public boolean equals(Object obj)
-   {
-      if (obj == this)
-         return true;
-      if (obj == null || obj instanceof Module == false)
-         return false;
-      return super.equals(obj);
-   }
-}

Copied: projects/jboss-cl/tags/2.0.2.GA/classloading/src/main/java/org/jboss/classloading/spi/dependency/Module.java (from rev 83469, projects/jboss-cl/branches/Branch_2_0/classloading/src/main/java/org/jboss/classloading/spi/dependency/Module.java)
===================================================================
--- projects/jboss-cl/tags/2.0.2.GA/classloading/src/main/java/org/jboss/classloading/spi/dependency/Module.java	                        (rev 0)
+++ projects/jboss-cl/tags/2.0.2.GA/classloading/src/main/java/org/jboss/classloading/spi/dependency/Module.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -0,0 +1,941 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.classloading.spi.dependency;
+
+import java.io.IOException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.DelegateLoader;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloading.spi.helpers.NameAndVersionSupport;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.ExportAll;
+import org.jboss.classloading.spi.metadata.ExportPackages;
+import org.jboss.classloading.spi.metadata.OptionalPackages;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * Module.
+ * 
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class Module extends NameAndVersionSupport
+{
+   /** The modules by classloader */
+   private static Map<ClassLoader, Module> modulesByClassLoader = new ConcurrentHashMap<ClassLoader, Module>();
+   
+   /** The context name */
+   private String contextName;
+   
+   /** Our cached capabilities */
+   private List<Capability> capabilities;
+   
+   /** Our cached requirements */
+   private List<Requirement> requirements;
+
+   /** The controller context */
+   private ControllerContext context;
+
+   /** The domain */
+   private Domain domain;
+
+   /** The classloading space */
+   private ClassLoadingSpace space;
+   
+   /** The requirements */
+   private List<RequirementDependencyItem> requirementDependencies;
+
+   /**
+    * Register a classloader for a module
+    * 
+    * @param module the module
+    * @param classLoader the classloader
+    * @throws IllegalArgumentException for a null parameter
+    */
+   protected static void registerModuleClassLoader(Module module, ClassLoader classLoader)
+   {
+      if (module == null)
+         throw new IllegalArgumentException("Null module");
+      if (classLoader == null)
+         throw new IllegalArgumentException("Null classloader");
+
+      modulesByClassLoader.put(classLoader, module);
+   }
+
+   /**
+    * Register a classloader for a module
+    * 
+    * @param module the module
+    * @param classLoader the classloader
+    * @throws IllegalArgumentException for a null parameter
+    */
+   protected static void unregisterModuleClassLoader(Module module, ClassLoader classLoader)
+   {
+      if (module == null)
+         throw new IllegalArgumentException("Null module");
+      if (classLoader == null)
+         throw new IllegalArgumentException("Null classloader");
+
+      modulesByClassLoader.remove(classLoader);
+   }
+   
+   /**
+    * Create a new Module with the default version
+    *
+    * @param name the name
+    * @throws IllegalArgumentException for a null parameter
+    */
+   public Module(String name)
+   {
+      this(name, name, null);
+   }
+   
+   /**
+    * Create a new Module with the given version
+    *
+    * @param name the name
+    * @param version pass null for the default version
+    * @throws IllegalArgumentException for a null parameter
+    */
+   public Module(String name, Object version)
+   {
+      this(name, name, version);
+   }
+   
+   /**
+    * Create a new Module with the given version
+    *
+    * @param name the name
+    * @param contextName the real name of the module in the controller
+    * @param version pass null for the default version
+    * @throws IllegalArgumentException for a null parameter
+    */
+   public Module(String name, String contextName, Object version)
+   {
+      super(name, version);
+      if (contextName == null)
+         contextName = name + version.toString();
+      this.contextName = contextName;
+   }
+
+   /**
+    * Get the context name
+    * 
+    * @return the context name
+    */
+   public String getContextName()
+   {
+      return contextName;
+   }
+   
+   /**
+    * Get the domain.
+    * 
+    * @return the domain.
+    */
+   Domain getDomain()
+   {
+      return domain;
+   }
+
+   void setDomain(Domain domain)
+   {
+      this.domain = domain;
+   }
+
+   Domain checkDomain()
+   {
+      Domain result = domain;
+      if (result == null)
+         throw new IllegalStateException("Domain is not set for " + this);
+      return result;
+   }
+   
+   /**
+    * Whether this is a valid  module
+    * 
+    * @return true when valid
+    */
+   public boolean isValid()
+   {
+      return domain != null;
+   }
+   
+   /**
+    * Get the domain name.
+    * 
+    * @return the domain name.
+    */
+   public String getDomainName()
+   {
+      return null;
+   }
+
+   /**
+    * Get the determined domain name.
+    * 
+    * @return the determined domain.
+    */
+   public String getDeterminedDomainName()
+   {
+      String domainName = getDomainName();
+      if (domainName == null)
+         domainName = ClassLoaderSystem.DEFAULT_DOMAIN_NAME;
+      return domainName;
+   }
+
+   /**
+    * Get the parent domain name.
+    * 
+    * @return the parent domain name.
+    */
+   public String getParentDomainName()
+   {
+      return null;
+   }
+
+   /**
+    * Get the determined parentDomain name.
+    * 
+    * @return the parentDomain.
+    */
+   public String getDeterminedParentDomainName()
+   {
+      String parentDomain = getParentDomainName();
+      if (parentDomain == null)
+      {
+         if (ClassLoaderSystem.DEFAULT_DOMAIN_NAME.equals(getDeterminedDomainName()) == false)
+            return ClassLoaderSystem.DEFAULT_DOMAIN_NAME;
+      }
+      return parentDomain;
+   }
+
+   /**
+    * Get the classloading space.
+    * 
+    * @return the space.
+    */
+   ClassLoadingSpace getClassLoadingSpace()
+   {
+      return space;
+   }
+
+   /**
+    * Set the classloading space.
+    * 
+    * @param space the space.
+    */
+   void setClassLoadingSpace(ClassLoadingSpace space)
+   {
+      this.space = space;
+   }
+
+   /**
+    * Get the export all for the module
+    * 
+    * @return the export all
+    */
+   public ExportAll getExportAll()
+   {
+      return null;
+   }
+
+   /**
+    * Get a filter for the included packages
+    * 
+    * @return the excluded packages
+    */
+   public ClassFilter getIncluded()
+   {
+      return null;
+   }
+
+   /**
+    * Get a filter for the excluded packages
+    * 
+    * @return the excluded packages
+    */
+   public ClassFilter getExcluded()
+   {
+      return null;
+   }
+
+   /**
+    * Get a filter for the excluded export packages
+    * 
+    * @return the excluded packages
+    */
+   public ClassFilter getExcludedExport()
+   {
+      return null;
+   }
+
+   /**
+    * Get the import all for the module
+    * 
+    * @return the import all
+    */
+   public boolean isImportAll()
+   {
+      return false;
+   }
+
+   /**
+    * Get delegate policy
+    * 
+    * @return the delegation policy
+    */
+   public boolean isJ2seClassLoadingCompliance()
+   {
+      return true;
+   }
+
+   public ParentPolicy getDeterminedParentPolicy()
+   {
+      if (isJ2seClassLoadingCompliance())
+         return ParentPolicy.BEFORE;
+      else
+         return ParentPolicy.AFTER_BUT_ONLY_JAVA_BEFORE;
+   }
+   
+   /**
+    * Whether to cache<p>
+    * 
+    * @return true to cache
+    */
+   protected boolean isCacheable()
+   {
+      return true;
+   }
+
+   /**
+    * Whether to cache misses<p>
+    * 
+    * @return true to cache misses
+    */
+   protected boolean isBlackListable()
+   {
+      return true;
+   }
+
+   /**
+    * Find the module for a classloader
+    * 
+    * @param cl the classloader
+    * @return the module or null if the classloader does not correspond to a registered module classloader
+    * @throws SecurityException if the caller doesn't have <code>new RuntimePermision("getClassLoader")</code>
+    */
+   static Module getModuleForClassLoader(ClassLoader cl)
+   {
+      SecurityManager sm = System.getSecurityManager();
+      if (sm != null)
+         sm.checkPermission(new RuntimePermission("getClassLoader"));
+      
+      // Determine the module (if any) for the classloader 
+      if (cl != null)
+         return modulesByClassLoader.get(cl);
+      // Unknown
+      return null;
+   }
+   
+   /**
+    * Find the module that loads a class
+    * 
+    * @param className the class name
+    * @return the module or null if the class is not loaded by a registered module classloader
+    * @throws ClassNotFoundException when the class is not found
+    * @throws IllegalStateException when the module is not associated with a classloader
+    */
+   public Module getModuleForClass(String className) throws ClassNotFoundException
+   {
+      SecurityManager sm = System.getSecurityManager();
+      if (sm != null)
+         sm.checkPermission(new RuntimePermission("getClassLoader"));
+
+      ClassLoader cl = getClassLoaderForClass(className);
+
+      // Determine the module (if any) for the classloader 
+      if (cl != null)
+         return modulesByClassLoader.get(cl);
+      // Unknown
+      return null;
+   }
+
+   /**
+    * Get the classloader for a class name 
+    * 
+    * @param className the class name
+    * @return the class
+    * @throws ClassNotFoundException when the class is not found
+    * @throws IllegalStateException when the module is not associated with a classloader
+    */
+   protected ClassLoader getClassLoaderForClass(String className) throws ClassNotFoundException
+   {
+      // Determine the classloader for this class
+      final Class<?> clazz = loadClass(className);
+      SecurityManager sm = System.getSecurityManager();
+      if (sm != null)
+      {
+         return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+         {
+            public ClassLoader run()
+            {
+               return clazz.getClassLoader(); 
+            }
+        });
+      }
+      return clazz.getClassLoader();
+   }
+
+   /**
+    * Load a class for this module 
+    * 
+    * @param className the class name
+    * @return the class
+    * @throws ClassNotFoundException when the class is not found
+    * @throws IllegalStateException when the module is not associated with a classloader
+    */
+   public Class<?> loadClass(String className) throws ClassNotFoundException
+   {
+      ClassLoader classLoader = getClassLoader();
+      if (classLoader == null)
+         throw new IllegalStateException("No classloader for this module " + this);
+      return classLoader.loadClass(className);
+   }
+
+   /**
+    * Get a resource for this module 
+    * 
+    * @param resourceName the resource name
+    * @return the class
+    * @throws IllegalStateException when the module is not associated with a classloader
+    */
+   public URL getResource(String resourceName) 
+   {
+      ClassLoader classLoader = getClassLoader();
+      if (classLoader == null)
+         throw new IllegalStateException("No classloader for this module " + this);
+      return classLoader.getResource(resourceName);
+   }
+
+   /**
+    * Get resources for this module 
+    * 
+    * @param resourceName the resource name
+    * @return the class
+    * @throws IOException for an error
+    * @throws IllegalStateException when the module is not associated with a classloader
+    */
+   public Enumeration<URL> getResources(String resourceName) throws IOException
+   {
+      ClassLoader classLoader = getClassLoader();
+      if (classLoader == null)
+         throw new IllegalStateException("No classloader for this module " + this);
+      return classLoader.getResources(resourceName);
+   }
+
+   /**
+    * Get the classloader for this module
+    * 
+    * @return the classloader
+    */
+   protected ClassLoader getClassLoader()
+   {
+      return null;
+   }
+   
+   /**
+    * Visit the resources in this module
+    * using the filter defined on the visitor
+    * 
+    * @param visitor the visitor
+    */
+   public void visit(ResourceVisitor visitor)
+   {
+      if (visitor == null)
+         throw new IllegalArgumentException("Null visitor");
+      visit(visitor, visitor.getFilter());
+   }
+
+   /**
+    * Visit the resources in this module
+    * using the given filter
+    * 
+    * @param visitor the visitor
+    * @param filter the filter
+    */
+   public void visit(ResourceVisitor visitor, ResourceFilter filter)
+   {
+      visit(visitor, filter, null);
+   }
+
+   /**
+    * Visit the resources in this module using the given filter(s)
+    * <p/>
+    * Typically the filter is used to determine which types of files to visit, e.g. .class files.
+    * While the recurseFilter determines which jars/directories to recurse into.
+    *
+    * @param visitor       the visitor
+    * @param filter        the filter
+    * @param recurseFilter the recursion filter (null means recurse into everything)
+    * @param urls the urls we should visit
+    */
+   public void visit(ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter, URL... urls)
+   {
+      throw new UnsupportedOperationException("The module " + getContextName() + " does not support filtering: " + getClass().getName());
+   }
+
+   /**
+    * Get the delegate loaders for this module
+    * 
+    * @return the delegates
+    */
+   public List<? extends DelegateLoader> getDelegates()
+   {
+      if (requirementDependencies == null || requirementDependencies.isEmpty())
+         return null;
+
+      List<DelegateLoader> result = new CopyOnWriteArrayList<DelegateLoader>();
+      List<DelegateLoader> dynamic = new CopyOnWriteArrayList<DelegateLoader>();
+      Set<Module> visited = new HashSet<Module>();
+      addDelegates(this, result, dynamic, visited, false);
+      
+      // Make sure the dynamic delegates are last
+      result.addAll(dynamic);
+      
+      return result;
+   }
+   
+   /**
+    * Get the dependency items
+    * 
+    * @return the depenency items
+    */
+   protected List<RequirementDependencyItem> getRequirementDependencyItems()
+   {
+      return requirementDependencies;
+   }
+
+   /**
+    * Add delegates
+    * 
+    * @param module the module to add delegates from
+    * @param delegates the current list of delegates
+    * @param dynamic the dynamic delegates
+    * @param visited the visited modules
+    * @param reExport whether to only add re-exports
+    */
+   protected void addDelegates(Module module, List<DelegateLoader> delegates, List<DelegateLoader> dynamic, Set<Module> visited, boolean reExport)
+   {
+      // Check whether we already did this module
+      if (visited.contains(module))
+         return;
+      visited.add(module);
+      
+      List<RequirementDependencyItem> dependencies = module.getRequirementDependencyItems();
+      if (dependencies == null || dependencies.isEmpty())
+         return;
+      
+      for (RequirementDependencyItem item : dependencies)
+      {
+         Requirement requirement = item.getRequirement();
+         
+         // If we are looking at everything or this is a re-export
+         if (reExport == false || requirement.isReExport())
+         {
+            // Sanity checks
+            if (item.isResolved() == false)
+               throw new IllegalStateException("Item not resolved: " + item);
+            
+            // Dynamic requirement, create it lazily
+            if (requirement.isDynamic())
+            {
+               DelegateLoader delegate = createLazyDelegateLoader(checkDomain(), item);
+               dynamic.add(delegate);
+               continue;
+            }
+
+            String name = (String) item.getIDependOn();
+            if (name == null)
+            {
+               // Optional requirement, just ignore
+               if (requirement.isOptional())
+                  continue;
+               // Something has gone wrong
+               throw new IllegalStateException("No iDependOn for item: " + item);
+            }
+            Module iDependOnModule = checkDomain().getModule(name);
+            if (iDependOnModule == null)
+               throw new IllegalStateException("Module not found with name: " + name);
+
+            // Determine the delegate loader for the module
+            Module other = item.getModule();
+            DelegateLoader delegate = iDependOnModule.getDelegateLoader(other, requirement);
+
+            // Check for re-export by the module
+            if (requirement.wantReExports())
+               addDelegates(iDependOnModule, delegates, dynamic, visited, true);
+            
+            // We want a module's re-exports (i.e. part of its imports) before the module itself
+            if (delegate != null)
+               delegates.add(delegate);
+         }
+      }
+   }
+
+   /**
+    * Create a lazy delegate loader
+    * 
+    * @param domain the domain
+    * @param item the dependency item
+    * @return the delegate loader
+    */
+   public abstract DelegateLoader createLazyDelegateLoader(Domain domain, RequirementDependencyItem item);
+
+   /**
+    * Get the delegate loader
+    * 
+    * @param requiringModule the requiring module
+    * @param requirement the requirement
+    * @return the delegate loader
+    */
+   public abstract DelegateLoader getDelegateLoader(Module requiringModule, Requirement requirement);
+
+   /**
+    * Get the capabilities.
+    * 
+    * @return the capabilities.
+    */
+   public List<Capability> getCapabilities()
+   {
+      // Have we already worked this out?
+      if (capabilities != null)
+         return capabilities;
+      
+      // Are there any configured ones?
+      List<Capability> capabilities = determineCapabilities();
+      
+      // Use the defaults
+      if (capabilities == null)
+         capabilities = defaultCapabilities();
+      
+      // Cache it
+      this.capabilities = capabilities;
+      return capabilities;
+   }
+
+   /**
+    * Determine the capabilities
+    * 
+    * @return the capabilities
+    */
+   protected List<Capability> determineCapabilities()
+   {
+      return null;
+   }
+
+   /**
+    * Determine the default capabilities.<p>
+    * 
+    * By default it is just the module capability
+    * 
+    * @return the capabilities
+    */
+   protected List<Capability> defaultCapabilities()
+   {
+      List<Capability> capabilities = new CopyOnWriteArrayList<Capability>();
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      Capability capability = factory.createModule(getName(), getVersion());
+      capabilities.add(capability);
+      return capabilities;
+   }
+
+   /**
+    * Get the package names
+    * 
+    * @return the package names
+    */
+   public String[] getPackageNames()
+   {
+      List<String> packageNames = determinePackageNames(true);
+      return packageNames.toArray(new String[packageNames.size()]);
+   }
+
+   /**
+    * Determine the package names
+    * 
+    * TODO JBCL-23 Better handling of conflicts for optional packages
+    * @param optional whether to include optional packages
+    * @return the package names
+    */
+   public List<String> determinePackageNames(boolean optional)
+   {
+      List<String> packageNames = Collections.emptyList();
+
+      List<Capability> capabilities = getCapabilities();
+      if (capabilities != null && capabilities.isEmpty() == false)
+      {
+         for (Capability capability : capabilities)
+         {
+            if (capability instanceof ExportPackages)
+            {
+               ExportPackages exported = (ExportPackages) capability;
+               Set<String> exportPackages = exported.getPackageNames(this);
+               if (exportPackages != null)
+               {
+                  if (packageNames.isEmpty())
+                     packageNames = new ArrayList<String>();
+                  packageNames.addAll(exportPackages);
+               }
+            }
+         }
+      }
+
+      List<Requirement> requirements = getRequirements();
+      if (requirements != null && requirements.isEmpty() == false)
+      {
+         for (Requirement requirement : getRequirements())
+         {
+            if (requirement instanceof ExportPackages)
+            {
+               ExportPackages exported = (ExportPackages) requirement;
+               Set<String> exportPackages = exported.getPackageNames(this);
+               if (optional || requirement.isOptional() == false)
+               {
+                  if (exportPackages != null && exportPackages.isEmpty() == false)
+                  {
+                     if (packageNames.isEmpty())
+                        packageNames = new ArrayList<String>();
+                     packageNames.addAll(exportPackages);
+                  }
+               }
+            }
+            else if (optional == false && requirement instanceof OptionalPackages)
+            {
+               OptionalPackages exported = (OptionalPackages) requirement;
+               Set<String> optionalPackages = exported.getOptionalPackageNames(this);
+               if (optionalPackages != null && packageNames.isEmpty() == false)
+                  packageNames.removeAll(optionalPackages);
+            }
+         }
+      }
+
+      return packageNames;
+   }
+   
+   /**
+    * Get the state for the classloader
+    * 
+    * @return the state
+    */
+   public ControllerState getClassLoaderState()
+   {
+      return ControllerState.INSTALLED;
+   }
+
+   /**
+    * Get the requirements.
+    * 
+    * @return the requirements.
+    */
+   public List<Requirement> getRequirements()
+   {
+      // Have we already worked this out?
+      if (requirements != null)
+         return requirements;
+      
+      // Are there any configured ones?
+      List<Requirement> requirements = determineRequirements();
+      
+      // Cache it
+      this.requirements = requirements;
+      return requirements;
+   }
+
+   /**
+    * Determine the requirements.
+    * 
+    * @return the requirements.
+    */
+   public List<Requirement> determineRequirements()
+   {
+      return Collections.emptyList();
+   }
+
+   /**
+    * Return a URL where dynamic classes can be stored
+    * 
+    * @return the url or null if there isn't one
+    */
+   public URL getDynamicClassRoot()
+   {
+      return null;
+   }
+   
+   List<RequirementDependencyItem> getDependencies()
+   {
+      return requirementDependencies;
+   }
+   
+   /**
+    * Create the dependencies for the module
+    */
+   protected void createDependencies()
+   {
+      ControllerState classLoaderState = getClassLoaderState();
+      
+      List<Requirement> requirements = getRequirements();
+      if (requirements != null)
+      {
+         requirementDependencies = new ArrayList<RequirementDependencyItem>();
+         for (Requirement requirement : requirements)
+         {
+            RequirementDependencyItem item = new RequirementDependencyItem(this, requirement, classLoaderState);
+            addIDependOn(item);
+            requirementDependencies.add(item);
+         }
+      }
+   }
+
+   /**
+    * Remove dependencies
+    */
+   protected void removeDependencies()
+   {
+      if (requirementDependencies != null && requirementDependencies.isEmpty() == false)
+      {
+         for (RequirementDependencyItem item : requirementDependencies)
+            removeIDependOn(item);
+      }
+      requirementDependencies = null;
+   }
+
+   /**
+    * Get the controller context.
+    * 
+    * @return the controller context.
+    */
+   protected ControllerContext getControllerContext()
+   {
+      return context;
+   }
+
+   /**
+    * Set the controller context
+    * 
+    * @param context the context
+    */
+   protected void setControllerContext(ControllerContext context)
+   {
+      this.context = context;
+   }
+   
+   /**
+    * Add a dependency
+    * 
+    * @param item the dependency item
+    */
+   protected void addIDependOn(RequirementDependencyItem item)
+   {
+      if (context == null)
+         throw new IllegalStateException("No controller context");
+      context.getDependencyInfo().addIDependOn(item);
+   }
+   
+   /**
+    * Remove a dependency
+    * 
+    * @param item the dependency item
+    */
+   protected void removeIDependOn(RequirementDependencyItem item)
+   {
+      if (context == null)
+         throw new IllegalStateException("No controller context");
+      context.getDependencyInfo().removeIDependOn(item);
+   }
+   
+   /**
+    * Resolve a requirement
+    * 
+    * @param dependency the dependency the dependency
+    * @param resolveSpace whether to resolve the module in the classloading space
+    * @return the resolved name or null if not resolved
+    */
+   protected Module resolveModule(RequirementDependencyItem dependency, boolean resolveSpace)
+   {
+      ClassLoadingSpace space = getClassLoadingSpace();
+      if (resolveSpace && space != null)
+         space.resolve(this);
+
+      Requirement requirement = dependency.getRequirement();
+      return checkDomain().resolveModule(this, requirement);
+   }
+   
+   /**
+    * Release the module
+    */
+   public void release()
+   {
+      Domain domain = this.domain;
+      if (domain != null)
+         domain.removeModule(this);
+      reset();
+   }
+   
+   /**
+    * Reset the module
+    */
+   public void reset()
+   {
+      this.capabilities = null;
+      this.requirements = null;
+   }
+
+   @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof Module == false)
+         return false;
+      return super.equals(obj);
+   }
+}

Deleted: projects/jboss-cl/tags/2.0.2.GA/classloading/src/test/java/org/jboss/test/classloading/dependency/test/ModuleClassLoadingUnitTestCase.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/test/ModuleClassLoadingUnitTestCase.java	2009-01-27 11:39:59 UTC (rev 83468)
+++ projects/jboss-cl/tags/2.0.2.GA/classloading/src/test/java/org/jboss/test/classloading/dependency/test/ModuleClassLoadingUnitTestCase.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -1,338 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, 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.classloading.dependency.test;
-
-import java.net.URL;
-import java.util.Enumeration;
-
-import junit.framework.Test;
-
-import org.jboss.classloader.plugins.ClassLoaderUtils;
-import org.jboss.classloading.spi.dependency.ClassLoading;
-import org.jboss.classloading.spi.dependency.Module;
-import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
-import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
-import org.jboss.classloading.spi.version.VersionRange;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
-import org.jboss.test.classloading.dependency.support.a.A;
-import org.jboss.test.classloading.dependency.support.b.B;
-import org.jboss.test.classloading.dependency.support.c.C;
-
-/**
- * ModuleClassLoadingUnitTestCase.
- * 
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class ModuleClassLoadingUnitTestCase extends AbstractMockClassLoaderUnitTest
-{
-   public static Test suite()
-   {
-      return suite(ModuleClassLoadingUnitTestCase.class);
-   }
-
-   public ModuleClassLoadingUnitTestCase(String name)
-   {
-      super(name);
-   }
-   
-   public void testLoadClassFromThisModule() throws Exception
-   {
-      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
-      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
-      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
-      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
-      a.setPathsAndPackageNames(A.class);
-      KernelControllerContext contextA = install(a);
-      try
-      {
-         ClassLoader clA = assertClassLoader(contextA);
-         Module moduleA = assertModule(contextA);
-         Class<?> result = moduleA.loadClass(A.class.getName());
-         assertEquals(clA, result.getClassLoader());
-         
-         Module other = moduleA.getModuleForClass(A.class.getName());
-         assertEquals(moduleA, other);
-         
-         assertEquals(moduleA, ClassLoading.getModuleForClassLoader(clA));
-         assertEquals(clA, ClassLoading.getClassLoaderForModule(moduleA));
-      }
-      finally
-      {
-         uninstall(contextA);
-      }
-      assertNoClassLoader(contextA);
-   }
-   
-   public void testLoadClassFromOtherModule() throws Exception
-   {
-      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
-      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
-      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
-      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
-      a.setPathsAndPackageNames(A.class);
-      KernelControllerContext contextA = install(a);
-      try
-      {
-         ClassLoader clA = assertClassLoader(contextA);
-         Module moduleA = assertModule(contextA);
-
-         assertEquals(moduleA, ClassLoading.getModuleForClassLoader(clA));
-
-         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
-         b.getRequirements().addRequirement(factory.createRequireModule("ModuleA"));
-         b.setPathsAndPackageNames(B.class);
-         KernelControllerContext contextB = install(b);
-         try
-         {
-            ClassLoader clB = assertClassLoader(contextB);
-            Module moduleB = assertModule(contextB);
-            Class<?> result = moduleB.loadClass(A.class.getName());
-            assertEquals(clA, result.getClassLoader());
-            
-            Module other = moduleB.getModuleForClass(A.class.getName());
-            assertEquals(moduleA, other);
-
-            assertEquals(moduleA, ClassLoading.getModuleForClassLoader(clA));
-            assertEquals(moduleB, ClassLoading.getModuleForClassLoader(clB));
-            assertEquals(clA, ClassLoading.getClassLoaderForModule(moduleA));
-            assertEquals(clB, ClassLoading.getClassLoaderForModule(moduleB));
-         }
-         finally
-         {
-            uninstall(contextB);
-         }
-      }
-      finally
-      {
-         uninstall(contextA);
-      }
-      assertNoClassLoader(contextA);
-   }
-   
-   public void testLoadClassFromOtherModuleDuplicates() throws Exception
-   {
-      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
-      MockClassLoadingMetaData a1 = new MockClassLoadingMetaData("a", "1.0.0");
-      a1.getCapabilities().addCapability(factory.createModule("ModuleA", "1.0.0"));
-      a1.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
-      a1.setPathsAndPackageNames(A.class);
-      KernelControllerContext contextA1 = install(a1);
-      try
-      {
-         ClassLoader clA1 = assertClassLoader(contextA1);
-         Module moduleA1 = assertModule(contextA1);
-
-         assertEquals(moduleA1, ClassLoading.getModuleForClassLoader(clA1));
-
-         MockClassLoadingMetaData a2 = new MockClassLoadingMetaData("a", "2.0.0");
-         a2.getCapabilities().addCapability(factory.createModule("ModuleA", "2.0.0"));
-         a2.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
-         a2.setPathsAndPackageNames(A.class);
-         KernelControllerContext contextA2 = install(a2);
-         try
-         {
-            ClassLoader clA2 = assertClassLoader(contextA2);
-            Module moduleA2 = assertModule(contextA2);
-
-            assertEquals(moduleA1, ClassLoading.getModuleForClassLoader(clA1));
-            assertEquals(moduleA2, ClassLoading.getModuleForClassLoader(clA2));
-
-            MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
-            b.getRequirements().addRequirement(factory.createRequireModule("ModuleA", new VersionRange("2.0.0")));
-            b.setPathsAndPackageNames(B.class);
-            KernelControllerContext contextB = install(b);
-            try
-            {
-               ClassLoader clB = assertClassLoader(contextB);
-               Module moduleB = assertModule(contextB);
-               Class<?> result = moduleB.loadClass(A.class.getName());
-               assertEquals(clA2, result.getClassLoader());
-               
-               Module other = moduleB.getModuleForClass(A.class.getName());
-               assertEquals(moduleA2, other);
-
-               assertEquals(moduleA1, ClassLoading.getModuleForClassLoader(clA1));
-               assertEquals(moduleA2, ClassLoading.getModuleForClassLoader(clA2));
-               assertEquals(moduleB, ClassLoading.getModuleForClassLoader(clB));
-               assertEquals(clA1, ClassLoading.getClassLoaderForModule(moduleA1));
-               assertEquals(clA2, ClassLoading.getClassLoaderForModule(moduleA2));
-               assertEquals(clB, ClassLoading.getClassLoaderForModule(moduleB));
-            }
-            finally
-            {
-               uninstall(contextB);
-            }
-         }
-         finally
-         {
-            uninstall(contextA2);
-         }
-         assertNoClassLoader(contextA2);
-      }
-      finally
-      {
-         uninstall(contextA1);
-      }
-      assertNoClassLoader(contextA1);
-   }
-   
-   public void testLoadClassNotFound() throws Exception
-   {
-      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
-      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
-      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
-      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
-      a.setPathsAndPackageNames(A.class);
-      KernelControllerContext contextA = install(a);
-      try
-      {
-         assertClassLoader(contextA);
-         Module moduleA = assertModule(contextA);
-
-         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
-         b.getRequirements().addRequirement(factory.createRequireModule("ModuleA"));
-         b.setPathsAndPackageNames(B.class);
-         KernelControllerContext contextB = install(b);
-         try
-         {
-            assertClassLoader(contextB);
-            try
-            {
-               moduleA.loadClass(C.class.getName());
-               fail("Should not be here!");
-            }
-            catch (Exception e)
-            {
-               checkThrowable(ClassNotFoundException.class, e);
-            }
-            try
-            {
-               moduleA.getModuleForClass(C.class.getName());
-               fail("Should not be here!");
-            }
-            catch (Exception e)
-            {
-               checkThrowable(ClassNotFoundException.class, e);
-            }
-            Module moduleB = assertModule(contextB);
-            try
-            {
-               moduleB.loadClass(C.class.getName());
-               fail("Should not be here!");
-            }
-            catch (Exception e)
-            {
-               checkThrowable(ClassNotFoundException.class, e);
-            }
-            try
-            {
-               moduleB.getModuleForClass(C.class.getName());
-               fail("Should not be here!");
-            }
-            catch (Exception e)
-            {
-               checkThrowable(ClassNotFoundException.class, e);
-            }
-         }
-         finally
-         {
-            uninstall(contextB);
-         }
-      }
-      finally
-      {
-         uninstall(contextA);
-      }
-      assertNoClassLoader(contextA);
-   }
-   
-   public void testLoadClassNotAModule() throws Exception
-   {
-      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
-      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
-      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
-      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
-      a.setPathsAndPackageNames(A.class);
-      KernelControllerContext contextA = install(a);
-      try
-      {
-         assertClassLoader(contextA);
-         Module moduleA = assertModule(contextA);
-
-         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
-         b.getRequirements().addRequirement(factory.createRequireModule("ModuleA"));
-         b.setPathsAndPackageNames(B.class);
-         KernelControllerContext contextB = install(b);
-         try
-         {
-            assertClassLoader(contextB);
-            Module moduleB = assertModule(contextB);
-            moduleA.loadClass(Object.class.getName());
-            assertNull(moduleA.getModuleForClass(Object.class.getName()));
-            moduleB.loadClass(Object.class.getName());
-            assertNull(moduleB.getModuleForClass(Object.class.getName()));
-            
-            assertNull(ClassLoading.getModuleForClassLoader(Object.class.getClassLoader()));
-         }
-         finally
-         {
-            uninstall(contextB);
-         }
-      }
-      finally
-      {
-         uninstall(contextA);
-      }
-      assertNoClassLoader(contextA);
-   }
-   
-   public void testGetResourceFromThisModule() throws Exception
-   {
-      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
-      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
-      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
-      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
-      a.setPathsAndPackageNames(A.class);
-      KernelControllerContext contextA = install(a);
-      try
-      {
-         assertClassLoader(contextA);
-         String path = ClassLoaderUtils.classNameToPath(A.class);
-         URL expected = getResource("/" + path);
-         Module moduleA = assertModule(contextA);
-         URL actual = moduleA.getResource(path);
-         assertEquals(expected, actual);
-         
-         Enumeration<URL> actuals = moduleA.getResources(path);
-         assertTrue(actuals.hasMoreElements());
-         actual = actuals.nextElement();
-         assertEquals(expected, actual);
-         assertFalse(actuals.hasMoreElements());
-      }
-      finally
-      {
-         uninstall(contextA);
-      }
-      assertNoClassLoader(contextA);
-   }
-}

Copied: projects/jboss-cl/tags/2.0.2.GA/classloading/src/test/java/org/jboss/test/classloading/dependency/test/ModuleClassLoadingUnitTestCase.java (from rev 83469, projects/jboss-cl/branches/Branch_2_0/classloading/src/test/java/org/jboss/test/classloading/dependency/test/ModuleClassLoadingUnitTestCase.java)
===================================================================
--- projects/jboss-cl/tags/2.0.2.GA/classloading/src/test/java/org/jboss/test/classloading/dependency/test/ModuleClassLoadingUnitTestCase.java	                        (rev 0)
+++ projects/jboss-cl/tags/2.0.2.GA/classloading/src/test/java/org/jboss/test/classloading/dependency/test/ModuleClassLoadingUnitTestCase.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -0,0 +1,524 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.classloading.dependency.test;
+
+import java.net.URL;
+import java.util.Enumeration;
+
+import junit.framework.Test;
+
+import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.classloading.spi.dependency.ClassLoading;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.classloading.dependency.support.a.A;
+import org.jboss.test.classloading.dependency.support.b.B;
+import org.jboss.test.classloading.dependency.support.c.C;
+
+/**
+ * ModuleClassLoadingUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ModuleClassLoadingUnitTestCase extends AbstractMockClassLoaderUnitTest
+{
+   public static Test suite()
+   {
+      return suite(ModuleClassLoadingUnitTestCase.class);
+   }
+
+   public ModuleClassLoadingUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testLoadClassFromThisModule() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
+      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         Module moduleA = assertModule(contextA);
+         Class<?> result = moduleA.loadClass(A.class.getName());
+         assertEquals(clA, result.getClassLoader());
+         
+         Module other = moduleA.getModuleForClass(A.class.getName());
+         assertEquals(moduleA, other);
+         
+         assertEquals(moduleA, ClassLoading.getModuleForClassLoader(clA));
+         assertEquals(clA, ClassLoading.getClassLoaderForModule(moduleA));
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testLoadClassFromOtherModule() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
+      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         ClassLoader clA = assertClassLoader(contextA);
+         Module moduleA = assertModule(contextA);
+
+         assertEquals(moduleA, ClassLoading.getModuleForClassLoader(clA));
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createRequireModule("ModuleA"));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            ClassLoader clB = assertClassLoader(contextB);
+            Module moduleB = assertModule(contextB);
+            Class<?> result = moduleB.loadClass(A.class.getName());
+            assertEquals(clA, result.getClassLoader());
+            
+            Module other = moduleB.getModuleForClass(A.class.getName());
+            assertEquals(moduleA, other);
+
+            assertEquals(moduleA, ClassLoading.getModuleForClassLoader(clA));
+            assertEquals(moduleB, ClassLoading.getModuleForClassLoader(clB));
+            assertEquals(clA, ClassLoading.getClassLoaderForModule(moduleA));
+            assertEquals(clB, ClassLoading.getClassLoaderForModule(moduleB));
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testLoadClassFromOtherModuleDuplicates() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      MockClassLoadingMetaData a1 = new MockClassLoadingMetaData("a", "1.0.0");
+      a1.getCapabilities().addCapability(factory.createModule("ModuleA", "1.0.0"));
+      a1.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a1.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA1 = install(a1);
+      try
+      {
+         ClassLoader clA1 = assertClassLoader(contextA1);
+         Module moduleA1 = assertModule(contextA1);
+
+         assertEquals(moduleA1, ClassLoading.getModuleForClassLoader(clA1));
+
+         MockClassLoadingMetaData a2 = new MockClassLoadingMetaData("a", "2.0.0");
+         a2.getCapabilities().addCapability(factory.createModule("ModuleA", "2.0.0"));
+         a2.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+         a2.setPathsAndPackageNames(A.class);
+         KernelControllerContext contextA2 = install(a2);
+         try
+         {
+            ClassLoader clA2 = assertClassLoader(contextA2);
+            Module moduleA2 = assertModule(contextA2);
+
+            assertEquals(moduleA1, ClassLoading.getModuleForClassLoader(clA1));
+            assertEquals(moduleA2, ClassLoading.getModuleForClassLoader(clA2));
+
+            MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+            b.getRequirements().addRequirement(factory.createRequireModule("ModuleA", new VersionRange("2.0.0")));
+            b.setPathsAndPackageNames(B.class);
+            KernelControllerContext contextB = install(b);
+            try
+            {
+               ClassLoader clB = assertClassLoader(contextB);
+               Module moduleB = assertModule(contextB);
+               Class<?> result = moduleB.loadClass(A.class.getName());
+               assertEquals(clA2, result.getClassLoader());
+               
+               Module other = moduleB.getModuleForClass(A.class.getName());
+               assertEquals(moduleA2, other);
+
+               assertEquals(moduleA1, ClassLoading.getModuleForClassLoader(clA1));
+               assertEquals(moduleA2, ClassLoading.getModuleForClassLoader(clA2));
+               assertEquals(moduleB, ClassLoading.getModuleForClassLoader(clB));
+               assertEquals(clA1, ClassLoading.getClassLoaderForModule(moduleA1));
+               assertEquals(clA2, ClassLoading.getClassLoaderForModule(moduleA2));
+               assertEquals(clB, ClassLoading.getClassLoaderForModule(moduleB));
+            }
+            finally
+            {
+               uninstall(contextB);
+            }
+         }
+         finally
+         {
+            uninstall(contextA2);
+         }
+         assertNoClassLoader(contextA2);
+      }
+      finally
+      {
+         uninstall(contextA1);
+      }
+      assertNoClassLoader(contextA1);
+   }
+   
+   public void testLoadClassNotFound() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
+      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         assertClassLoader(contextA);
+         Module moduleA = assertModule(contextA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createRequireModule("ModuleA"));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertClassLoader(contextB);
+            try
+            {
+               moduleA.loadClass(C.class.getName());
+               fail("Should not be here!");
+            }
+            catch (Exception e)
+            {
+               checkThrowable(ClassNotFoundException.class, e);
+            }
+            try
+            {
+               moduleA.getModuleForClass(C.class.getName());
+               fail("Should not be here!");
+            }
+            catch (Exception e)
+            {
+               checkThrowable(ClassNotFoundException.class, e);
+            }
+            Module moduleB = assertModule(contextB);
+            try
+            {
+               moduleB.loadClass(C.class.getName());
+               fail("Should not be here!");
+            }
+            catch (Exception e)
+            {
+               checkThrowable(ClassNotFoundException.class, e);
+            }
+            try
+            {
+               moduleB.getModuleForClass(C.class.getName());
+               fail("Should not be here!");
+            }
+            catch (Exception e)
+            {
+               checkThrowable(ClassNotFoundException.class, e);
+            }
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testLoadClassNotAModule() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
+      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         assertClassLoader(contextA);
+         Module moduleA = assertModule(contextA);
+
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createRequireModule("ModuleA"));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+         try
+         {
+            assertClassLoader(contextB);
+            Module moduleB = assertModule(contextB);
+            moduleA.loadClass(Object.class.getName());
+            assertNull(moduleA.getModuleForClass(Object.class.getName()));
+            moduleB.loadClass(Object.class.getName());
+            assertNull(moduleB.getModuleForClass(Object.class.getName()));
+            
+            assertNull(ClassLoading.getModuleForClassLoader(Object.class.getClassLoader()));
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testGetResourceFromThisModule() throws Exception
+   {
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
+      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+      try
+      {
+         assertClassLoader(contextA);
+         String path = ClassLoaderUtils.classNameToPath(A.class);
+         URL expected = getResource("/" + path);
+         Module moduleA = assertModule(contextA);
+         URL actual = moduleA.getResource(path);
+         assertEquals(expected, actual);
+         
+         Enumeration<URL> actuals = moduleA.getResources(path);
+         assertTrue(actuals.hasMoreElements());
+         actual = actuals.nextElement();
+         assertEquals(expected, actual);
+         assertFalse(actuals.hasMoreElements());
+      }
+      finally
+      {
+         uninstall(contextA);
+      }
+      assertNoClassLoader(contextA);
+   }
+   
+   public void testSeveralModulesWithSamePackages() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+      MockClassLoadingMetaData x = new MockClassLoadingMetaData("x");
+      x.getCapabilities().addCapability(factory.createModule("ModuleX"));
+      x.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      x.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextX = install(x);
+
+      MockClassLoadingMetaData a = new MockClassLoadingMetaData("a");
+      a.getCapabilities().addCapability(factory.createModule("ModuleA"));
+      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA = install(a);
+
+      MockClassLoadingMetaData y = new MockClassLoadingMetaData("y");
+      y.getCapabilities().addCapability(factory.createModule("ModuleY"));
+      y.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      y.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextY = install(y);
+
+      try
+      {
+         ClassLoader clX = assertClassLoader(contextX);
+         ClassLoader clA = assertClassLoader(contextA);
+         ClassLoader clY = assertClassLoader(contextY);
+
+         assertLoadClass(A.class, clX);
+         assertLoadClass(A.class, clA);
+         assertLoadClass(A.class, clY);
+         
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createRequireModule("ModuleA"));
+         b.getCapabilities().addCapability(factory.createPackage(B.class.getPackage().getName()));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+
+         try
+         {
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA);
+            
+            Module moduleA = assertModule(contextA);
+            Module moduleB = assertModule(contextB);
+            Module result = moduleB.getModuleForClass(A.class.getName());
+            assertSame(moduleA, result);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+      }
+      finally
+      {
+         uninstall(contextX);
+         uninstall(contextA);
+         uninstall(contextY);
+      }
+   }
+   
+   public void testSeveralModulesWithSameNamesDifferentVersions() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+      MockClassLoadingMetaData a1 = new MockClassLoadingMetaData("a1");
+      a1.getCapabilities().addCapability(factory.createModule("ModuleA", "1.0.0"));
+      a1.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a1.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA1 = install(a1);
+
+      MockClassLoadingMetaData a2 = new MockClassLoadingMetaData("a2");
+      a2.getCapabilities().addCapability(factory.createModule("ModuleA", "2.0.0"));
+      a2.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a2.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA2 = install(a2);
+
+      MockClassLoadingMetaData a3 = new MockClassLoadingMetaData("a3");
+      a3.getCapabilities().addCapability(factory.createModule("ModuleA", "3.0.0"));
+      a3.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a3.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA3 = install(a3);
+
+      try
+      {
+         ClassLoader clA1 = assertClassLoader(contextA1);
+         ClassLoader clA2 = assertClassLoader(contextA2);
+         ClassLoader clA3 = assertClassLoader(contextA3);
+
+         assertLoadClass(A.class, clA1);
+         assertLoadClass(A.class, clA2);
+         assertLoadClass(A.class, clA3);
+         
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createRequireModule("ModuleA", new VersionRange("2.0.0", true, "3.0.0", false)));
+         b.getCapabilities().addCapability(factory.createPackage(B.class.getPackage().getName()));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+
+         try
+         {
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA2);
+            
+            Module moduleA2 = assertModule(contextA2);
+            Module moduleB = assertModule(contextB);
+            Module result = moduleB.getModuleForClass(A.class.getName());
+            assertSame(moduleA2, result);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+      }
+      finally
+      {
+         uninstall(contextA1);
+         uninstall(contextA2);
+         uninstall(contextA3);
+      }
+   }
+
+   public void testSeveralModulesWithSamePackagesDifferentVersions() throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+
+      MockClassLoadingMetaData a1 = new MockClassLoadingMetaData("a1");
+      a1.getCapabilities().addCapability(factory.createModule("ModuleA"));
+      a1.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName(), "1.0.0"));
+      a1.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA1 = install(a1);
+
+      MockClassLoadingMetaData a2 = new MockClassLoadingMetaData("a2");
+      a2.getCapabilities().addCapability(factory.createModule("ModuleA"));
+      a2.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName(), "2.0.0"));
+      a2.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA2 = install(a2);
+
+      MockClassLoadingMetaData a3 = new MockClassLoadingMetaData("a3");
+      a3.getCapabilities().addCapability(factory.createModule("ModuleA"));
+      a3.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName(), "3.0.0"));
+      a3.setPathsAndPackageNames(A.class);
+      KernelControllerContext contextA3 = install(a3);
+
+      try
+      {
+         ClassLoader clA1 = assertClassLoader(contextA1);
+         ClassLoader clA2 = assertClassLoader(contextA2);
+         ClassLoader clA3 = assertClassLoader(contextA3);
+
+         assertLoadClass(A.class, clA1);
+         assertLoadClass(A.class, clA2);
+         assertLoadClass(A.class, clA3);
+         
+         MockClassLoadingMetaData b = new MockClassLoadingMetaData("b");
+         b.getRequirements().addRequirement(factory.createRequirePackage(A.class.getPackage().getName(), new VersionRange("2.0.0", true, "3.0.0", false)));
+         b.getCapabilities().addCapability(factory.createPackage(B.class.getPackage().getName()));
+         b.setPathsAndPackageNames(B.class);
+         KernelControllerContext contextB = install(b);
+
+         try
+         {
+            ClassLoader clB = assertClassLoader(contextB);
+            assertLoadClass(B.class, clB);
+            assertLoadClass(A.class, clB, clA2);
+            
+            Module moduleA2 = assertModule(contextA2);
+            Module moduleB = assertModule(contextB);
+            Module result = moduleB.getModuleForClass(A.class.getName());
+            assertSame(moduleA2, result);
+         }
+         finally
+         {
+            uninstall(contextB);
+         }
+      }
+      finally
+      {
+         uninstall(contextA1);
+         uninstall(contextA2);
+         uninstall(contextA3);
+      }
+   }
+}

Deleted: projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/pom.xml
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading-vfs/pom.xml	2009-01-27 11:39:59 UTC (rev 83468)
+++ projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/pom.xml	2009-01-27 13:22:11 UTC (rev 83485)
@@ -1,128 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <parent>
-    <groupId>org.jboss.cl</groupId>
-    <artifactId>jboss-cl</artifactId>
-    <version>2.0.2-SNAPSHOT</version>
-    <relativePath>../build</relativePath>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-  <artifactId>jboss-classloading-vfs</artifactId>
-  <packaging>jar</packaging>
-  <name>JBoss ClassLoading VFS</name>
-  <url>http://www.jboss.org/jbossmc</url>
-  <description>JBoss ClassLoading VFS</description>
-  
-  <!-- Do not add version information here, use ../pom.xml instead -->
-  <dependencies>
-    
-    <!-- Global dependencies -->
-    <dependency>
-      <groupId>org.jboss</groupId>
-      <artifactId>jboss-common-core</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.logging</groupId>
-      <artifactId>jboss-logging-spi</artifactId>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.cl</groupId>
-      <artifactId>jboss-classloading</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss.microcontainer</groupId>
-          <artifactId>jboss-kernel</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.microcontainer</groupId>
-      <artifactId>jboss-kernel</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-common-core</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>jboss</groupId>
-          <artifactId>jboss-common-logging-spi</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jbossxb</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss</groupId>
-      <artifactId>jbossxb</artifactId>
-      <optional>true</optional>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-reflect</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-common-core</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>jboss</groupId>
-          <artifactId>jboss-common-logging-spi</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss.man</groupId>
-      <artifactId>jboss-managed</artifactId>
-      <optional>true</optional>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-reflect</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-common-core</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>jboss</groupId>
-          <artifactId>jboss-common-logging-spi</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    
-    <dependency>
-      <groupId>org.jboss</groupId>
-      <artifactId>jboss-vfs</artifactId>
-      <exclusions>
-        <exclusion>
-          <groupId>org.jboss</groupId>
-          <artifactId>jboss-common-core</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>jboss</groupId>
-          <artifactId>jboss-common-logging-spi</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    
-    <!-- Test dependencies -->
-    <dependency>
-      <groupId>org.jboss.test</groupId>
-      <artifactId>jboss-test</artifactId>
-      <scope>test</scope>
-    </dependency>
-    
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
-    
-  </dependencies>  
-</project>
\ No newline at end of file

Copied: projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/pom.xml (from rev 83484, projects/jboss-cl/branches/Branch_2_0/classloading-vfs/pom.xml)
===================================================================
--- projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/pom.xml	                        (rev 0)
+++ projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/pom.xml	2009-01-27 13:22:11 UTC (rev 83485)
@@ -0,0 +1,128 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.jboss.cl</groupId>
+    <artifactId>jboss-cl</artifactId>
+    <version>2.0.2.GA</version>
+    <relativePath>../build</relativePath>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>jboss-classloading-vfs</artifactId>
+  <packaging>jar</packaging>
+  <name>JBoss ClassLoading VFS</name>
+  <url>http://www.jboss.org/jbossmc</url>
+  <description>JBoss ClassLoading VFS</description>
+  
+  <!-- Do not add version information here, use ../pom.xml instead -->
+  <dependencies>
+    
+    <!-- Global dependencies -->
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-common-core</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-spi</artifactId>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.cl</groupId>
+      <artifactId>jboss-classloading</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss.microcontainer</groupId>
+          <artifactId>jboss-kernel</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-kernel</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-common-core</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>jboss</groupId>
+          <artifactId>jboss-common-logging-spi</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jbossxb</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jbossxb</artifactId>
+      <optional>true</optional>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-reflect</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-common-core</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>jboss</groupId>
+          <artifactId>jboss-common-logging-spi</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss.man</groupId>
+      <artifactId>jboss-managed</artifactId>
+      <optional>true</optional>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-reflect</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-common-core</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>jboss</groupId>
+          <artifactId>jboss-common-logging-spi</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-vfs</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>org.jboss</groupId>
+          <artifactId>jboss-common-core</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>jboss</groupId>
+          <artifactId>jboss-common-logging-spi</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    
+    <!-- Test dependencies -->
+    <dependency>
+      <groupId>org.jboss.test</groupId>
+      <artifactId>jboss-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
+  </dependencies>  
+</project>
\ No newline at end of file

Deleted: projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java	2009-01-27 11:39:59 UTC (rev 83468)
+++ projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -1,248 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, 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.classloading.spi.vfs.dependency;
-
-import java.net.URI;
-import java.net.URL;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.jboss.classloader.spi.filter.ClassFilter;
-import org.jboss.classloading.plugins.vfs.PackageVisitor;
-import org.jboss.classloading.plugins.vfs.VFSResourceVisitor;
-import org.jboss.classloading.spi.dependency.policy.ClassLoaderPolicyModule;
-import org.jboss.classloading.spi.metadata.Capability;
-import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
-import org.jboss.classloading.spi.metadata.ExportAll;
-import org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory;
-import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
-import org.jboss.classloading.spi.visitor.ResourceFilter;
-import org.jboss.classloading.spi.visitor.ResourceVisitor;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
-import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * VFSClassLoaderPolicyModule.
- * 
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class VFSClassLoaderPolicyModule extends ClassLoaderPolicyModule implements KernelControllerContextAware
-{
-   /** The serialVersionUID */
-   private static final long serialVersionUID = 1L;
-
-   /** The roots */
-   private List<String> roots;
-   
-   /** Our cached vfs roots */
-   private VirtualFile[] vfsRoots;
-
-   /**
-    * Create a new VFSClassLoaderPolicyModule.
-    * 
-    * @param classLoadingMetaData the classloading metadata
-    * @param contextName the context name
-    */
-   public VFSClassLoaderPolicyModule(VFSClassLoaderFactory classLoadingMetaData, String contextName)
-   {
-      super(classLoadingMetaData, contextName);
-   }
-   
-   /**
-    * Get the roots.
-    * 
-    * @return the roots.
-    */
-   public List<String> getRoots()
-   {
-      return roots;
-   }
-
-   /**
-    * Set the roots.
-    * 
-    * @param roots the roots.
-    */
-   public void setRoots(List<String> roots)
-   {
-      this.roots = roots;
-   }
-
-   @Override
-   protected List<Capability> determineCapabilities()
-   {
-      // While we are here, check the roots
-      VirtualFile[] roots = determineVFSRoots();
-
-      List<Capability> capabilities = super.determineCapabilities();
-      if (capabilities != null)
-         return capabilities;
-         
-      // We need to work it out
-      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
-      capabilities = new CopyOnWriteArrayList<Capability>();
-
-      // We have a module capability
-      Object version = getVersion();
-      Capability capability = factory.createModule(getName(), version);
-      capabilities.add(capability);
-      
-      // Do we determine package capabilities
-      ClassFilter included = getIncluded();
-      ClassFilter excluded = getExcluded();
-      ClassFilter excludedExport = getExcludedExport();
-      ExportAll exportAll = getExportAll();
-      if (exportAll != null)
-      {
-         Set<String> exportedPackages = PackageVisitor.determineAllPackages(roots, null, exportAll, included, excluded, excludedExport);
-         for (String packageName : exportedPackages)
-         {
-            capability = factory.createPackage(packageName, version);
-            capabilities.add(capability);
-         }
-      }
-      
-      return capabilities;
-   }
-
-   public void setKernelControllerContext(KernelControllerContext context) throws Exception
-   {
-      setControllerContext(context);
-   }
-
-   public void unsetKernelControllerContext(KernelControllerContext context) throws Exception
-   {
-      setControllerContext(null);
-   }
-
-   @Override
-   protected VFSClassLoaderFactory getClassLoadingMetaData()
-   {
-      return (VFSClassLoaderFactory) super.getClassLoadingMetaData();
-   }
-   
-   /**
-    * Get the virtual file roots
-    * 
-    * @return the roots
-    */
-   protected VirtualFile[] determineVFSRoots()
-   {
-      if (vfsRoots != null)
-         return vfsRoots;
-      
-      if (roots == null)
-      {
-         vfsRoots = new VirtualFile[0];
-      }
-      else
-      {
-         VirtualFile[] vfsRoots = new VirtualFile[roots.size()];
-         for (int i = 0; i < roots.size(); ++i)
-         {
-            String root = roots.get(i);
-            try
-            {
-               URI uri = new URI(root);
-               vfsRoots[i] = getVirtualFile(uri);
-            }
-            catch (RuntimeException e)
-            {
-               throw e;
-            }
-            catch (Exception e)
-            {
-               throw new RuntimeException("Error creating VFS file for " + root, e);
-            }
-         }
-         this.vfsRoots = vfsRoots;
-      }
-      return vfsRoots;
-   }
-
-   /**
-    * Get virtual file for uri.
-    *
-    * @param uri the uri
-    * @return virtual file for uri
-    * @throws Exception for any error
-    */
-   protected VirtualFile getVirtualFile(URI uri) throws Exception
-   {
-      if (isCacheable())
-         return VFS.getCachedFile(uri);
-      else
-         return VFS.getRoot(uri);
-   }
-
-   @Override
-   public VFSClassLoaderPolicy getPolicy()
-   {
-      return (VFSClassLoaderPolicy) super.getPolicy();
-   }
-   
-   @Override
-   protected VFSClassLoaderPolicy determinePolicy()
-   {
-      VirtualFile[] roots = determineVFSRoots();
-      VFSClassLoaderPolicy policy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy(getContextName(), roots);
-      
-      String[] packageNames = getPackageNames();
-      policy.setExportedPackages(packageNames);
-      policy.setIncluded(getIncluded());
-      policy.setExcluded(getExcluded());
-      policy.setExcludedExport(getExcludedExport());
-      policy.setExportAll(getExportAll());
-      policy.setImportAll(isImportAll());
-      policy.setCacheable(isCacheable());
-      policy.setBlackListable(isBlackListable());
-      policy.setDelegates(getDelegates());
-      return policy;
-   }
-
-   @Override
-   public void reset()
-   {
-      super.reset();
-      vfsRoots = null;
-   }
-
-   @Override
-   public void visit(ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter, URL... urls)
-   {
-      ClassLoader classLoader = getClassLoader();
-      if (classLoader == null)
-         throw new IllegalStateException("ClassLoader has not been constructed for " + getContextName());
-
-      VirtualFile[] roots = determineVFSRoots();
-      if (roots != null && roots.length > 0)
-      {
-         ClassFilter included = getIncluded();
-         ClassFilter excluded = getExcluded();
-         VFSResourceVisitor.visit(roots, null, included, excluded, classLoader, visitor, filter, recurseFilter, urls);
-      }
-   } 
-}

Copied: projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java (from rev 83482, projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java)
===================================================================
--- projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java	                        (rev 0)
+++ projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/src/main/java/org/jboss/classloading/spi/vfs/dependency/VFSClassLoaderPolicyModule.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -0,0 +1,248 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, 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.classloading.spi.vfs.dependency;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloading.plugins.vfs.PackageVisitor;
+import org.jboss.classloading.plugins.vfs.VFSResourceVisitor;
+import org.jboss.classloading.spi.dependency.policy.ClassLoaderPolicyModule;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.ExportAll;
+import org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory;
+import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
+import org.jboss.classloading.spi.visitor.ResourceFilter;
+import org.jboss.classloading.spi.visitor.ResourceVisitor;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * VFSClassLoaderPolicyModule.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class VFSClassLoaderPolicyModule extends ClassLoaderPolicyModule implements KernelControllerContextAware
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+
+   /** The roots */
+   private List<String> roots;
+
+   /** Our cached vfs roots */
+   private VirtualFile[] vfsRoots;
+
+   /**
+    * Create a new VFSClassLoaderPolicyModule.
+    *
+    * @param classLoadingMetaData the classloading metadata
+    * @param contextName the context name
+    */
+   public VFSClassLoaderPolicyModule(VFSClassLoaderFactory classLoadingMetaData, String contextName)
+   {
+      super(classLoadingMetaData, contextName);
+   }
+
+   /**
+    * Get the roots.
+    *
+    * @return the roots.
+    */
+   public List<String> getRoots()
+   {
+      return roots;
+   }
+
+   /**
+    * Set the roots.
+    *
+    * @param roots the roots.
+    */
+   public void setRoots(List<String> roots)
+   {
+      this.roots = roots;
+   }
+
+   @Override
+   protected List<Capability> determineCapabilities()
+   {
+      // While we are here, check the roots
+      VirtualFile[] roots = determineVFSRoots();
+
+      List<Capability> capabilities = super.determineCapabilities();
+      if (capabilities != null)
+         return capabilities;
+
+      // We need to work it out
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      capabilities = new CopyOnWriteArrayList<Capability>();
+
+      // We have a module capability
+      Object version = getVersion();
+      Capability capability = factory.createModule(getName(), version);
+      capabilities.add(capability);
+
+      // Do we determine package capabilities
+      ClassFilter included = getIncluded();
+      ClassFilter excluded = getExcluded();
+      ClassFilter excludedExport = getExcludedExport();
+      ExportAll exportAll = getExportAll();
+      if (exportAll != null)
+      {
+         Set<String> exportedPackages = PackageVisitor.determineAllPackages(roots, null, exportAll, included, excluded, excludedExport);
+         for (String packageName : exportedPackages)
+         {
+            capability = factory.createPackage(packageName, version);
+            capabilities.add(capability);
+         }
+      }
+
+      return capabilities;
+   }
+
+   public void setKernelControllerContext(KernelControllerContext context) throws Exception
+   {
+      setControllerContext(context);
+   }
+
+   public void unsetKernelControllerContext(KernelControllerContext context) throws Exception
+   {
+      setControllerContext(null);
+   }
+
+   @Override
+   protected VFSClassLoaderFactory getClassLoadingMetaData()
+   {
+      return (VFSClassLoaderFactory) super.getClassLoadingMetaData();
+   }
+
+   /**
+    * Get the virtual file roots
+    *
+    * @return the roots
+    */
+   protected VirtualFile[] determineVFSRoots()
+   {
+      if (vfsRoots != null)
+         return vfsRoots;
+
+      if (roots == null)
+      {
+         vfsRoots = new VirtualFile[0];
+      }
+      else
+      {
+         VirtualFile[] vfsRoots = new VirtualFile[roots.size()];
+         for (int i = 0; i < roots.size(); ++i)
+         {
+            String root = roots.get(i);
+            try
+            {
+               URI uri = new URI(root);
+               vfsRoots[i] = getVirtualFile(uri);
+            }
+            catch (RuntimeException e)
+            {
+               throw e;
+            }
+            catch (Exception e)
+            {
+               throw new RuntimeException("Error creating VFS file for " + root, e);
+            }
+         }
+         this.vfsRoots = vfsRoots;
+      }
+      return vfsRoots;
+   }
+
+   /**
+    * Get virtual file for uri.
+    *
+    * @param uri the uri
+    * @return virtual file for uri
+    * @throws Exception for any error
+    */
+   protected VirtualFile getVirtualFile(URI uri) throws Exception
+   {
+      if (isCacheable())
+         return VFS.getRoot(uri);
+      else
+         return VFS.createNewRoot(uri);
+   }
+
+   @Override
+   public VFSClassLoaderPolicy getPolicy()
+   {
+      return (VFSClassLoaderPolicy) super.getPolicy();
+   }
+
+   @Override
+   protected VFSClassLoaderPolicy determinePolicy()
+   {
+      VirtualFile[] roots = determineVFSRoots();
+      VFSClassLoaderPolicy policy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy(getContextName(), roots);
+
+      String[] packageNames = getPackageNames();
+      policy.setExportedPackages(packageNames);
+      policy.setIncluded(getIncluded());
+      policy.setExcluded(getExcluded());
+      policy.setExcludedExport(getExcludedExport());
+      policy.setExportAll(getExportAll());
+      policy.setImportAll(isImportAll());
+      policy.setCacheable(isCacheable());
+      policy.setBlackListable(isBlackListable());
+      policy.setDelegates(getDelegates());
+      return policy;
+   }
+
+   @Override
+   public void reset()
+   {
+      super.reset();
+      vfsRoots = null;
+   }
+
+   @Override
+   public void visit(ResourceVisitor visitor, ResourceFilter filter, ResourceFilter recurseFilter, URL... urls)
+   {
+      ClassLoader classLoader = getClassLoader();
+      if (classLoader == null)
+         throw new IllegalStateException("ClassLoader has not been constructed for " + getContextName());
+
+      VirtualFile[] roots = determineVFSRoots();
+      if (roots != null && roots.length > 0)
+      {
+         ClassFilter included = getIncluded();
+         ClassFilter excluded = getExcluded();
+         VFSResourceVisitor.visit(roots, null, included, excluded, classLoader, visitor, filter, recurseFilter, urls);
+      }
+   }
+}

Copied: projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/metadata/test/GeneratedClassesUnitTestCase.java (from rev 83469, projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/metadata/test/GeneratedClassesUnitTestCase.java)
===================================================================
--- projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/metadata/test/GeneratedClassesUnitTestCase.java	                        (rev 0)
+++ projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/src/test/java/org/jboss/test/classloading/vfs/metadata/test/GeneratedClassesUnitTestCase.java	2009-01-27 13:22:11 UTC (rev 83485)
@@ -0,0 +1,215 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.classloading.vfs.metadata.test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import junit.framework.Test;
+
+import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.classloading.spi.RealClassLoader;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.ExportAll;
+import org.jboss.classloading.spi.vfs.metadata.VFSClassLoaderFactory;
+import org.jboss.kernel.spi.deployment.KernelDeployment;
+import org.jboss.test.classloading.vfs.metadata.VFSClassLoadingMicrocontainerTest;
+import org.jboss.test.classloading.vfs.metadata.support.a.A;
+import org.jboss.test.classloading.vfs.metadata.support.b.B;
+import org.jboss.util.id.GUID;
+import org.jboss.virtual.MemoryFileFactory;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.plugins.context.memory.MemoryContextFactory;
+
+/**
+ * DomainUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class GeneratedClassesUnitTestCase extends VFSClassLoadingMicrocontainerTest
+{
+   final static GeneratedClassInfo DEFAULT_PACKAGE = new GeneratedClassInfo("DefaultGeneratedClass");
+   final static GeneratedClassInfo NEW_PACKAGE  = new GeneratedClassInfo("newpackage.GeneratedClass");
+   final static GeneratedClassInfo EXISTING_PACKAGE  = new GeneratedClassInfo("org.jboss.test.classloading.vfs.metadata.support.a.GeneratedClass");
+   static
+   {
+      VFS.init();
+   }
+   
+   public static Test suite()
+   {
+      return suite(GeneratedClassesUnitTestCase.class);
+   }
+
+   public GeneratedClassesUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testImportAllGenerateClassInExistingPackage() throws Exception
+   {
+      runImportAllGenerateClass(EXISTING_PACKAGE);
+   }
+   
+   public void testImportAllGenerateClassInDefaultPackage() throws Exception
+   {
+      runImportAllGenerateClass(DEFAULT_PACKAGE);      
+   }
+   
+   public void testImportAllGenerateClassInNewPackage() throws Exception
+   {
+      runImportAllGenerateClass(NEW_PACKAGE);
+   }
+   
+   
+   private void runImportAllGenerateClass(GeneratedClassInfo info) throws Exception
+   {
+      ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+      String dynamicClassRoot = getDynamicClassRoot();
+      VFSClassLoaderFactory a = new VFSClassLoaderFactory("a");
+      a.setImportAll(true);
+      a.getRoots().add(getRoot(A.class));
+      a.getRoots().add(dynamicClassRoot);
+      a.getCapabilities().addCapability(factory.createPackage(A.class.getPackage().getName()));
+      a.getCapabilities().addCapability(factory.createPackage(info.getPackageName()));
+      KernelDeployment depA = install(a);
+
+      VFSClassLoaderFactory b = new VFSClassLoaderFactory("b");
+      b.setExportAll(ExportAll.NON_EMPTY);
+      b.setImportAll(true);
+      b.getRoots().add(getRoot(B.class));
+      b.getCapabilities().addCapability(factory.createPackage(B.class.getPackage().getName()));
+      KernelDeployment depB = install(b);
+      try
+      {
+         ClassLoader clA = assertClassLoader(a);
+         ClassLoader clB = assertClassLoader(b);
+         assertLoadClass(A.class, clA);
+         assertLoadClass(B.class, clB);
+         assertLoadClass(A.class, clB, clA);
+         assertLoadClass(B.class, clA, clB);
+         
+         Class<?> clazz = generateClass(clA, dynamicClassRoot, info);
+         Class<?> clazzA = assertLoadClass(info.getClassname(), clA);
+         assertSame(clazz, clazzA);
+         Class<?> clazzB = assertLoadClass(info.getClassname(), clB, clA);
+         assertSame(clazz, clazzB);
+      }
+      finally
+      {
+         undeploy(depB);
+         undeploy(depA);
+      }
+   }
+
+   private Class<?> generateClass(ClassLoader loader, String dynamicClassRoot, GeneratedClassInfo info) throws Exception
+   {
+      URL outputURL = new URL(dynamicClassRoot + "/" + info.getResourceName());
+      MemoryContextFactory factory = MemoryContextFactory.getInstance();
+      factory.putFile(outputURL, info.getClassBytes());
+      
+      if (loader instanceof RealClassLoader)
+      {
+         ((RealClassLoader)loader).clearBlackList(info.getResourceName());
+      }
+      return loader.loadClass(info.getClassname());
+   }
+   
+   private String getDynamicClassRoot() throws Exception
+   {
+      URL dynamicClassRoot = new URL("vfsmemory", GUID.asString(), "");
+      MemoryFileFactory.createRoot(dynamicClassRoot).getRoot();
+      return dynamicClassRoot.toString();
+   }
+
+   private static class GeneratedClassInfo
+   {
+      String classname;
+      String resourceName;
+      byte[] classBytes;
+      
+      public GeneratedClassInfo(String classname)
+      {
+         this.classname = classname;
+         resourceName = ClassLoaderUtils.classNameToPath(classname);
+         loadClassBytes();
+      }
+      
+      public String getClassname()
+      {
+         return classname;
+      }
+      
+      public String getPackageName()
+      {
+         return ClassLoaderUtils.getClassPackageName(classname);
+      }
+
+      public String getResourceName()
+      {
+         return resourceName;
+      }
+
+      public byte[] getClassBytes()
+      {
+         return classBytes;
+      }
+
+      private void loadClassBytes()
+      {
+         InputStream in = this.getClass().getClassLoader().getResourceAsStream("classes/" + resourceName);
+         try
+         {
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            int i = in.read();
+            while(i != -1)
+            {
+               out.write((byte)i);
+               i = in.read();
+            }
+            classBytes = out.toByteArray();
+         }
+         catch(Exception e)
+         {
+            throw new RuntimeException(e);
+         }
+         finally
+         {
+            if (in != null)
+            {
+               try
+               {
+                  in.close();
+               }
+               catch (IOException e)
+               {
+                  // AutoGenerated
+                  throw new RuntimeException(e);
+               }
+            }
+         }
+      }
+   }
+}

Copied: projects/jboss-cl/tags/2.0.2.GA/classloading-vfs/src/test/resources/classes (from rev 83469, projects/jboss-cl/branches/Branch_2_0/classloading-vfs/src/test/resources/classes)

Deleted: projects/jboss-cl/tags/2.0.2.GA/pom.xml
===================================================================
--- projects/jboss-cl/branches/Branch_2_0/pom.xml	2009-01-27 11:39:59 UTC (rev 83468)
+++ projects/jboss-cl/tags/2.0.2.GA/pom.xml	2009-01-27 13:22:11 UTC (rev 83485)
@@ -1,301 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <modelVersion>4.0.0</modelVersion>
-  <parent>
-    <groupId>org.jboss</groupId>
-    <artifactId>jboss-parent</artifactId>
-    <version>4</version>
-  </parent>
-  <groupId>org.jboss.cl</groupId>
-  <artifactId>jboss-cl</artifactId>
-  <version>2.0.2-SNAPSHOT</version>
-  <packaging>pom</packaging>
-  <name>JBoss ClassLoader Parent POM</name>
-  <url>http://www.jboss.com/products/jbossmc</url>
-  <description>
-    JBoss ClassLoader
-  </description>
-  <scm>
-    <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/jboss-cl/branches/Branch_2_0/</connection>
-    <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/jboss-cl/branches/Branch_2_0/</developerConnection>
-    <url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/projects/jboss-cl/branches/Branch_2_0</url>
-  </scm>
-
-  <modules>
-    <module>classloader</module>
-    <module>classloading</module>
-    <module>classloading-vfs</module>
-    <module>build</module>
-  </modules>
-  
-  <properties>
-    <version.jboss.man>2.0.0.GA</version.jboss.man>
-    <version.jboss.microcontainer>2.0.0.GA</version.jboss.microcontainer>
-    <version.jboss.common.core>2.2.9.GA</version.jboss.common.core>
-    <version.jboss.logging.spi>2.0.5.GA</version.jboss.logging.spi>
-    <version.jboss.classloading.spi>5.0.3.GA</version.jboss.classloading.spi>
-    <version.jboss.vfs>2.0.0.GA</version.jboss.vfs>
-    <version.jbossxb>2.0.0.GA</version.jbossxb>
-    <version.org.jboss.test>1.1.1.GA</version.org.jboss.test>
-    <version.junit>4.4</version.junit>
-  </properties>
-
-  <build>
-    <outputDirectory>${microcontainer.outputDirectory}</outputDirectory>
-    <testOutputDirectory>${microcontainer.testOutputDirectory}</testOutputDirectory>
-    <finalName>${artifactId}</finalName>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-compiler-plugin</artifactId>
-        <version>2.0.2</version>
-        <configuration>
-          <source>1.5</source>
-          <target>1.5</target>
-          <showDeprecation>true</showDeprecation>
-          <showWarnings>true</showWarnings>
-          <optimize>true</optimize>
-        </configuration>
-      </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-release-plugin</artifactId>
-        <version>2.0-beta-7</version>
-        <configuration>
-          <generateReleasePoms>false</generateReleasePoms>
-          <tagBase>https://svn.jboss.org/repos/jbossas/projects/jboss-cl/tags</tagBase>
-          <autoVersionSubmodules>true</autoVersionSubmodules>
-        </configuration>
-      </plugin>
-    </plugins>
-    <pluginManagement>
-      <plugins>
-        <plugin>
-          <artifactId>maven-idea-plugin</artifactId>
-          <configuration>
-            <downloadSources>true</downloadSources>
-          </configuration>
-        </plugin>
-        <plugin>
-          <groupId>org.apache.maven.plugins</groupId>
-          <artifactId>maven-jar-plugin</artifactId>
-          <version>2.2</version>
-        </plugin>
-        <plugin>
-          <groupId>org.apache.maven.plugins</groupId>
-          <artifactId>maven-surefire-plugin</artifactId>
-          <version>2.4.1</version>
-          <configuration>
-            <redirectTestOutputToFile>true</redirectTestOutputToFile>
-            <includes>
-              <include>org/jboss/test/**/*TestCase.java</include>
-            </includes>
-          </configuration>
-        </plugin>
-        <plugin>
-          <!-- Configure javadoc plugin with APIviz -->
-          <groupId>org.apache.maven.plugins</groupId>
-          <artifactId>maven-javadoc-plugin</artifactId>
-          <configuration>
-            <doclet>net.gleamynode.apiviz.APIviz</doclet>
-            <docletArtifact>
-              <groupId>net.gleamynode.apiviz</groupId>
-              <artifactId>apiviz</artifactId>
-              <version>1.1.0</version>
-            </docletArtifact>
-            <encoding>UTF-8</encoding>
-          </configuration>
-        </plugin>        
-      </plugins>
-    </pluginManagement>
-  </build>
-  
-  <repositories>
-    <repository>
-      <id>repository.jboss.org</id>
-      <name>JBoss Repository</name>
-      <layout>default</layout>
-      <url>http://repository.jboss.org/maven2/</url>
-      <snapshots>
-        <enabled>false</enabled>
-      </snapshots>
-    </repository>
-    <repository>
-      <id>snapshots.jboss.org</id>
-      <name>JBoss Snapshots Repository</name>
-      <layout>default</layout>
-      <url>http://snapshots.jboss.org/maven2/</url>
-      <snapshots>
-        <enabled>true</enabled>
-      </snapshots>
-      <releases>
-        <enabled>false</enabled>
-      </releases>
-    </repository>
-    <!-- APIviz repository -->
-    <repository>
-      <id>apiviz.release</id>
-      <name>APIviz releases</name>
-      <url>http://apiviz.googlecode.com/svn/site/repo/mvn/release</url>
-      <releases>
-        <enabled>true</enabled>
-      </releases>
-      <snapshots>
-        <enabled>false</enabled>
-      </snapshots>
-    </repository>
-  </repositories>
-  
-  <reporting>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-project-info-reports-plugin</artifactId>
-        <reportSets>
-          <reportSet>
-            <reports>
-              <report>dependencies</report>
-              <report>issue-tracking</report>
-              <report>license</report>
-              <report>scm</report>
-            </reports>
-          </reportSet>
-        </reportSets>
-      </plugin>
-      <plugin>
-        <groupId>org.codehaus.mojo</groupId>
-        <artifactId>findbugs-maven-plugin</artifactId>
-        <version>1.0.0</version>
-      </plugin>
-    </plugins>
-  </reporting>
-  
-  <dependencyManagement>
-    <!-- The parent pom manages the inter-dependencies of the modules. -->
-    <dependencies>
-    
-      <dependency>
-        <groupId>org.jboss.cl</groupId>
-        <artifactId>jboss-classloader</artifactId>
-        <version>${project.version}</version>
-      </dependency>
-      
-      <dependency>
-        <groupId>org.jboss.cl</groupId>
-        <artifactId>jboss-classloading</artifactId>
-        <version>${project.version}</version>
-      </dependency>
-      
-      <dependency>
-        <groupId>org.jboss.cl</groupId>
-        <artifactId>jboss-classloading-vfs</artifactId>
-        <version>${project.version}</version>
-      </dependency>
-      
-      <dependency>
-        <groupId>org.jboss.man</groupId>
-        <artifactId>jboss-managed</artifactId>
-        <version>${version.jboss.man}</version>
-      </dependency>
-      
-      <dependency>
-        <groupId>org.jboss.microcontainer</groupId>
-        <artifactId>jboss-dependency</artifactId>
-        <version>${version.jboss.microcontainer}</version>
-      </dependency>
-      
-      <dependency>
-        <groupId>org.jboss.microcontainer</groupId>
-        <artifactId>jboss-kernel</artifactId>
-        <version>${version.jboss.microcontainer}</version>
-      </dependency>
-      
-      <dependency>
-        <groupId>org.jboss</groupId>
-        <artifactId>jboss-common-core</artifactId>
-        <version>${version.jboss.common.core}</version>
-      </dependency>
-      
-      <dependency>
-        <groupId>org.jboss.logging</groupId>
-        <artifactId>jboss-logging-spi</artifactId>
-        <version>${version.jboss.logging.spi}</version>
-      </dependency>
-
-      <dependency>
-        <groupId>org.jboss.integration</groupId>
-        <artifactId>jboss-classloading-spi</artifactId>
-        <version>${version.jboss.classloading.spi}</version>
-      </dependency>
-      
-      <dependency>
-        <groupId>org.jboss</groupId>
-        <artifactId>jbossxb</artifactId>
-        <version>${version.jbossxb}</version>
-      </dependency>
-      
-      <dependency>
-        <groupId>org.jboss</groupId>
-        <artifactId>jboss-vfs</artifactId>
-        <version>${version.jboss.vfs}</version>
-      </dependency>
-      
-      <!-- test dependencies -->
-      <dependency>
-        <groupId>org.jboss.test</groupId>
-        <artifactId>jboss-test</artifactId>
-        <version>${version.org.jboss.test}</version>
-        <scope>test</scope>
-      </dependency>
-      
-      <dependency>
-        <groupId>junit</groupId>
-        <artifactId>junit</artifactId>
-        <version>${version.junit}</version>
-        <scope>test</scope>
-      </dependency>
-      
-    </dependencies>
-  </dependencyManagement>
-
-  <profiles>
-    <profile>
-      <id>default</id>
-      <activation>
-        <activeByDefault>true</activeByDefault>
-      </activation>
-      <properties>
-        <microcontainer.outputDirectory>target/classes</microcontainer.outputDirectory>
-        <microcontainer.testOutputDirectory>target/tests-classes</microcontainer.testOutputDirectory>
-      </properties>
-    </profile>
-    <profile>
-      <id>eclipse</id>
-      <build>
-        <defaultGoal>process-test-resources</defaultGoal>
-        <plugins>
-          <plugin>
-            <artifactId>maven-eclipse-plugin</artifactId>
-            <executions>
-              <execution>
-                <id>eclipse</id>
-                <phase>process-test-resources</phase>
-                <goals>
-                  <goal>eclipse</goal>
-                </goals>
-              </execution>
-            </executions>
-            <configuration>
-              <downloadSources>true</downloadSources>
-              <buildOutputDirectory>${microcontainer.outputDirectory}</buildOutputDirectory>
-            </configuration>
-          </plugin>
-        </plugins>
-      </build>
-      <properties>
-        <microcontainer.outputDirectory>eclipse-target/classes</microcontainer.outputDirectory>
-        <microcontainer.testOutputDirectory>eclipse-target/tests-classes</microcontainer.testOutputDirectory>
-      </properties>
-    </profile>
-  </profiles>
-
-</project>
\ No newline at end of file

Copied: projects/jboss-cl/tags/2.0.2.GA/pom.xml (from rev 83484, projects/jboss-cl/branches/Branch_2_0/pom.xml)
===================================================================
--- projects/jboss-cl/tags/2.0.2.GA/pom.xml	                        (rev 0)
+++ projects/jboss-cl/tags/2.0.2.GA/pom.xml	2009-01-27 13:22:11 UTC (rev 83485)
@@ -0,0 +1,301 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.jboss</groupId>
+    <artifactId>jboss-parent</artifactId>
+    <version>4</version>
+  </parent>
+  <groupId>org.jboss.cl</groupId>
+  <artifactId>jboss-cl</artifactId>
+  <version>2.0.2.GA</version>
+  <packaging>pom</packaging>
+  <name>JBoss ClassLoader Parent POM</name>
+  <url>http://www.jboss.com/products/jbossmc</url>
+  <description>
+    JBoss ClassLoader
+  </description>
+  <scm>
+    <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/jboss-cl/tags/2.0.2.GA</connection>
+    <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/jboss-cl/tags/2.0.2.GA</developerConnection>
+    <url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/projects/jboss-cl/tags/2.0.2.GA</url>
+  </scm>
+
+  <modules>
+    <module>classloader</module>
+    <module>classloading</module>
+    <module>classloading-vfs</module>
+    <module>build</module>
+  </modules>
+  
+  <properties>
+    <version.jboss.vfs>2.0.1.GA</version.jboss.vfs>
+    <version.jboss.man>2.0.0.GA</version.jboss.man>
+    <version.jboss.microcontainer>2.0.3.GA</version.jboss.microcontainer>
+    <version.jboss.common.core>2.2.10.GA</version.jboss.common.core>
+    <version.jboss.logging.spi>2.0.5.GA</version.jboss.logging.spi>
+    <version.jboss.classloading.spi>5.0.3.GA</version.jboss.classloading.spi>
+    <version.jbossxb>2.0.0.GA</version.jbossxb>
+    <version.org.jboss.test>1.1.1.GA</version.org.jboss.test>
+    <version.junit>4.4</version.junit>
+  </properties>
+
+  <build>
+    <outputDirectory>${microcontainer.outputDirectory}</outputDirectory>
+    <testOutputDirectory>${microcontainer.testOutputDirectory}</testOutputDirectory>
+    <finalName>${artifactId}</finalName>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+          <showDeprecation>true</showDeprecation>
+          <showWarnings>true</showWarnings>
+          <optimize>true</optimize>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-release-plugin</artifactId>
+        <version>2.0-beta-7</version>
+        <configuration>
+          <generateReleasePoms>false</generateReleasePoms>
+          <tagBase>https://svn.jboss.org/repos/jbossas/projects/jboss-cl/tags</tagBase>
+          <autoVersionSubmodules>true</autoVersionSubmodules>
+        </configuration>
+      </plugin>
+    </plugins>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-idea-plugin</artifactId>
+          <configuration>
+            <downloadSources>true</downloadSources>
+          </configuration>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-jar-plugin</artifactId>
+          <version>2.2</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <version>2.4.1</version>
+          <configuration>
+            <redirectTestOutputToFile>true</redirectTestOutputToFile>
+            <includes>
+              <include>org/jboss/test/**/*TestCase.java</include>
+            </includes>
+          </configuration>
+        </plugin>
+        <plugin>
+          <!-- Configure javadoc plugin with APIviz -->
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-javadoc-plugin</artifactId>
+          <configuration>
+            <doclet>net.gleamynode.apiviz.APIviz</doclet>
+            <docletArtifact>
+              <groupId>net.gleamynode.apiviz</groupId>
+              <artifactId>apiviz</artifactId>
+              <version>1.1.0</version>
+            </docletArtifact>
+            <encoding>UTF-8</encoding>
+          </configuration>
+        </plugin>        
+      </plugins>
+    </pluginManagement>
+  </build>
+  
+  <repositories>
+    <repository>
+      <id>repository.jboss.org</id>
+      <name>JBoss Repository</name>
+      <layout>default</layout>
+      <url>http://repository.jboss.org/maven2/</url>
+      <snapshots>
+        <enabled>false</enabled>
+      </snapshots>
+    </repository>
+    <repository>
+      <id>snapshots.jboss.org</id>
+      <name>JBoss Snapshots Repository</name>
+      <layout>default</layout>
+      <url>http://snapshots.jboss.org/maven2/</url>
+      <snapshots>
+        <enabled>true</enabled>
+      </snapshots>
+      <releases>
+        <enabled>false</enabled>
+      </releases>
+    </repository>
+    <!-- APIviz repository -->
+    <repository>
+      <id>apiviz.release</id>
+      <name>APIviz releases</name>
+      <url>http://apiviz.googlecode.com/svn/site/repo/mvn/release</url>
+      <releases>
+        <enabled>true</enabled>
+      </releases>
+      <snapshots>
+        <enabled>false</enabled>
+      </snapshots>
+    </repository>
+  </repositories>
+  
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-project-info-reports-plugin</artifactId>
+        <reportSets>
+          <reportSet>
+            <reports>
+              <report>dependencies</report>
+              <report>issue-tracking</report>
+              <report>license</report>
+              <report>scm</report>
+            </reports>
+          </reportSet>
+        </reportSets>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>findbugs-maven-plugin</artifactId>
+        <version>1.0.0</version>
+      </plugin>
+    </plugins>
+  </reporting>
+  
+  <dependencyManagement>
+    <!-- The parent pom manages the inter-dependencies of the modules. -->
+    <dependencies>
+    
+      <dependency>
+        <groupId>org.jboss.cl</groupId>
+        <artifactId>jboss-classloader</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      
+      <dependency>
+        <groupId>org.jboss.cl</groupId>
+        <artifactId>jboss-classloading</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      
+      <dependency>
+        <groupId>org.jboss.cl</groupId>
+        <artifactId>jboss-classloading-vfs</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      
+      <dependency>
+        <groupId>org.jboss.man</groupId>
+        <artifactId>jboss-managed</artifactId>
+        <version>${version.jboss.man}</version>
+      </dependency>
+      
+      <dependency>
+        <groupId>org.jboss.microcontainer</groupId>
+        <artifactId>jboss-dependency</artifactId>
+        <version>${version.jboss.microcontainer}</version>
+      </dependency>
+      
+      <dependency>
+        <groupId>org.jboss.microcontainer</groupId>
+        <artifactId>jboss-kernel</artifactId>
+        <version>${version.jboss.microcontainer}</version>
+      </dependency>
+      
+      <dependency>
+        <groupId>org.jboss</groupId>
+        <artifactId>jboss-common-core</artifactId>
+        <version>${version.jboss.common.core}</version>
+      </dependency>
+      
+      <dependency>
+        <groupId>org.jboss.logging</groupId>
+        <artifactId>jboss-logging-spi</artifactId>
+        <version>${version.jboss.logging.spi}</version>
+      </dependency>
+
+      <dependency>
+        <groupId>org.jboss.integration</groupId>
+        <artifactId>jboss-classloading-spi</artifactId>
+        <version>${version.jboss.classloading.spi}</version>
+      </dependency>
+      
+      <dependency>
+        <groupId>org.jboss</groupId>
+        <artifactId>jbossxb</artifactId>
+        <version>${version.jbossxb}</version>
+      </dependency>
+      
+      <dependency>
+        <groupId>org.jboss</groupId>
+        <artifactId>jboss-vfs</artifactId>
+        <version>${version.jboss.vfs}</version>
+      </dependency>
+      
+      <!-- test dependencies -->
+      <dependency>
+        <groupId>org.jboss.test</groupId>
+        <artifactId>jboss-test</artifactId>
+        <version>${version.org.jboss.test}</version>
+        <scope>test</scope>
+      </dependency>
+      
+      <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+        <version>${version.junit}</version>
+        <scope>test</scope>
+      </dependency>
+      
+    </dependencies>
+  </dependencyManagement>
+
+  <profiles>
+    <profile>
+      <id>default</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <properties>
+        <microcontainer.outputDirectory>target/classes</microcontainer.outputDirectory>
+        <microcontainer.testOutputDirectory>target/tests-classes</microcontainer.testOutputDirectory>
+      </properties>
+    </profile>
+    <profile>
+      <id>eclipse</id>
+      <build>
+        <defaultGoal>process-test-resources</defaultGoal>
+        <plugins>
+          <plugin>
+            <artifactId>maven-eclipse-plugin</artifactId>
+            <executions>
+              <execution>
+                <id>eclipse</id>
+                <phase>process-test-resources</phase>
+                <goals>
+                  <goal>eclipse</goal>
+                </goals>
+              </execution>
+            </executions>
+            <configuration>
+              <downloadSources>true</downloadSources>
+              <buildOutputDirectory>${microcontainer.outputDirectory}</buildOutputDirectory>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+      <properties>
+        <microcontainer.outputDirectory>eclipse-target/classes</microcontainer.outputDirectory>
+        <microcontainer.testOutputDirectory>eclipse-target/tests-classes</microcontainer.testOutputDirectory>
+      </properties>
+    </profile>
+  </profiles>
+
+</project>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list