org.osgi.framework.Bundle.getResources()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.1k)|赞(0)|评价(0)|浏览(162)

本文整理了Java中org.osgi.framework.Bundle.getResources()方法的一些代码示例,展示了Bundle.getResources()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bundle.getResources()方法的具体详情如下:
包路径:org.osgi.framework.Bundle
类名称:Bundle
方法名:getResources

Bundle.getResources介绍

[英]Find the specified resources from this bundle's class loader. This bundle's class loader is called to search for the specified resources. If this bundle's state is INSTALLED, this method must attempt to resolve this bundle before attempting to get the specified resources. If this bundle cannot be resolved, then only this bundle must be searched for the specified resources. Imported packages cannot be searched when a bundle has not been resolved. If this bundle is a fragment bundle then null is returned.

Note: Jar and zip files are not required to include directory entries. URLs to directory entries will not be returned if the bundle contents do not contain directory entries.
[中]从该捆绑包的类装入器中查找指定的资源。调用此捆绑包的类加载器来搜索指定的资源。如果此捆绑包的状态为已安装,则此方法必须在尝试获取指定资源之前尝试解析此捆绑包。如果无法解析此捆绑包,则必须仅在此捆绑包中搜索指定的资源。未解析包时,无法搜索导入的包。如果此捆绑包是片段捆绑包,则返回null。
注意:Jar和zip文件不需要包含目录条目。如果捆绑包内容不包含目录项,则不会返回指向目录项的URL。

代码示例

代码示例来源:origin: apache/ignite

/**
 * Finds a given resource from within the {@link #bundle}.
 *
 * @param name The resource name.
 * @return URLs of resources.
 * @throws IOException
 */
@SuppressWarnings({"unchecked", "rawtypes"})
protected Enumeration findResources(String name) throws IOException {
  return bundle.getResources(name);
}

代码示例来源:origin: hibernate/hibernate-orm

for ( Bundle bundle : bundles ) {
  try {
    final Enumeration<URL> resources = bundle.getResources( name );
    if ( resources != null ) {
      enumerations.add( resources );

代码示例来源:origin: org.dhatim/milyn-smooks-all

@SuppressWarnings("unchecked")
@Override
protected Enumeration<URL> findResources(String name) throws IOException
{
  return bundle.getResources(name);
}

代码示例来源:origin: org.eclipse/org.eclipse.osgi

public Enumeration<URL> getResources(String name) throws IOException {
  Bundle current = systemBundle;
  if (current == null)
    return null;
  return current.getResources(name);
}

代码示例来源:origin: net.sf.jnrpe/jnrpe-osgi-core

@SuppressWarnings("unchecked")
@Override
protected final Enumeration<URL> findResources(final String resName) throws IOException {
  return bundle.getResources(resName);
}

代码示例来源:origin: org.apache.openejb.patch/openjpa

@SuppressWarnings("unchecked")
@Override
protected Enumeration<URL> findResources(String resName) throws IOException {
 return bundle.getResources(resName);
}

代码示例来源:origin: org.jboss.osgi/jboss-osgi-spi

@SuppressWarnings("unchecked")
protected Enumeration<URL> findResources(String name) throws IOException
{
 return bundle.getResources(name);
}

代码示例来源:origin: org.apache.openjpa/openjpa-all

@SuppressWarnings("unchecked")
@Override
protected Enumeration<URL> findResources(String resName) throws IOException {
 return bundle.getResources(resName);
}

代码示例来源:origin: org.glassfish.hk2/osgi-adapter

@Override
public Enumeration<URL> getResources(String name) throws IOException {
  Enumeration<URL> resources = bundle.getResources(name);
  if (resources==null) {
    // This check is needed, because ClassLoader.getResources()
    // expects us to return an empty enumeration.
    resources = EMPTY_URLS;
  }
  return resources;
}

代码示例来源:origin: org.apache.openejb.patch/openjpa-persistence

@SuppressWarnings("unchecked")
@Override
protected Enumeration<URL> findResources(String resName) throws IOException {
 return bundle.getResources(resName);
}

代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.osgi

public Enumeration<URL> getResources(String name) throws IOException {
  Bundle current = systemBundle;
  if (current == null)
    return null;
  return current.getResources(name);
}

代码示例来源:origin: org.apache.cxf/cxf-rt-core

@SuppressWarnings("unchecked")
public Enumeration<URL> run() throws IOException {
  return bundle.getResources(name);
}

代码示例来源:origin: org.apache.camel/camel-jcache

@Override
  protected Enumeration findResources(String name) throws IOException {
    try {
      return acl.getResources(name);
    } catch (IOException e) {
      return bundle.getResources(name);
    }
  }
};

代码示例来源:origin: stackoverflow.com

Bundle bundle = FrameworkUtil.getBundle(this.getClass());
Enumeration<URL> resources = bundle.getResources("/com/me/myapp/style.css");   
if (resources != null) {
  URL myCSS = resources.nextElement();
}

代码示例来源:origin: org.apache.tuscany.sca/tuscany-contribution-osgi

@SuppressWarnings("unchecked")
  @Override
  protected Enumeration<URL> findResources(String name) throws IOException {
    Enumeration<URL> urls = bundle.getResources(name);
    if (urls == null) {
      List<URL> list = Collections.emptyList();
      return Collections.enumeration(list);
    } else {
      return urls;
    }
  }
}

代码示例来源:origin: org.apache.xbean/xbean-bundleutils

public Enumeration<URL> getResources(String name) throws IOException {
  ArrayList<URL> allResources = new ArrayList<URL>();
  for (Bundle bundle : bundles) {
    Enumeration<URL> e = bundle.getResources(name);
    addToList(allResources, e);
  }
  return Collections.enumeration(allResources);
}

代码示例来源:origin: org.ops4j.pax.wicket/org.ops4j.pax.wicket.service

public Iterator<URL> getResources(String name) {
  try {
    final Bundle bundle = bundleContext.getBundle();
    final Enumeration<URL> enumeration = bundle.getResources(name);
    if (null == enumeration) {
      return null;
    }
    return new EnumerationAdapter<URL>(enumeration);
  } catch (IOException e) {
    return Collections.<URL> emptyList().iterator();
  }
}

代码示例来源:origin: org.ops4j.pax.cdi/pax-cdi-weld

public Enumeration<URL> getResources(String name) throws IOException {
  ArrayList<URL> allResources = new ArrayList<URL>();
  for (Bundle b : bundles) {
    Enumeration<URL> e = b.getResources(name);
    addToList(allResources, e);
  }
  return Collections.enumeration(allResources);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-rt-felix

@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);
  }
}

代码示例来源:origin: org.apache.camel/camel-core-osgi

@Override
public Enumeration<URL> loadResourcesAsURL(String uri) {
  ObjectHelper.notEmpty(uri, "uri");
  try {
    String resolvedName = resolveUriPath(uri);
    return bundleContext.getBundle().getResources(resolvedName);
  } catch (IOException e) {
    throw new RuntimeException("Cannot load resource: " + uri, e);
  }
}

相关文章