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

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

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

Bundle.findEntries介绍

[英]Returns entries in this bundle and its attached fragments. This bundle's class loader is not used to search for entries. Only the contents of this bundle and its attached fragments are searched for the specified entries. If this bundle's state is INSTALLED, this method must attempt to resolve this bundle before attempting to find entries.

This method is intended to be used to obtain configuration, setup, localization and other information from this bundle. This method takes into account that the "contents" of this bundle can be extended with fragments. This "bundle space" is not a namespace with unique members; the same entry name can be present multiple times. This method therefore returns an enumeration of URL objects. These URLs can come from different JARs but have the same path name. This method can either return only entries in the specified path or recurse into subdirectories returning entries in the directory tree beginning at the specified path. Fragments can be attached after this bundle is resolved, possibly changing the set of URLs returned by this method. If this bundle is not resolved, only the entries in the JAR file of this bundle are returned.

Examples:

// List all XML files in the OSGI-INF directory and below 
Enumeration e = b.findEntries("OSGI-INF", "*.xml", true); 
// Find a specific localization file 
Enumeration e = b.findEntries("OSGI-INF/l10n", 
"bundle_nl_DU.properties", false); 
if (e.hasMoreElements()) 
return (URL) e.nextElement();

URLs for directory entries must have their path end with "/".

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.
[中]返回此捆绑包及其附加片段中的条目。此捆绑包的类加载器不用于搜索条目。仅搜索此捆绑包及其附加片段的内容以查找指定的条目。如果此捆绑包的状态已安装,则此方法必须在尝试查找条目之前尝试解析此捆绑包。
此方法用于从该捆绑包中获取配置、设置、本地化和其他信息。此方法考虑到此捆绑包的“内容”可以使用片段进行扩展。此“捆绑空间”不是具有唯一成员的命名空间;同一条目名称可以出现多次。因此,此方法返回URL对象的枚举。这些URL可以来自不同的JAR,但具有相同的路径名。此方法可以只返回指定路径中的条目,也可以递归到子目录中,返回从指定路径开始的目录树中的条目。解析此捆绑包后可以附加片段,这可能会更改此方法返回的URL集。如果未解析此捆绑包,则仅返回此捆绑包的JAR文件中的条目。
示例:

// List all XML files in the OSGI-INF directory and below 
Enumeration e = b.findEntries("OSGI-INF", "*.xml", true); 
// Find a specific localization file 
Enumeration e = b.findEntries("OSGI-INF/l10n", 
"bundle_nl_DU.properties", false); 
if (e.hasMoreElements()) 
return (URL) e.nextElement();

目录项的URL路径必须以“/”结尾。
注意:Jar和zip文件不需要包含目录条目。如果捆绑包内容不包含目录项,则不会返回指向目录项的URL。

代码示例

代码示例来源:origin: jersey/jersey

@SuppressWarnings("unchecked")
  @Override
  public Enumeration<URL> run() {
    return bundle.findEntries(path, fileNamePattern, recursive);
  }
});

代码示例来源:origin: jersey/jersey

@SuppressWarnings("unchecked")
  @Override
  public Enumeration<URL> run() {
    return bundle.findEntries(path, fileNamePattern, recursive);
  }
});

代码示例来源:origin: gocd/gocd

private List<Class> getCandidateGoExtensionClasses(Bundle bundle) throws ClassNotFoundException {
  List<Class> candidateClasses = new ArrayList<>();
  Enumeration<URL> entries = bundle.findEntries("/", "*.class", true);
  while (entries.hasMoreElements()) {
    String entryPath = entries.nextElement().getFile();
    if (isInvalidPath(entryPath)) {
      continue;
    }
    Class<?> candidateClass = loadClass(bundle, entryPath);
    if (candidateClass != null && isValidClass(candidateClass)) {
      candidateClasses.add(candidateClass);
    }
  }
  return candidateClasses;
}

代码示例来源:origin: gocd/gocd

