[jboss-cvs] JBossAS SVN: r103082 - in projects/jboss-cl/trunk: classloading/src/main/java/org/jboss/classloading/spi/visitor and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Mar 28 07:24:59 EDT 2010


Author: alesj
Date: 2010-03-28 07:24:59 -0400 (Sun, 28 Mar 2010)
New Revision: 103082

Added:
   projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/visitor/RootAwareResource.java
Modified:
   projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/plugins/vfs/VFSResourceContext.java
   projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java
   projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/visitor/AbstractResourceContext.java
Log:
[JBCL-158]; expose current root -- better way; no need for thread local hack.

Modified: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/visitor/AbstractResourceContext.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/visitor/AbstractResourceContext.java	2010-03-28 10:01:50 UTC (rev 103081)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/plugins/visitor/AbstractResourceContext.java	2010-03-28 11:24:59 UTC (rev 103082)
@@ -27,6 +27,7 @@
 
 import org.jboss.classloader.plugins.ClassLoaderUtils;
 import org.jboss.classloading.spi.visitor.ResourceContext;
+import org.jboss.classloading.spi.visitor.RootAwareResource;
 
 /**
  * Abstract resource context.
@@ -35,7 +36,7 @@
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public abstract class AbstractResourceContext implements ResourceContext
+public abstract class AbstractResourceContext implements ResourceContext, RootAwareResource
 {
    /** The classloader */
    private ClassLoader classLoader;
@@ -61,6 +62,16 @@
    }
 
    /**
+    * Get root url.
+    *
+    * @return the root url
+    */
+   public URL getRootUrl()
+   {
+      throw new RuntimeException("Not implemented, override in non-abstract class / implementation.");
+   }
+
+   /**
     * Get the classLoader.
     *
     * @return the classLoader.

Copied: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/visitor/RootAwareResource.java (from rev 102530, projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/visitor/ResourceContext.java)
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/visitor/RootAwareResource.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/visitor/RootAwareResource.java	2010-03-28 11:24:59 UTC (rev 103082)
@@ -0,0 +1,40 @@
+/*
+* 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.visitor;
+
+import java.net.URL;
+
+/**
+ * Root aware resource.
+ * TODO -- move to resource context spi, once we update major version
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface RootAwareResource
+{
+   /**
+    * Get the root url.
+    *
+    * @return the url.
+    */
+   URL getRootUrl();
+}
\ No newline at end of file

Modified: projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/plugins/vfs/VFSResourceContext.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/plugins/vfs/VFSResourceContext.java	2010-03-28 10:01:50 UTC (rev 103081)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/plugins/vfs/VFSResourceContext.java	2010-03-28 11:24:59 UTC (rev 103082)
@@ -21,9 +21,9 @@
 */
 package org.jboss.classloading.plugins.vfs;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
-import java.io.InputStream;
-import java.io.IOException;
 
 import org.jboss.classloading.plugins.visitor.AbstractResourceContext;
 import org.jboss.vfs.VirtualFile;
@@ -36,6 +36,7 @@
 public class VFSResourceContext extends AbstractResourceContext
 {
    private VirtualFile file;
+   private VirtualFile root;
 
    public VFSResourceContext(VirtualFile file, String resourceName, ClassLoader classLoader)
    {
@@ -62,4 +63,29 @@
    {
       return file.openStream();
    }
+
+   @Override
+   public URL getRootUrl()
+   {
+      try
+      {
+         return root.toURL();
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   /**
+    * Set the root.
+    *
+    * @param root the root
+    */
+   void setRoot(VirtualFile root)
+   {
+      if (root == null)
+         throw new IllegalArgumentException("Null root");
+      this.root = root;
+   }
 }

Modified: projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java
===================================================================
--- projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java	2010-03-28 10:01:50 UTC (rev 103081)
+++ projects/jboss-cl/trunk/classloading-vfs/src/main/java/org/jboss/classloading/plugins/vfs/VFSResourceVisitor.java	2010-03-28 11:24:59 UTC (rev 103082)
@@ -76,9 +76,6 @@
    /** The resource filter */
    private ResourceFilter recurseFilter;
 
-   /** The current root */
-   private static ThreadLocal<VirtualFile> currentRoot = new ThreadLocal<VirtualFile>();
-
    /**
     * Visit the resources
     * 
@@ -101,16 +98,8 @@
          {
             if (urls == null || urls.length == 0 || matchRootWithUrls(root, urls))
             {
-               currentRoot.set(root);
-               try
-               {
-                  vfsVisitor.setRoot(root);
-                  root.visit(vfsVisitor);
-               }
-               finally
-               {
-                  currentRoot.remove();   
-               }
+               vfsVisitor.setRoot(root);
+               root.visit(vfsVisitor);
             }
          }
          catch (Exception e)
@@ -121,16 +110,6 @@
    }
 
    /**
-    * Get the current root.
-    *
-    * @return the current root
-    */
-   public static VirtualFile getCurrentRoot()
-   {
-      return currentRoot.get();
-   }
-
-   /**
     * Match root with urls.
     *
     * @param root one of the roots
@@ -277,7 +256,8 @@
          if (excluded != null && excluded.matchesResourcePath(path))
             return;
          
-         ResourceContext resource = new VFSResourceContext(file, path, classLoader);
+         VFSResourceContext resource = new VFSResourceContext(file, path, classLoader);
+         resource.setRoot(root);
          
          //Check the filter and visit
          if (filter == null || filter.accepts(resource))




More information about the jboss-cvs-commits mailing list