[jboss-cvs] JBossAS SVN: r62807 - in projects/microcontainer/trunk/deployers: src/main/org/jboss/deployers/spi/classloader and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 4 07:44:55 EDT 2007


Author: adrian at jboss.org
Date: 2007-05-04 07:44:54 -0400 (Fri, 04 May 2007)
New Revision: 62807

Added:
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/vfs/
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/vfs/ExportAll.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/vfs/PackageVisitor.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/vfs/VFSClassLoaderPolicy.java
Modified:
   projects/microcontainer/trunk/deployers/.classpath
   projects/microcontainer/trunk/deployers/pom.xml
Log:
[JBOSGI-14] - VFSClassLoaderPolicy

Modified: projects/microcontainer/trunk/deployers/.classpath
===================================================================
--- projects/microcontainer/trunk/deployers/.classpath	2007-05-04 11:35:49 UTC (rev 62806)
+++ projects/microcontainer/trunk/deployers/.classpath	2007-05-04 11:44:54 UTC (rev 62807)
@@ -1,43 +1,44 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
-	<classpathentry kind="src" path="src/main"/>
-	<classpathentry excluding="**/*.java" kind="src" path="src/resources/tests"/>
-	<classpathentry kind="src" path="src/tests"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
-	<classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-spi/2.0.2.GA/jboss-logging-spi-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-spi/2.0.2.GA/jboss-logging-spi-2.0.2.GA-sources.jar"/>
-	<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-junit/1.7.0/ant-junit-1.7.0.jar"/>
-	<classpathentry kind="var" path="M2_REPO/oswego-concurrent/concurrent/1.3.4/concurrent-1.3.4.jar"/>
-	<classpathentry kind="var" path="M2_REPO/javax/xml/bind/jaxb-api/2.0/jaxb-api-2.0.jar"/>
-	<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar" sourcepath="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14-sources.jar"/>
-	<classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-log4j/2.0.2.GA/jboss-logging-log4j-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-log4j/2.0.2.GA/jboss-logging-log4j-2.0.2.GA-sources.jar"/>
-	<classpathentry kind="var" path="M2_REPO/jboss/jboss-vfs/2.0.4.snapshot/jboss-vfs-2.0.4.snapshot.jar" sourcepath="M2_REPO/jboss/jboss-vfs/2.0.4.snapshot/jboss-vfs-2.0.4.snapshot-sources.jar"/>
-	<classpathentry kind="src" path="/jboss-managed"/>
-	<classpathentry kind="var" path="M2_REPO/apache-httpclient/commons-httpclient/2.0.2/commons-httpclient-2.0.2.jar"/>
-	<classpathentry kind="var" path="M2_REPO/jboss/jboss-aop/2.0.0-SNAPSHOT/jboss-aop-2.0.0-SNAPSHOT.jar" sourcepath="M2_REPO/jboss/jboss-aop/2.0.0-SNAPSHOT/jboss-aop-2.0.0-SNAPSHOT-sources.jar"/>
-	<classpathentry kind="var" path="M2_REPO/javax/xml/bind/jsr173_api/1.0/jsr173_api-1.0.jar"/>
-	<classpathentry kind="src" path="/jboss-aop-mc-int"/>
-	<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant/1.7.0/ant-1.7.0.jar"/>
-	<classpathentry kind="var" path="M2_REPO/jboss/profiler/jvmti/jboss-profiler-jvmti/1.0.0.CR5/jboss-profiler-jvmti-1.0.0.CR5.jar"/>
-	<classpathentry kind="var" path="M2_REPO/apache-xerces/xml-apis/2.7.1/xml-apis-2.7.1.jar"/>
-	<classpathentry kind="var" path="M2_REPO/jboss/jboss-common-core/2.0.4.GA/jboss-common-core-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-core/2.0.4.GA/jboss-common-core-2.0.4.GA-sources.jar"/>
-	<classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.1/activation-1.1.jar" sourcepath="M2_REPO/javax/activation/activation/1.1/activation-1.1-sources.jar"/>
-	<classpathentry kind="var" path="M2_REPO/apache-slide/webdavlib/2.0/webdavlib-2.0.jar"/>
-	<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
-	<classpathentry kind="var" path="M2_REPO/qdox/qdox/1.6/qdox-1.6.jar" sourcepath="M2_REPO/qdox/qdox/1.6/qdox-1.6-sources.jar"/>
-	<classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA-sources.jar"/>
-	<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-launcher/1.7.0/ant-launcher-1.7.0.jar"/>
-	<classpathentry kind="var" path="M2_REPO/ant/ant/1.6.5/ant-1.6.5.jar" sourcepath="M2_REPO/ant/ant/1.6.5/ant-1.6.5-sources.jar"/>
-	<classpathentry kind="var" path="M2_REPO/sun-jaf/activation/1.0.2/activation-1.0.2.jar"/>
-	<classpathentry kind="var" path="M2_REPO/jboss/jboss-test/1.0.3.GA/jboss-test-1.0.3.GA.jar" sourcepath="M2_REPO/jboss/jboss-test/1.0.3.GA/jboss-test-1.0.3.GA-sources.jar"/>
-	<classpathentry kind="var" path="M2_REPO/apache-log4j/log4j/1.2.8/log4j-1.2.8.jar"/>
-	<classpathentry kind="var" path="M2_REPO/jboss/jbossxb/2.0.0.CR3/jbossxb-2.0.0.CR3.jar" sourcepath="M2_REPO/jboss/jbossxb/2.0.0.CR3/jbossxb-2.0.0.CR3-sources.jar"/>
-	<classpathentry kind="var" path="M2_REPO/trove/trove/2.1.1/trove-2.1.1.jar"/>
-	<classpathentry kind="src" path="/jboss-container"/>
-	<classpathentry kind="src" path="/jboss-metatype"/>
-	<classpathentry kind="src" path="/jboss-dependency"/>
-	<classpathentry kind="var" path="M2_REPO/wutka-dtdparser/dtdparser121/1.2.1/dtdparser121-1.2.1.jar"/>
-	<classpathentry kind="var" path="M2_REPO/apache-xerces/xercesImpl/2.7.1/xercesImpl-2.7.1.jar"/>
-	<classpathentry kind="src" path="/jboss-kernel"/>
-	<classpathentry kind="var" path="M2_REPO/javassist/javassist/3.5-SNAPSHOT/javassist-3.5-SNAPSHOT.jar" sourcepath="M2_REPO/javassist/javassist/3.5-SNAPSHOT/javassist-3.5-SNAPSHOT-sources.jar"/>
-	<classpathentry kind="output" path="target/eclipse-classes"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/main"/>
+	<classpathentry excluding="**/*.java" kind="src" path="src/resources/tests"/>
+	<classpathentry kind="src" path="src/tests"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-spi/2.0.2.GA/jboss-logging-spi-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-spi/2.0.2.GA/jboss-logging-spi-2.0.2.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-junit/1.7.0/ant-junit-1.7.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/oswego-concurrent/concurrent/1.3.4/concurrent-1.3.4.jar"/>
+	<classpathentry kind="var" path="M2_REPO/javax/xml/bind/jaxb-api/2.0/jaxb-api-2.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar" sourcepath="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/jboss-logging-log4j/2.0.2.GA/jboss-logging-log4j-2.0.2.GA.jar" sourcepath="M2_REPO/jboss/jboss-logging-log4j/2.0.2.GA/jboss-logging-log4j-2.0.2.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/jboss-vfs/2.0.4.snapshot/jboss-vfs-2.0.4.snapshot.jar" sourcepath="M2_REPO/jboss/jboss-vfs/2.0.4.snapshot/jboss-vfs-2.0.4.snapshot-sources.jar"/>
+	<classpathentry kind="src" path="/jboss-managed"/>
+	<classpathentry kind="var" path="M2_REPO/apache-httpclient/commons-httpclient/2.0.2/commons-httpclient-2.0.2.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/jboss-aop/2.0.0-SNAPSHOT/jboss-aop-2.0.0-SNAPSHOT.jar" sourcepath="M2_REPO/jboss/jboss-aop/2.0.0-SNAPSHOT/jboss-aop-2.0.0-SNAPSHOT-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/javax/xml/bind/jsr173_api/1.0/jsr173_api-1.0.jar"/>
+	<classpathentry kind="src" path="/jboss-aop-mc-int"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant/1.7.0/ant-1.7.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/profiler/jvmti/jboss-profiler-jvmti/1.0.0.CR5/jboss-profiler-jvmti-1.0.0.CR5.jar"/>
+	<classpathentry kind="var" path="M2_REPO/apache-xerces/xml-apis/2.7.1/xml-apis-2.7.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/jboss-common-core/2.0.4.GA/jboss-common-core-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-core/2.0.4.GA/jboss-common-core-2.0.4.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.1/activation-1.1.jar" sourcepath="M2_REPO/javax/activation/activation/1.1/activation-1.1-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/apache-slide/webdavlib/2.0/webdavlib-2.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/qdox/qdox/1.6/qdox-1.6.jar" sourcepath="M2_REPO/qdox/qdox/1.6/qdox-1.6-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA.jar" sourcepath="M2_REPO/jboss/jboss-common-logging-spi/2.0.4.GA/jboss-common-logging-spi-2.0.4.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/org/apache/ant/ant-launcher/1.7.0/ant-launcher-1.7.0.jar"/>
+	<classpathentry kind="var" path="M2_REPO/ant/ant/1.6.5/ant-1.6.5.jar" sourcepath="M2_REPO/ant/ant/1.6.5/ant-1.6.5-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/sun-jaf/activation/1.0.2/activation-1.0.2.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/jboss-test/1.0.3.GA/jboss-test-1.0.3.GA.jar" sourcepath="M2_REPO/jboss/jboss-test/1.0.3.GA/jboss-test-1.0.3.GA-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/apache-log4j/log4j/1.2.8/log4j-1.2.8.jar"/>
+	<classpathentry kind="var" path="M2_REPO/jboss/jbossxb/2.0.0.CR3/jbossxb-2.0.0.CR3.jar" sourcepath="M2_REPO/jboss/jbossxb/2.0.0.CR3/jbossxb-2.0.0.CR3-sources.jar"/>
+	<classpathentry kind="var" path="M2_REPO/trove/trove/2.1.1/trove-2.1.1.jar"/>
+	<classpathentry kind="src" path="/jboss-container"/>
+	<classpathentry kind="src" path="/jboss-metatype"/>
+	<classpathentry kind="src" path="/jboss-dependency"/>
+	<classpathentry kind="var" path="M2_REPO/wutka-dtdparser/dtdparser121/1.2.1/dtdparser121-1.2.1.jar"/>
+	<classpathentry kind="var" path="M2_REPO/apache-xerces/xercesImpl/2.7.1/xercesImpl-2.7.1.jar"/>
+	<classpathentry kind="src" path="/jboss-kernel"/>
+	<classpathentry kind="var" path="M2_REPO/javassist/javassist/3.5-SNAPSHOT/javassist-3.5-SNAPSHOT.jar" sourcepath="M2_REPO/javassist/javassist/3.5-SNAPSHOT/javassist-3.5-SNAPSHOT-sources.jar"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/jboss-classloader"/>
+	<classpathentry kind="output" path="target/eclipse-classes"/>
+</classpath>

