Java Code Examples for org.osgi.framework.Bundle#getResources()

The following examples show how to use org.osgi.framework.Bundle#getResources() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NetigsoLoader.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Enumeration<URL> findResources(String name) {
    //Netigso.start();
    Bundle b = bundle;
    if (b == null) {
        LOG.log(Level.WARNING, "Trying to load resource before initialization finished {0}", name);
        return Enumerations.empty();
    }
    Enumeration<URL> ret = null;
    try {
        if (b.getState() != Bundle.UNINSTALLED) {
            ret = b.getResources(name);
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return ret == null ? Enumerations.<URL>empty() : NbCollections.checkedEnumerationByFilter(ret, URL.class, true);
}
 
Example 2
Source File: ExtensionClassLoader.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Enumeration<URL> getResources(String name) throws IOException {

  List<URL> resources = new ArrayList<>();

  for (Bundle bundle : mBundles) {
    Enumeration<URL> bundleResources = bundle.getResources(name);
    if (bundleResources != null) {
      resources.addAll(Collections.list(bundleResources));
    }
  }
  return Collections.enumeration(resources);

}
 
Example 3
Source File: OSGiClassLoader.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected @Override Enumeration<URL> findResources(String name) throws IOException {
    List<Enumeration<URL>> resourcess = new ArrayList<Enumeration<URL>>();
    for (Bundle b : bundles()) {
        Enumeration<?> resourcesRaw = b.getResources(name);
        if (resourcesRaw == null) {
            // Oddly, this is permitted.
            continue;
        }
        Enumeration<URL> resources = NbCollections.checkedEnumerationByFilter(resourcesRaw, URL.class, true);
        if (resources != null) {
            resourcess.add(resources);
        }
    }
    return Enumerations.concat(Collections.enumeration(resourcess));
}
 
Example 4
Source File: EmbeddedFramework.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public <T> Enumeration<URL> getResourcesFromBundle(String type, Bundle b) throws IOException {
    if (EmbeddedFelixFramework.isExtensionBundle(b)) {
        return getClass().getClassLoader().getResources(type);
    } else {
        return b.getResources(type);
    }
}
 
Example 5
Source File: BundleBasedUIResourceProvider.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
public URL getUIResource(String name) {
    String resourceName = bundleResourcePath + name;
    int lastSlash = resourceName.lastIndexOf('/');
    if (lastSlash == -1) {
        return null;
    }

    String path = resourceName.substring(0, lastSlash);
    if (path.length() == 0) {
        path = "/";
    }
    String file = resourceName.substring(lastSlash + 1);

    //Searching the resourceBundle for the given bundle resource paths.
    String resourcePath = CarbonUIUtil.getBundleResourcePath(name);
    Bundle resourceBundle = bundleResourceMap.get(resourcePath);
    if (resourceBundle != null) {
        Enumeration entryPaths = null;
        try { 
            entryPaths = resourceBundle.getResources(path + "/" + file); 
        } catch (IOException ignored) { 
            log.error(ignored.getMessage(), ignored); 
        }
        if (entryPaths != null && entryPaths.hasMoreElements()) {
            return (URL) entryPaths.nextElement();
        }
    }
    return null;
}
 
Example 6
Source File: ContainerFramework.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Override
public <T> Enumeration<URL> getResourcesFromBundle(String type, Bundle b) throws IOException {
    return b.getResources(type);
}