本文整理汇总了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;
}
示例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";
}