private void setupClassesInBundle(String... classes) throws MalformedURLException, ClassNotFoundException {
  Hashtable<URL, String> classFileEntries = new Hashtable<>();
  for (String aClass : classes) {
    classFileEntries.put(new URL("file:///" + aClass), "");
  }
  when(bundle.findEntries("/", "*.class", true)).thenReturn(classFileEntries.keys());
}

代码示例来源:origin: gocd/gocd

@Before
public void setUp() {
  initMocks(this);
  when(context.getServiceReference(PluginHealthService.class)).thenReturn(pluginHealthServiceReference);
  when(context.getServiceReference(LoggingService.class)).thenReturn(loggingServiceReference);
  when(context.getService(pluginHealthServiceReference)).thenReturn(pluginHealthService);
  when(context.getService(loggingServiceReference)).thenReturn(loggingService);
  when(context.getBundle()).thenReturn(bundle);
  when(bundle.getSymbolicName()).thenReturn(PLUGIN_ID);
  when(bundle.findEntries("/", "*.class", true)).thenReturn(emptyListOfClassesInBundle);
  activator = new DefaultGoPluginActivator();
}

代码示例来源:origin: eclipse/smarthome

private List<String> determineResourceNames() {
  List<String> resourceNames = new ArrayList<String>();
  Enumeration<URL> resourceFiles = this.bundle.findEntries(RESOURCE_DIRECTORY, RESOURCE_FILE_PATTERN, true);
  if (resourceFiles != null) {
    while (resourceFiles.hasMoreElements()) {
      URL resourceURL = resourceFiles.nextElement();
      String resourcePath = resourceURL.getFile();
      File resourceFile = new File(resourcePath);
      String resourceFileName = resourceFile.getName();
      String baseName = resourceFileName.replaceFirst("[._]+.*", "");
      if (!resourceNames.contains(baseName)) {
        resourceNames.add(baseName);
      }
    }
  }
  return resourceNames;
}

代码示例来源:origin: spring-projects/spring-roo

public void execute(final Bundle bundle) {
  try {
   final Enumeration<URL> enumeration = bundle.findEntries(ROOT_PATH, "*", true);
   if (enumeration != null) {
    while (enumeration.hasMoreElements()) {
     final URL url = enumeration.nextElement();
     if (PATH_MATCHER.match(antPathExpression, url.getPath())) {
      results.add(url);
     }
    }
   }
  } catch (final IllegalStateException e) {
   // The bundle has been uninstalled - ignore it
  }
 }
}, context);

代码示例来源:origin: spring-projects/spring-roo

public void execute(final Bundle bundle) {
  try {
   final Enumeration<URL> enumeration = bundle.findEntries(ROOT_PATH, "*", true);
   if (enumeration != null) {
    while (enumeration.hasMoreElements()) {
     final URL url = enumeration.nextElement();
     if (PATH_MATCHER.match(antPathExpression, url.getPath())) {
      try {
       final URI uri = url.toURI();
       if (!uris.contains(uri)) {
        urls.add(url);
        uris.add(uri);
       }
      } catch (final URISyntaxException e) {
       // This URL can't be converted to a URI -
       // ignore it
      }
     }
    }
   }
  } catch (final IllegalStateException e) {
   // The bundle has been uninstalled - ignore it
  }
 }
}, context);

代码示例来源:origin: eclipse/smarthome

@Override
public URL getResource(String name) {
  Enumeration<URL> resourceFiles = this.bundle.findEntries(this.path, this.filePattern, true);

代码示例来源:origin: org.glassfish.jersey.core/jersey-common

@SuppressWarnings("unchecked")
  @Override
  public Enumeration<URL> run() {
    return bundle.findEntries(path, fileNamePattern, recursive);
  }
});

代码示例来源:origin: org.glassfish.jersey.bundles/jaxrs-ri

@SuppressWarnings("unchecked")
  @Override
  public Enumeration<URL> run() {
    return bundle.findEntries(path, fileNamePattern, recursive);
  }
});

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.core.filesystem

