[jboss-cvs] JBossAS SVN: r99167 - in projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework: classloading and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 8 11:43:57 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-01-08 11:43:56 -0500 (Fri, 08 Jan 2010)
New Revision: 99167

Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderFactory.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java
Log:
Load fragment resources from CL policy 

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2010-01-08 15:49:11 UTC (rev 99166)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java	2010-01-08 16:43:56 UTC (rev 99167)
@@ -192,21 +192,7 @@
          return getDeploymentUnit().getResourceLoader().getResource(name);
 
       ClassLoader classLoader = getDeploymentUnit().getClassLoader();
-      URL resourceURL = classLoader.getResource(name);
-      
-      // Try to find the resource in the attached fragments
-      if (resourceURL == null)
-      {
-         for (OSGiFragmentState fragment : getAttachedFragments())
-         {
-            classLoader = fragment.getDeploymentUnit().getClassLoader();
-            resourceURL = classLoader.getResource(name);
-            if (resourceURL != null)
-               break;
-         }
-      }
-      
-      return resourceURL;
+      return classLoader.getResource(name);
    }
 
    @SuppressWarnings("rawtypes")
@@ -219,7 +205,8 @@
       if (resolveBundle() == false)
          return getDeploymentUnit().getResourceLoader().getResources(name);
 
-      return getDeploymentUnit().getClassLoader().getResources(name);
+      ClassLoader classLoader = getDeploymentUnit().getClassLoader();
+      return classLoader.getResources(name);
    }
 
    // [TODO] options

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderFactory.java	2010-01-08 15:49:11 UTC (rev 99166)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderFactory.java	2010-01-08 16:43:56 UTC (rev 99167)
@@ -34,7 +34,7 @@
 import org.jboss.deployers.vfs.plugins.classloader.VFSDeploymentClassLoaderPolicyModule;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
 import org.jboss.osgi.framework.bundle.AbstractBundleState;
-import org.jboss.osgi.framework.bundle.AbstractDeployedBundleState;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
 import org.jboss.virtual.VirtualFile;
 
 /**
@@ -70,10 +70,9 @@
          public ClassLoaderPolicy createClassLoaderPolicy()
          {
             VFSDeploymentUnit vfsUnit = (VFSDeploymentUnit)unit;
-            AbstractBundleState bundleState = unit.getAttachment(AbstractBundleState.class);
-            AbstractDeployedBundleState depBundleState = (AbstractDeployedBundleState)bundleState;
-            VirtualFile[] roots = getClassLoaderPolicyRoots(depBundleState, vfsUnit);
-            ClassLoaderPolicy policy = new OSGiClassLoaderPolicy(depBundleState, roots);
+            OSGiBundleState bundleState = (OSGiBundleState)unit.getAttachment(AbstractBundleState.class);
+            VirtualFile[] roots = getClassLoaderPolicyRoots(bundleState, vfsUnit);
+            ClassLoaderPolicy policy = new OSGiClassLoaderPolicy(bundleState, roots);
             unit.addAttachment(ClassLoaderPolicy.class, policy);
             return policy;
          }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java	2010-01-08 15:49:11 UTC (rev 99166)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java	2010-01-08 16:43:56 UTC (rev 99167)
@@ -24,6 +24,7 @@
 // $Id$
 
 import java.io.File;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -31,7 +32,8 @@
 import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.plugins.classloader.VFSDeploymentClassLoaderPolicyModule;
-import org.jboss.osgi.framework.bundle.AbstractDeployedBundleState;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.bundle.OSGiFragmentState;
 import org.jboss.virtual.VirtualFile;
 
 /**
@@ -44,16 +46,20 @@
  */
 public class OSGiClassLoaderPolicy extends VFSClassLoaderPolicy
 {
+   // The bundle state associated with this policy
+   private OSGiBundleState bundleState;
    // Maps the lib name to native code archive
    private Map<String, File> libraryMap = new HashMap<String, File>();
    
-   public OSGiClassLoaderPolicy(AbstractDeployedBundleState bundleState, VirtualFile[] roots)
+   public OSGiClassLoaderPolicy(OSGiBundleState bundleState, VirtualFile[] roots)
    {
       super(roots);
       
       if (bundleState == null)
          throw new IllegalArgumentException("Null bundleState");
 
+      this.bundleState = bundleState;
+      
       DeploymentUnit unit = bundleState.getDeploymentUnit();
       Module module = unit.getAttachment(Module.class);
       if (module instanceof VFSDeploymentClassLoaderPolicyModule == false)
@@ -87,4 +93,24 @@
          
       return (libfile != null ? libfile.getAbsolutePath() : null);
    }
+
+   @Override
+   public URL getResource(String path)
+   {
+      URL resourceURL = super.getResource(path);
+      
+      // Try to find the resource in the attached fragments
+      if (resourceURL == null && bundleState.isFragment() == false)
+      {
+         for (OSGiFragmentState fragment : bundleState.getAttachedFragments())
+         {
+            ClassLoader classLoader = fragment.getDeploymentUnit().getClassLoader();
+            resourceURL = classLoader.getResource(path);
+            if (resourceURL != null)
+               break;
+         }
+      }
+      
+      return resourceURL;
+   }
 }




More information about the jboss-cvs-commits mailing list