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


Java PackageAdmin.getExportedPackages方法代码示例

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


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

示例1: getImportedBundles

import org.osgi.service.packageadmin.PackageAdmin; //导入方法依赖的package包/类
public ImportedBundle[] getImportedBundles(Bundle bundle) {
	boolean trace = log.isTraceEnabled();

	PackageAdmin pa = getPackageAdmin();

	// create map with bundles as keys and a list of packages as value
	Map<Bundle, List<String>> importedBundles = new LinkedHashMap<Bundle, List<String>>(8);

	// 1. consider required bundles first

	// see if there are required bundle(s) defined
	String[] entries = OsgiHeaderUtils.getRequireBundle(bundle);

	// 1. if so, locate the bundles
	for (int i = 0; i < entries.length; i++) {
		String[] parsed = OsgiHeaderUtils.parseRequiredBundleString(entries[i]);
		// trim the strings just to be on the safe side (some implementations allows whitespaces, some don't)
		String symName = parsed[0].trim();
		String versionRange = parsed[1].trim();
		Bundle[] foundBundles = pa.getBundles(symName, versionRange);

		if (!ObjectUtils.isEmpty(foundBundles)) {
			Bundle requiredBundle = foundBundles[0];

			// find exported packages
			ExportedPackage[] exportedPackages = pa.getExportedPackages(requiredBundle);
			if (exportedPackages != null)
				addExportedPackages(importedBundles, requiredBundle, exportedPackages);
		}
		else {
			if (trace) {
				log.trace("Cannot find required bundle " + symName + "|" + versionRange);
			}
		}
	}

	// 2. determine imported bundles 
	// get all bundles
	Bundle[] bundles = bundleContext.getBundles();

	for (int i = 0; i < bundles.length; i++) {
		Bundle analyzedBundle = bundles[i];
		// if the bundle is already included (it's a required one), there's no need to look at it again
		if (!importedBundles.containsKey(analyzedBundle)) {
			ExportedPackage[] epa = pa.getExportedPackages(analyzedBundle);
			if (epa != null)
				for (int j = 0; j < epa.length; j++) {
					ExportedPackage exportedPackage = epa[j];
					Bundle[] importingBundles = exportedPackage.getImportingBundles();
					if (importingBundles != null)
						for (int k = 0; k < importingBundles.length; k++) {
							if (bundle.equals(importingBundles[k])) {
								addImportedBundle(importedBundles, exportedPackage);
							}
						}
				}
		}
	}

	List<ImportedBundle> importedBundlesList = new ArrayList<ImportedBundle>(importedBundles.size());

	for (Map.Entry<Bundle, List<String>> entry : importedBundles.entrySet()) {
		Bundle importedBundle = entry.getKey();
		List<String> packages = entry.getValue();
		importedBundlesList.add(new ImportedBundle(importedBundle,
			(String[]) packages.toArray(new String[packages.size()])));
	}

	return (ImportedBundle[]) importedBundlesList.toArray(new ImportedBundle[importedBundlesList.size()]);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:71,代码来源:PackageAdminResolver.java

示例2: getVersion

import org.osgi.service.packageadmin.PackageAdmin; //导入方法依赖的package包/类
/**
 * Tries to retrieve the version of iClass via the PackageAdmin.
 *
 * @param iClass tThe interface for which the version should be found
 * @param bc any valid BundleContext
 * @return the version of the interface or "0.0.0" if no version information could be found or an error
 *         occurred during the retrieval
 */
public static String getVersion(Class<?> iClass, BundleContext bc) {
    ServiceReference<PackageAdmin> paRef = bc.getServiceReference(PackageAdmin.class);
    if (paRef != null) {
        PackageAdmin pa = bc.getService(paRef);
        try {
            Bundle b = pa.getBundle(iClass);
            if (b == null) {
                LOG.info("Unable to find interface version for interface " + iClass.getName()
                        + ". Falling back to 0.0.0");
                return "0.0.0";
            }
            LOG.debug("Interface source bundle: {}", b.getSymbolicName());

            ExportedPackage[] ep = pa.getExportedPackages(b);
            LOG.debug("Exported Packages of the source bundle: {}", (Object)ep);

            String pack = iClass.getPackage().getName();
            LOG.debug("Looking for Package: {}", pack);
            if (ep != null) {
                for (ExportedPackage p : ep) {
                    if (p != null
                        && pack.equals(p.getName())) {
                        LOG.debug("found package -> Version: {}", p.getVersion());
                        return p.getVersion().toString();
                    }
                }
            }
        } finally {
            if (pa != null) {
                bc.ungetService(paRef);
            }
        }
    } else {
        LOG.error("Was unable to obtain the package admin service -> can't resolve interface versions");
    }

    LOG.info("Unable to find interface version for interface " + iClass.getName()
             + ". Falling back to 0.0.0");
    return "0.0.0";
}
 
开发者ID:apache,项目名称:aries-rsa,代码行数:49,代码来源:PackageUtil.java

示例3: getImportedBundles

import org.osgi.service.packageadmin.PackageAdmin; //导入方法依赖的package包/类
public ImportedBundle[] getImportedBundles(Bundle bundle) {
	boolean trace = log.isTraceEnabled();

	PackageAdmin pa = getPackageAdmin();

	// create map with bundles as keys and a list of packages as value
	Map importedBundles = new LinkedHashMap(8);

	// 1. consider required bundles first

	// see if there are required bundle(s) defined
	String[] entries = OsgiHeaderUtils.getRequireBundle(bundle);

	// 1. if so, locate the bundles
	for (int i = 0; i < entries.length; i++) {
		String[] parsed = OsgiHeaderUtils.parseRequiredBundleString(entries[i]);
		// trim the strings just to be on the safe side (some implementations allows whitespaces, some don't)
		String symName = parsed[0].trim();
		String versionRange = parsed[1].trim();
		Bundle[] foundBundles = pa.getBundles(symName, versionRange);

		if (!ObjectUtils.isEmpty(foundBundles)) {
			Bundle requiredBundle = foundBundles[0];

			// find exported packages
			ExportedPackage[] exportedPackages = pa.getExportedPackages(requiredBundle);
			if (exportedPackages != null)
				addExportedPackages(importedBundles, requiredBundle, exportedPackages);
		}
		else {
			if (trace) {
				log.trace("Cannot find required bundle " + symName + "|" + versionRange);
			}
		}
	}

	// 2. determine imported bundles 
	// get all bundles
	Bundle[] bundles = bundleContext.getBundles();

	for (int i = 0; i < bundles.length; i++) {
		Bundle analyzedBundle = bundles[i];
		// if the bundle is already included (it's a required one), there's no need to look at it again
		if (!importedBundles.containsKey(analyzedBundle)) {
			ExportedPackage[] epa = pa.getExportedPackages(analyzedBundle);
			if (epa != null)
				for (int j = 0; j < epa.length; j++) {
					ExportedPackage exportedPackage = epa[j];
					Bundle[] importingBundles = exportedPackage.getImportingBundles();
					if (importingBundles != null)
						for (int k = 0; k < importingBundles.length; k++) {
							if (bundle.equals(importingBundles[k])) {
								addImportedBundle(importedBundles, exportedPackage);
							}
						}
				}
		}
	}

	List importedBundlesList = new ArrayList(importedBundles.size());

	for (Iterator iterator = importedBundles.entrySet().iterator(); iterator.hasNext();) {
		Map.Entry entry = (Map.Entry) iterator.next();
		Bundle importedBundle = (Bundle) entry.getKey();
		List packages = (List) entry.getValue();
		importedBundlesList.add(new ImportedBundle(importedBundle,
			(String[]) packages.toArray(new String[packages.size()])));
	}

	return (ImportedBundle[]) importedBundlesList.toArray(new ImportedBundle[importedBundlesList.size()]);
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:72,代码来源:PackageAdminResolver.java


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