本文整理汇总了Java中org.osgi.service.packageadmin.ExportedPackage.getImportingBundles方法的典型用法代码示例。如果您正苦于以下问题:Java ExportedPackage.getImportingBundles方法的具体用法?Java ExportedPackage.getImportingBundles怎么用?Java ExportedPackage.getImportingBundles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.osgi.service.packageadmin.ExportedPackage
的用法示例。
在下文中一共展示了ExportedPackage.getImportingBundles方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getImportedPackages
import org.osgi.service.packageadmin.ExportedPackage; //导入方法依赖的package包/类
public String[] getImportedPackages(Bundle bundle) {
Set<String> importedPackages = new TreeSet<String>();
Set<Bundle> seenBundles = new HashSet<Bundle>();
Bundle[] bundles = bundleContext.getBundles();
for (int i = 0; i < bundles.length; i++) {
Bundle analyzedBundle = bundles[i];
if (!seenBundles.contains(analyzedBundle)) {
seenBundles.add(bundle);
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])) {
importedPackages.add(exportedPackage.getName() + ";version="
+ exportedPackage.getVersion());
}
}
}
}
}
return (String[]) importedPackages.toArray(new String[importedPackages.size()]);
}
示例2: getImportedBundles
import org.osgi.service.packageadmin.ExportedPackage; //导入方法依赖的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()]);
}
示例3: isImportedByBundle
import org.osgi.service.packageadmin.ExportedPackage; //导入方法依赖的package包/类
private boolean isImportedByBundle(ExportedPackage exportedPackage, Bundle bundle) {
Bundle[] importingBundles = exportedPackage.getImportingBundles();
return ArrayUtils.contains(importingBundles, bundle);
}
示例4: getImportedBundles
import org.osgi.service.packageadmin.ExportedPackage; //导入方法依赖的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()]);
}