/**
  * Support for 'bundle:/' to look for libraries in osgi bundles or classes or ruby files.
  *
  * @mri rb_find_file
  * @param name the file to find, this is a path name
  * @return the correct file
  */
 @Override
 protected LoadServiceResource findFileInClasspath(String name) {
   if (name.startsWith(OSGI_BUNDLE_CLASSPATH_SCHEME)) {
     name = cleanupFindName(name);
     StringTokenizer tokenizer = new StringTokenizer(name, "/", false);
     tokenizer.nextToken();
     String symname = tokenizer.nextToken();
     StringBuilder sb = new StringBuilder();
     if (!tokenizer.hasMoreTokens()) {
       sb.append('/');
     } else {
       while (tokenizer.hasMoreTokens()) {
         sb.append('/');
         sb.append(tokenizer.nextToken());
       }
     }
     Bundle bundle = OSGiFileLocator.getBundle(symname);
     if (bundle != null) {
       URL url = bundle.getEntry(sb.toString());
       if (url != null) {
         return new LoadServiceResource(OSGiFileLocator.getLocalURL(url), name);
       }
     }
   }
   return super.findFileInClasspath(name);
 }
Exemple #2
0
 /** Support for 'bundle:/' to look for libraries in osgi bundles. */
 @Override
 protected Library createLibrary(SearchState state, LoadServiceResource resource) {
   if (resource == null) {
     return null;
   }
   String file = state.loadName;
   if (file.startsWith(OSGI_BUNDLE_CLASSPATH_SCHEME)) {
     file = cleanupFindName(file);
     StringTokenizer tokenizer = new StringTokenizer(file, "/", false);
     tokenizer.nextToken();
     String symname = tokenizer.nextToken();
     Bundle bundle = OSGiFileLocator.getBundle(symname);
     if (bundle != null) {
       return new OSGiBundleLibrary(bundle);
     }
   }
   return super.createLibrary(state, resource);
 }