public static Enumeration<URL> findEntries(String path, String filePattern, boolean recurse) {
  if (instance != null && instance.context != null)
    return instance.context.getBundle().findEntries(path, filePattern, recurse);
  return null;
}

代码示例来源:origin: infinitest/infinitest

@SuppressWarnings("unchecked")
private List<URL> bundleUrlsForPattern() {
  Bundle pluginBundle = bundleSupplier.get();
  @SuppressWarnings("rawtypes")
  Enumeration entries = pluginBundle.findEntries("", extractPattern, true);
  return (List<URL>) Collections.list(entries);
}

代码示例来源:origin: OpenNMS/opennms

protected static String findWidgetset(Bundle bundle) {
    Enumeration<URL> widgetEntries = bundle.findEntries("", "*.gwt.xml", true);
//        Enumeration widgetEntries = bundle.getEntryPaths(VAADIN_PATH);
    if (widgetEntries == null || !widgetEntries.hasMoreElements())
      return null;

    URL widgetUrl = widgetEntries.nextElement();
    String path = widgetUrl.getPath();
    path = path.substring(1,path.length()-8);
    path = path.replace("/", ".");
    return path;
  }

代码示例来源:origin: org.opennms.features.vaadin-components/extender-service

protected String findWidgetset(Bundle bundle) {
    Enumeration<URL> widgetEntries = bundle.findEntries("", "*.gwt.xml", true);
//        Enumeration widgetEntries = bundle.getEntryPaths(VAADIN_PATH);
    if (widgetEntries == null || !widgetEntries.hasMoreElements())
      return null;

    URL widgetUrl = widgetEntries.nextElement();
    String path = widgetUrl.getPath();
    path = path.substring(1,path.length()-8);
    path = path.replace("/", ".");
    return path;
  }

代码示例来源:origin: org.apache.aries.blueprint/org.apache.aries.blueprint.core

private void addEntries(Bundle bundle, String path, String filePattern, List<URL> pathList) {
  Enumeration<?> e = bundle.findEntries(path, filePattern, false);
  while (e != null && e.hasMoreElements()) {
    URL u = (URL) e.nextElement();
    URL override = getOverrideURL(bundle, u, path);
    if (override == null) {
      pathList.add(u);
    } else {
      pathList.add(override);
    }
  }
}

代码示例来源:origin: com.liferay/com.liferay.portal.spring.extender

@Override
public Resource[] getResources(String locationPattern) {
  Enumeration<URL> enumeration = _bundle.findEntries(
    locationPattern, "*.xml", false);
  List<Resource> resources = new ArrayList<>();
  while (enumeration.hasMoreElements()) {
    resources.add(new UrlResource(enumeration.nextElement()));
  }
  return resources.toArray(new Resource[resources.size()]);
}

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

protected void register(final Bundle bundle) {
  Enumeration<?> e = bundle.findEntries("META-INF/cxf/", "bus-extensions.txt", false);
  while (e != null && e.hasMoreElements()) {
    List<Extension> orig = new TextExtensionFragmentParser(null).getExtensions((URL)e.nextElement());
    addExtensions(bundle, orig);
  }
}

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

protected void register(final Bundle bundle) {
  Enumeration<?> e = bundle.findEntries("META-INF/cxf/", "bus-extensions.txt", false);
  while (e != null && e.hasMoreElements()) {
    List<Extension> orig = new TextExtensionFragmentParser(null).getExtensions((URL)e.nextElement());
    addExtensions(bundle, orig);
  }
}

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

protected void register(final Bundle bundle) {
  Enumeration<?> e = bundle.findEntries("META-INF/cxf/", "bus-extensions.txt", false);
  while (e != null && e.hasMoreElements()) {
    List<Extension> orig = new TextExtensionFragmentParser(null).getExtensions((URL)e.nextElement());
    addExtensions(bundle, orig);
  }
}

相关文章