Modified: projects/microcontainer/trunk/deployers/pom.xml
===================================================================
--- projects/microcontainer/trunk/deployers/pom.xml	2007-05-04 11:35:49 UTC (rev 62806)
+++ projects/microcontainer/trunk/deployers/pom.xml	2007-05-04 11:44:54 UTC (rev 62807)
@@ -71,5 +71,10 @@
       <version>3.8.1</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>jboss</groupId>
+      <artifactId>jboss-classloader</artifactId>
+      <version>2.0.0-SNAPSHOT</version>
+    </dependency>
   </dependencies>
 </project>

Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/vfs/ExportAll.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/vfs/ExportAll.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/vfs/ExportAll.java	2007-05-04 11:44:54 UTC (rev 62807)
@@ -0,0 +1,37 @@
+/*
+ * 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.deployers.spi.classloader.vfs;
+
+/**
+ * ExportAll.
+ * 
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public enum ExportAll
+{
+   /** All packages */
+   ALL,
+   
+   /** All non empty packages */
+   NON_EMPTY
+}

Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/vfs/PackageVisitor.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/vfs/PackageVisitor.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/vfs/PackageVisitor.java	2007-05-04 11:44:54 UTC (rev 62807)
@@ -0,0 +1,120 @@
+/*
+ * 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.deployers.spi.classloader.vfs;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileVisitor;
+import org.jboss.virtual.VisitorAttributes;
+
+/**
+ * Visits a virtual file system recursively
+ * to determine package names based on the exportAll policy
+ * 
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class PackageVisitor implements VirtualFileVisitor
+{
+   /** The packages */
+   private Set<String> packages = new HashSet<String>();
+   
+   /** The exportAll policy */
+   private ExportAll exportAll;
+
+   /**
+    * Create a new PackageVisitor.
+    * 
+    * @param exportAll the export all policy
+    * @throws IllegalArgumentException for a null exportAll policy
+    */
+   public PackageVisitor(ExportAll exportAll)
+   {
+      if (exportAll == null)
+         throw new IllegalArgumentException("Null exportAll policy");
+      this.exportAll = exportAll;
+   }
+
+   /**
+    * Get the packages.
+    * 
+    * @return the packages.
+    */
+   public Set<String> getPackages()
+   {
+      return packages;
+   }
+
+   public VisitorAttributes getAttributes()
+   {
+      VisitorAttributes attributes = new VisitorAttributes();
+      attributes.setIncludeRoot(true);
+      attributes.setRecurseFilter(VisitorAttributes.RECURSE_ALL);
+      return attributes;
+   }
+   
+   public void visit(VirtualFile file)
+   {
+      try
+      {
+         // We only want only directories
+         if (file.isLeaf() == false)
+         {
+            boolean empty = true;
+            // Include empty directories?
+            if (exportAll == ExportAll.ALL)
+               empty = false;
+            else
+            {
+               // Determine whether there is anything there
+               List<VirtualFile> children = file.getChildren();
+               if (children != null && children.isEmpty() == false)
+               {
+                  for (VirtualFile child : children)
+                  {
+                     // We must have a leaf to be non-empty
+                     if (child.isLeaf())
+                     {
+                        empty = false;
+                        break;
+                     }
+                  }
+               }
+            }
+            // This looks interesting
+            if (empty == false)
+            {
+               String path = file.getPathName();
+               packages.add(path.replace('/', '.'));
+            }
+         }
+      }
+      catch (IOException e)
+      {
+         throw new Error("Error visiting " + file, e);
+      }
+   }
+}
\ No newline at end of file

Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/vfs/VFSClassLoaderPolicy.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/vfs/VFSClassLoaderPolicy.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/vfs/VFSClassLoaderPolicy.java	2007-05-04 11:44:54 UTC (rev 62807)
@@ -0,0 +1,275 @@
+/*
+ * 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.deployers.spi.classloader.vfs;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.security.CodeSource;
+import java.security.PermissionCollection;
+import java.security.Policy;
+import java.security.ProtectionDomain;
+import java.security.cert.Certificate;
+import java.util.Arrays;
+import java.util.Set;
+import java.util.jar.Manifest;
+
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.PackageInformation;
+import org.jboss.logging.Logger;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * VFSClassLoaderPolicy.
+ * 
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class VFSClassLoaderPolicy extends ClassLoaderPolicy
+{
+   /** The log */
+   private static Logger log = Logger.getLogger(VFSClassLoaderPolicy.class);
+   
+   /** The roots */
+   private VirtualFile[] roots;
+
+   /** Whether to export all */
+   private ExportAll exportAll;
+   
+   /** The exported packages */
+   private String[] exportedPackages;
+   
+   /**
+    * Create a new VFSClassLoaderPolicy.
+    * 
+    * @param roots the roots
+    * @return the classloader policy
+    * @throws IllegalArgumentException for null roots
+    */
+   public static VFSClassLoaderPolicy createVFSClassLoaderPolicy(VirtualFile... roots)
+   {
+      return new VFSClassLoaderPolicy(roots);
+   }
+
+   /**
+    * Create a new VFSClassLoaderPolicy.
+    * 
+    * @param roots the roots
+    * @throws IllegalArgumentException for null roots
+    */
+   public VFSClassLoaderPolicy(VirtualFile[] roots)
+   {
+      if (roots == null)
+         throw new IllegalArgumentException("Null roots");
+      for (VirtualFile root : roots)
+      {
+         if (root == null)
+            throw new IllegalArgumentException("Null root in " + Arrays.asList(roots));
+      }
+
+      this.roots = roots;
+   }
+
+   /**
+    * Get the exportAll.
+    * 
+    * @return the exportAll.
+    */
+   public ExportAll isExportAll()
+   {
+      return exportAll;
+   }
+
+   /**
+    * Set the exportAll.
+    * 
+    * @param exportAll the exportAll.
+    */
+   public void setExportAll(ExportAll exportAll)
+   {
+      this.exportAll = exportAll;
+      if (exportAll != null)
+         exportedPackages = determineAllPackages().toArray(new String[0]);
+      else
+         exportedPackages = null;
+   }
+
+   @Override
+   public String[] getPackageNames()
+   {
+      return exportedPackages;
+   }
+
+   /**
+    * Set the exportedPackages.
+    * 
+    * @param exportedPackages the exportedPackages.
+    */
+   public void setExportedPackages(String[] exportedPackages)
+   {
+      this.exportedPackages = exportedPackages;
+   }
+
+   @Override
+   public URL getResource(String path)
+   {
+      VirtualFile child = findChild(path);
+      if (child != null)
+      {
+         try
+         {
+            return child.toURL();
+         }
+         catch (Exception ignored)
+         {
+            log.trace("Error determining URL for " + child, ignored);
+            return null;
+         }
+      }
+      return null;
+   }
+
+   @Override
+   public InputStream getResourceAsStream(String path)
+   {
+      VirtualFile child = findChild(path);
+      if (child != null)
+      {
+         try
+         {
+            return child.openStream();
+         }
+         catch (Exception ignored)
+         {
+            log.trace("Error opening stream for " + child, ignored);
+            return null;
+         }
+      }
+      return null;
+   }
+
+   @Override
+   public void getResources(String name, Set<URL> urls) throws IOException
+   {
+      for (VirtualFile root : roots)
+      {
+         try
+         {
+            VirtualFile child = root.findChild(name);
+            urls.add(child.toURL());
+         }
+         catch (Exception ignored)
+         {
+            log.trace("Error getting resources for " + root, ignored);
+         }
+      }
+   }
+
+   /**
+    * Find a child from a path
+    * 
+    * @param path the path
+    * @return the child if found in the roots
+    */
+   protected VirtualFile findChild(String path)
+   {
+      for (VirtualFile root : roots)
+      {
+         try
+         {
+            return root.findChild(path);
+         }
+         catch (Exception ignored)
+         {
+            // not found
+         }
+      }
+      return null;
+   }
+   
+   @Override
+   public PackageInformation getPackageInformation(String packageName)
+   {
+      String path = packageName.replace('.', '/');
+      VirtualFile pkge = findChild(path);
+      if (pkge == null)
+         return null;
+      try
+      {
+         Manifest manifest = VFSUtils.getManifest(pkge.getVFS());
+         return new PackageInformation(packageName, manifest);
+      }
+      catch (IOException ignored)
+      {
+         log.trace("Unable to retrieve manifest for " + pkge + " " + ignored.getMessage());
+         return null;
+      }
+   }
+
+   @Override
+   protected ProtectionDomain getProtectionDomain(String className, String path)
+   {
+      VirtualFile clazz = findChild(path);
+      if (clazz == null)
+      {
+         log.trace("Unable to determine class file for " + className);
+         return null;
+      }
+      try
+      {
+         VirtualFile root = clazz.getVFS().getRoot();
+         URL codeSourceURL = root.toURL();
+         Certificate[] certs = null; // TODO determine certificates
+         CodeSource cs = new CodeSource(codeSourceURL, certs);
+         PermissionCollection permissions = Policy.getPolicy().getPermissions(cs);
+         return new ProtectionDomain(cs, permissions);
+      }
+      catch (Exception e)
+      {
+         throw new Error("Error determining protection domain for " + clazz, e);
+      }
+   }
+
+   /**
+    * Determine all the packages
+    * 
+    * @return the packages
+    * @throws IllegalArgumentException if there is no exportAll policy
+    */
+   protected Set<String> determineAllPackages()
+   {
+      PackageVisitor visitor = new PackageVisitor(exportAll);
+      for (VirtualFile root : roots)
+      {
+         try
+         {
+            root.visit(visitor);
+         }
+         catch (Exception e)
+         {
+            throw new Error("Error visiting " + root, e);
+         }
+      }
+      return visitor.getPackages();
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list