[jboss-dev-forums] [JBoss OSGi Development] - Handling of Bundle-ClassPath

thomas.diesler@jboss.com do-not-reply at jboss.com
Wed Oct 7 13:29:49 EDT 2009


The Bundle-ClassPath is now handles in OSGiClassLoaderFactory like this


  |          public ClassLoaderPolicy createClassLoaderPolicy()
  |          {
  |             VFSDeploymentUnit vfsUnit = (VFSDeploymentUnit)unit;
  |             OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
  |             VirtualFile[] roots = getClassLoaderPolicyRoots(bundleState, vfsUnit);
  |             return new OSGiClassLoaderPolicy(bundleState, roots);
  |          }
  | 
  |          private VirtualFile[] getClassLoaderPolicyRoots(OSGiBundleState bundleState, VFSDeploymentUnit vfsUnit)
  |          {
  |             VirtualFile root = vfsUnit.getRoot();
  |             
  |             // If there is no Bundle-ClassPath in the manifest, simply use the root
  |             List<String> bundleClassPath = bundleState.getOSGiMetaData().getBundleClassPath();
  |             if (bundleClassPath == null)
  |             {
  |                return new VirtualFile[] { root };
  |             }
  |             
  |             log.debug("Bundle-ClassPath: " + bundleClassPath);
  |             
  |             // Add a vfs root for every Bundle-ClassPath element
  |             List<VirtualFile> rootsList = new ArrayList<VirtualFile>();
  |             for (String path : bundleClassPath)
  |             {
  |                if (path.equals("."))
  |                {
  |                   rootsList.add(root);
  |                }
  |                else
  |                {
  |                   try
  |                   {
  |                      VirtualFile child = root.getChild(path);
  |                      rootsList.add(child);
  |                   }
  |                   catch (IOException ex)
  |                   {
  |                      throw new IllegalArgumentException("Cannot find class path '" + path + "' in: " + root);
  |                   }
  |                }
  |             }
  |             
  |             VirtualFile[] rootsArray = new VirtualFile[rootsList.size()];
  |             rootsList.toArray(rootsArray);
  |             
  |             return rootsArray;
  |          }
  | 

Note, I create a policy root entry for every bundle class path token.

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4259229#4259229

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4259229



More information about the jboss-dev-forums mailing list