[jboss-cvs] JBossAS SVN: r91139 - in projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual: impl/vfs and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 13 02:22:56 EDT 2009


Author: ALRubinger
Date: 2009-07-13 02:22:56 -0400 (Mon, 13 Jul 2009)
New Revision: 91139

Modified:
   projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/AbstractVirtualArchive.java
   projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/vfs/VirtualVfsArchiveImpl.java
   projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/ExtensibleVirtualArchive.java
Log:
[EMB-34] Add classes into the virtual archive using the loading CL

Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/AbstractVirtualArchive.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/AbstractVirtualArchive.java	2009-07-13 05:50:53 UTC (rev 91138)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/base/AbstractVirtualArchive.java	2009-07-13 06:22:56 UTC (rev 91139)
@@ -71,56 +71,6 @@
    private static final String EXTENSION_CLASS = ".class";
 
    //-------------------------------------------------------------------------------------||
-   // Instance Members -------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * The ClassLoader used in loading resources and classes into the virtual deployment
-    */
-   private final ClassLoader classLoader;
-
-   //-------------------------------------------------------------------------------------||
-   // Constructor ------------------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Constructor
-    * 
-    * Creates a new {@link AbstractVirtualArchive} using the Thread Context  
-    * ClassLoader.
-    * 
-    * @param name Unique name for the deployment
-    * @throws IllegalArgumentException If the name was not specified
-    */
-   public AbstractVirtualArchive(final String name) throws IllegalArgumentException
-   {
-      this(name, SecurityActions.getThreadContextClassLoader());
-   }
-
-   /**
-    * Constructor
-    * 
-    * @param name Unique name for the deployment
-    * @param cl ClassLoader to be used in loading resources and classes
-    * @throws IllegalArgumentException If the name, actual class or ClassLoader was not specified
-    */
-   public AbstractVirtualArchive(final String name, final ClassLoader cl) throws IllegalArgumentException
-   {
-      // Precondition check
-      if (name == null || name.length() == 0)
-      {
-         throw new IllegalArgumentException("name must be specified");
-      }
-      if (cl == null)
-      {
-         throw new IllegalArgumentException("ClassLoader must be specified");
-      }
-
-      // Set the CL
-      this.classLoader = cl;
-   }
-
-   //-------------------------------------------------------------------------------------||
    // Required Implementations -----------------------------------------------------------||
    //-------------------------------------------------------------------------------------||
 
@@ -140,12 +90,15 @@
       // Get the resource name of the class
       final String name = this.getResourceNameOfClass(clazz);
 
+      // Get the CL of the Class
+      final ClassLoader cl = clazz.getClassLoader();
+
       // Add it as a resource
       if (log.isTraceEnabled())
       {
          log.trace("Adding class as resource: " + clazz);
       }
-      return this.addResource(name);
+      return this.addResource(name, cl);
    }
 
    /*
@@ -257,18 +210,4 @@
       }
    }
 
-   //-------------------------------------------------------------------------------------||
-   // Accessors / Mutators ---------------------------------------------------------------||
-   //-------------------------------------------------------------------------------------||
-
-   /**
-    * Returns the ClassLoader used to load classes
-    * and resources into this virtual deployment
-    * 
-    * @return
-    */
-   protected final ClassLoader getClassLoader()
-   {
-      return this.classLoader;
-   }
 }

Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/vfs/VirtualVfsArchiveImpl.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/vfs/VirtualVfsArchiveImpl.java	2009-07-13 05:50:53 UTC (rev 91138)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/impl/vfs/VirtualVfsArchiveImpl.java	2009-07-13 06:22:56 UTC (rev 91139)
@@ -80,6 +80,11 @@
     */
    private final URL rootUrl;
 
+   /**
+    * The ClassLoader used in loading resources and classes into the virtual deployment
+    */
+   private final ClassLoader classLoader;
+
    //-------------------------------------------------------------------------------------||
    // Constructors -----------------------------------------------------------------------||
    //-------------------------------------------------------------------------------------||
@@ -107,8 +112,15 @@
     */
    public VirtualVfsArchiveImpl(final String name, final ClassLoader cl) throws IllegalArgumentException
    {
-      // Invoke super
-      super(name, cl);
+      // Precondition Check
+      if (name == null || name.length() == 0)
+      {
+         throw new IllegalArgumentException("name must be specified");
+      }
+      if (cl == null)
+      {
+         throw new IllegalArgumentException("ClassLoader must be specified");
+      }
 
       // Create the root for the deployment
       VirtualFile file = null;
@@ -128,6 +140,9 @@
       // Set properties for the root
       this.root = file;
       this.rootUrl = url;
+
+      // Set the CL
+      this.classLoader = cl;
    }
 
    //-------------------------------------------------------------------------------------||
