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


Java PackageAdmin.getBundle方法代码示例

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


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

示例1: getDMCoreBundle

import org.osgi.service.packageadmin.PackageAdmin; //导入方法依赖的package包/类
public static Bundle getDMCoreBundle(BundleContext ctx) {
	ServiceReference ref = ctx.getServiceReference(PackageAdmin.class.getName());
	if (ref != null) {
		Object service = ctx.getService(ref);
		if (service instanceof PackageAdmin) {
			PackageAdmin pa = (PackageAdmin) service;
			if (pa != null) {
				return pa.getBundle(OsgiBundleXmlApplicationContext.class);
			}
		}
	}
	return null;
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:14,代码来源:BundleUtils.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


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