当前位置: 首页>>代码示例>>Java>>正文


Java Bundle.getEntryPaths方法代码示例

本文整理汇总了Java中org.osgi.framework.Bundle.getEntryPaths方法的典型用法代码示例。如果您正苦于以下问题:Java Bundle.getEntryPaths方法的具体用法?Java Bundle.getEntryPaths怎么用?Java Bundle.getEntryPaths使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.osgi.framework.Bundle的用法示例。


在下文中一共展示了Bundle.getEntryPaths方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findImportedBundleMatchingResource

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
/**
 * Searches for the given pattern inside the imported bundle. This translates to pattern matching on the imported
 * packages.
 * 
 * @param importedBundle imported bundle
 * @param path path used for pattern matching
 * @param foundPaths collection of found results
 */
@SuppressWarnings("unchecked")
private void findImportedBundleMatchingResource(final ImportedBundle importedBundle, String rootPath, String path,
		final Collection<String> foundPaths) throws IOException {

	final boolean trace = logger.isTraceEnabled();

	String[] packages = importedBundle.getImportedPackages();

	if (trace)
		logger.trace("Searching path [" + path + "] on imported pkgs " + ObjectUtils.nullSafeToString(packages)
				+ "...");

	final boolean startsWithSlash = rootPath.startsWith(FOLDER_SEPARATOR);

	for (int i = 0; i < packages.length; i++) {
		// transform the package name into a path
		String pkg = packages[i].replace(DOT, SLASH) + SLASH;

		if (startsWithSlash) {
			pkg = FOLDER_SEPARATOR + pkg;
		}

		final PathMatcher matcher = getPathMatcher();
		// if the imported package matches the path
		if (matcher.matchStart(path, pkg)) {
			Bundle bundle = importedBundle.getBundle();
			// 1. look at the Bundle jar root
			Enumeration<String> entries = bundle.getEntryPaths(pkg);
			while (entries != null && entries.hasMoreElements()) {
				String entry = entries.nextElement();
				if (startsWithSlash)
					entry = FOLDER_SEPARATOR + entry;

				if (matcher.match(path, entry)) {
					if (trace)
						logger.trace("Found entry [" + entry + "]");
					foundPaths.add(entry);
				}
			}
			// 2. Do a Bundle-Classpath lookup (since the jar might use a different classpath)
			Collection<String> cpMatchingPaths = findBundleClassPathMatchingPaths(bundle, path);
			foundPaths.addAll(cpMatchingPaths);
		}
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:54,代码来源:OsgiBundleResourcePatternResolver.java

示例2: doRetrieveMatchingBundleEntries

import org.osgi.framework.Bundle; //导入方法依赖的package包/类
/**
 * Searches each level inside the bundle for entries based on the search strategy chosen.
 * 
 * @param bundle the bundle to do the lookup
 * @param fullPattern matching pattern
 * @param dir directory inside the bundle
 * @param result set of results (used to concatenate matching sub dirs)
 * @param searchType the search strategy to use
 * @throws IOException
 */
private void doRetrieveMatchingBundleEntries(Bundle bundle, String fullPattern, String dir, Set<Resource> result,
		int searchType) throws IOException {

	Enumeration<?> candidates;

	switch (searchType) {
	case OsgiResourceUtils.PREFIX_TYPE_NOT_SPECIFIED:
	case OsgiResourceUtils.PREFIX_TYPE_BUNDLE_SPACE:
		// returns an enumeration of URLs
		candidates = bundle.findEntries(dir, null, false);
		break;
	case OsgiResourceUtils.PREFIX_TYPE_BUNDLE_JAR:
		// returns an enumeration of Strings
		candidates = bundle.getEntryPaths(dir);
		break;
	case OsgiResourceUtils.PREFIX_TYPE_CLASS_SPACE:
		// returns an enumeration of URLs
		throw new IllegalArgumentException("class space does not support pattern matching");
	default:
		throw new IllegalArgumentException("unknown searchType " + searchType);
	}

	// entries are relative to the root path - miss the leading /
	if (candidates != null) {
		boolean dirDepthNotFixed = (fullPattern.indexOf(FOLDER_WILDCARD) != -1);
		while (candidates.hasMoreElements()) {
			Object path = candidates.nextElement();
			String currPath;

			if (path instanceof String)
				currPath = handleString((String) path);
			else
				currPath = handleURL((URL) path);

			if (!currPath.startsWith(dir)) {
				// Returned resource path does not start with relative
				// directory:
				// assuming absolute path returned -> strip absolute path.
				int dirIndex = currPath.indexOf(dir);
				if (dirIndex != -1) {
					currPath = currPath.substring(dirIndex);
				}
			}

			if (currPath.endsWith(FOLDER_SEPARATOR)
					&& (dirDepthNotFixed || StringUtils.countOccurrencesOf(currPath, FOLDER_SEPARATOR) < StringUtils
							.countOccurrencesOf(fullPattern, FOLDER_SEPARATOR))) {
				// Search subdirectories recursively: we manually get the
				// folders on only one level

				doRetrieveMatchingBundleEntries(bundle, fullPattern, currPath, result, searchType);
			}
			if (getPathMatcher().match(fullPattern, currPath)) {
				if (path instanceof URL)
					result.add(new UrlContextResource((URL) path, currPath));
				else
					result.add(new OsgiBundleResource(bundle, currPath));

			}
		}
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:73,代码来源:OsgiBundleResourcePatternResolver.java


注:本文中的org.osgi.framework.Bundle.getEntryPaths方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。