@@ -160,17 +175,31 @@
    @Override
    public VirtualVfsArchive addResource(final String name) throws IllegalArgumentException
    {
+      return this.addResource(name, this.getClassLoader());
+   }
+
+   /*
+    * (non-Javadoc)
+    * @see org.jboss.embedded.core.virtual.spi.ExtensibleVirtualArchive#addResource(java.lang.String, java.lang.ClassLoader)
+    */
+   @Override
+   public final VirtualVfsArchive addResource(final String name, final ClassLoader cl) throws IllegalArgumentException
+   {
       // Precondition check
       if (name == null || name.length() == 0)
       {
          throw new IllegalArgumentException("name must be specified");
       }
+      if (cl == null)
+      {
+         throw new IllegalArgumentException("ClassLoader must be specified");
+      }
 
       // Get the content of the resource
       byte[] content = null;
       try
       {
-         content = this.getBytesOfResource(name);
+         content = this.getBytesOfResource(name, cl);
       }
       catch (final IOException ioe)
       {
@@ -221,23 +250,29 @@
    //-------------------------------------------------------------------------------------||
 
    /**
-    * Obtains the contents (bytes) of the specified resource
+    * Obtains the contents (bytes) of the specified resource using the 
+    * specified ClassLoader
     * 
     * @param name
     * @return
     * @throws IOException
-    * @throws IllegalArgumentException If the name is not specified
+    * @throws IllegalArgumentException If the name or ClassLoader is not specified
     */
-   private byte[] getBytesOfResource(final String name) throws IOException, IllegalArgumentException
+   private byte[] getBytesOfResource(final String name, final ClassLoader cl) throws IOException,
+         IllegalArgumentException
    {
       // Precondition check
       if (name == null || name.length() == 0)
       {
          throw new IllegalArgumentException("name must be specified");
       }
+      if (cl == null)
+      {
+         throw new IllegalArgumentException("ClassLoader must be specified");
+      }
 
       // Get the URL
-      final URL resourceUrl = this.getResourceUrl(name);
+      final URL resourceUrl = this.getResourceUrl(name, cl);
 
       // Open a connection and read in all the bytes
       final URLConnection connection = resourceUrl.openConnection();
@@ -379,18 +414,22 @@
     * 
     * @param name
     * @return
-    * @throws IllegalArgumentException If name is not specified or could not 
+    * @throws IllegalArgumentException If name is not specified or could not be found, 
+    *   or if the ClassLoader is not specified 
     */
-   private URL getResourceUrl(final String name) throws IllegalArgumentException
+   private URL getResourceUrl(final String name, final ClassLoader cl) throws IllegalArgumentException
    {
       // Precondition check
       if (name == null || name.length() == 0)
       {
          throw new IllegalArgumentException("name must be specified");
       }
+      if (cl == null)
+      {
+         throw new IllegalArgumentException("ClassLoader must be specified");
+      }
 
       // Find
-      final ClassLoader cl = this.getClassLoader();
       final URL url = cl.getResource(name);
 
       // Ensure found
@@ -417,4 +456,15 @@
    {
       return this.copyURL(this.rootUrl);
    }
+
+   /**
+    * Returns the ClassLoader used to load classes
+    * and resources into this virtual deployment
+    * 
+    * @return
+    */
+   protected final ClassLoader getClassLoader()
+   {
+      return this.classLoader;
+   }
 }

Modified: projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/ExtensibleVirtualArchive.java
===================================================================
--- projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/ExtensibleVirtualArchive.java	2009-07-13 05:50:53 UTC (rev 91138)
+++ projects/embedded/trunk/core/src/main/java/org/jboss/embedded/core/virtual/spi/ExtensibleVirtualArchive.java	2009-07-13 06:22:56 UTC (rev 91139)
@@ -42,7 +42,7 @@
    //-------------------------------------------------------------------------------------||
 
    /**
-    * Adds the specified Class to the deployment
+    * Adds the specified Class to the archive
     * 
     * @param The class to add
     * @return This virtual deployment
@@ -51,7 +51,7 @@
    T addClass(Class<?> clazz) throws IllegalArgumentException;
 
    /**
-    * Adds the specified Classes to the deployment.  
+    * Adds the specified Classes to the archive.  
     * 
     * @param classes
     * @return This virtual deployment
@@ -62,7 +62,7 @@
    /**
     * Adds the resource with the specified name to the 
     * deployment.  The resource name must be visible to the ClassLoader
-    * of the deployment
+    * of the archive
     * 
     * @param name
     * @return
@@ -71,6 +71,17 @@
    T addResource(String name) throws IllegalArgumentException;
 
    /**
+    * Adds the specified resource to the archive, using the specified ClassLoader
+    * to load the resource
+    * 
+    * @param name
+    * @param cl
+    * @return
+    * @throws IllegalArgumentException If either the name or ClassLoader is not specified
+    */
+   T addResource(String name, ClassLoader cl) throws IllegalArgumentException;
+
+   /**
     * Returns a multiline "ls -l"-equse output of the contents of
     * this deployment and (recursively) its children if the verbosity 
     * flag is set to "true".  Otherwise the no-arg version is invoked




More information about the jboss-cvs-commits mailing list