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


Java ExportedPackage类代码示例

本文整理汇总了Java中org.osgi.service.packageadmin.ExportedPackage的典型用法代码示例。如果您正苦于以下问题:Java ExportedPackage类的具体用法?Java ExportedPackage怎么用?Java ExportedPackage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getJasperBundle

import org.osgi.service.packageadmin.ExportedPackage; //导入依赖的package包/类
public static Bundle getJasperBundle() {
	Bundle bundle = getBundle(org.apache.jasper.servlet.JspServlet.class);
	if (bundle != null)
		return bundle;

	if (thisBundle == null)
		throw new IllegalStateException("Not started"); //$NON-NLS-1$

	ExportedPackage[] exportedPackages = packageAdmin.getExportedPackages("org.apache.jasper.servlet"); //$NON-NLS-1$
	for (int i = 0; i < exportedPackages.length; i++) {
		Bundle[] importingBundles = exportedPackages[i].getImportingBundles();
		for (int j = 0; j < importingBundles.length; j++) {
			if (thisBundle.equals(importingBundles[j]))
				return exportedPackages[i].getExportingBundle();
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:packagedrone,代码行数:19,代码来源:Activator.java

示例2: resolveBundleWiring

import org.osgi.service.packageadmin.ExportedPackage; //导入依赖的package包/类
/**
 * Resolves the bundle wiring for the bundle represented by {@link ExtendedBundleInformation} by creating
 * {@link PackageInfo} objects. These objects represent an OSGi import containing information about both of the
 * involved parties - the importer and the exporter.
 *
 * @param bundleInfo the object representing the bundle, it will be filled with the import information. The
 *                   bundle is resolved based on the bundle ID returned by
 *                   {@link org.motechproject.admin.bundles.ExtendedBundleInformation#getBundleId()}
 * @see PackageInfo
 */
public void resolveBundleWiring(ExtendedBundleInformation bundleInfo) {
    List<PackageInfo> imports = new ArrayList<>();
    List<PackageInfo> exports = new ArrayList<>();

    Bundle bundle = bundleContext.getBundle(bundleInfo.getBundleId());

    ExportedPackage[] allExportedPackages = packageAdmin.getExportedPackages((Bundle) null);

    for (ExportedPackage exportedPackage : allExportedPackages) {
        if (isImportedByBundle(exportedPackage, bundle)) {
            PackageInfo importInfo = new PackageInfo(exportedPackage);
            imports.add(importInfo);
        }

        if (exportedPackage.getExportingBundle().equals(bundle)) {
            PackageInfo exportInfo = new PackageInfo(exportedPackage);
            exports.add(exportInfo);
        }
    }

    bundleInfo.setBundleExports(exports);
    bundleInfo.setBundleImports(imports);
}
 
开发者ID:motech,项目名称:motech,代码行数:34,代码来源:ImportExportResolver.java

示例3: testResolveImportExport

import org.osgi.service.packageadmin.ExportedPackage; //导入依赖的package包/类
@Test
public void testResolveImportExport() {
    ExportedPackage[] allExportedPackages = new ExportedPackage[] { exportedPackage, importedPackage, unrelatedPackage,
        secondImportedPackage };
    long bundleId = 1;

    when(bundle.getBundleId()).thenReturn(bundleId);
    when(bundle.getSymbolicName()).thenReturn("my.bundle");
    when(bundle.getHeaders()).thenReturn(headers);
    when(otherBundle.getSymbolicName()).thenReturn("other.bundle");
    when(bundleContext.getBundle(bundleId)).thenReturn(bundle);
    when(packageAdmin.getExportedPackages((Bundle) null)).thenReturn(allExportedPackages);

    setUpExport(exportedPackage, bundle, new Bundle[]{ otherBundle }, "my.export", exportedVersion);
    setUpExport(unrelatedPackage, otherBundle, new Bundle[]{ }, "unrelated", exportedVersion);
    setUpExport(importedPackage, otherBundle, new Bundle[]{ bundle }, "my.import", importedVersion);
    setUpExport(secondImportedPackage, otherBundle, new Bundle[]{ bundle }, "my.import.number.two", secondImportedVersion);

    ExtendedBundleInformation bundleInfo = new ExtendedBundleInformation(bundle);

    importExportResolver.resolveBundleWiring(bundleInfo);

    assertEquals(expectedExports(), bundleInfo.getBundleExports());
    assertEquals(expectedImports(), bundleInfo.getBundleImports());
}
 
开发者ID:motech,项目名称:motech,代码行数:26,代码来源:ImportExportResolverTest.java

示例4: testUsedPackages

import org.osgi.service.packageadmin.ExportedPackage; //导入依赖的package包/类
@Test
public void testUsedPackages() throws ResourceNotFoundException, IllegalActionOnResourceException {
    Resource packages = get("/osgi/packages");
    assertThat(osgiHelper.getPackageAdmin()).isNotNull();
    for (Resource pkg : packages.getResources()) {
        PackageResource packageResource = pkg.adaptTo(PackageResource.class);
        String packageName = packageResource.getPackageName();
        boolean used = pkg.getMetadata().get("in-use", Boolean.class);
        assertThat(used).isEqualTo(packageResource.isUsed());
        ExportedPackage exportedPackage = osgiHelper.getPackageAdmin().getExportedPackage(packageName);
        assertThat(exportedPackage).isNotNull();
        if (used) {
            assertThat(pkg.getMetadata().get("version", Version.class)).isEqualTo(exportedPackage.getVersion());
            assertThat(exportedPackage.getImportingBundles()).isNotEmpty();
        }
    }
}
 
开发者ID:ow2-chameleon,项目名称:everest,代码行数:18,代码来源:TestOsgiResources.java

示例5: loadClass

import org.osgi.service.packageadmin.ExportedPackage; //导入依赖的package包/类
/**
 * Load the Class of name <code>klassName</code>.
 * TODO : handle class version
 *
 * @param context   The BundleContext
 * @param klassName The Class name
 * @return The Class of name <code>klassName</code>
 * @throws ClassNotFoundException if we can't load the Class of name <code>klassName</code>
 */
public static Class<?> loadClass(BundleContext context, String klassName) throws ClassNotFoundException {
    ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
    try {
        PackageAdmin padmin = (PackageAdmin) context.getService(sref);
        // extract package name
        String packageName = klassName.substring(0, klassName.lastIndexOf('.'));
        ExportedPackage pkg = padmin.getExportedPackage(packageName);
        if (pkg == null) {
            try {
                return context.getBundle().loadClass(klassName);
            } catch (ClassNotFoundException e) {
                throw new ClassNotFoundException("No package found with name " + packageName + " while trying to load the class "
                        + klassName + ".", e);
            }
        }
        return pkg.getExportingBundle().loadClass(klassName);
    } finally {
        context.ungetService(sref);
    }
}
 
开发者ID:ow2-chameleon,项目名称:fuchsia,代码行数:30,代码来源:FuchsiaUtils.java

示例6: addImportedBundle

import org.osgi.service.packageadmin.ExportedPackage; //导入依赖的package包/类
/**
 * Adds the imported bundle to the map of packages.
 * 
 * @param map
 * @param bundle
 * @param packageName
 */
private void addImportedBundle(Map<Bundle, List<String>> map, ExportedPackage expPackage) {
	Bundle bnd = expPackage.getExportingBundle();
	List<String> packages = map.get(bnd);
	if (packages == null) {
		packages = new ArrayList<String>(4);
		map.put(bnd, packages);
	}
	packages.add(new String(expPackage.getName()));
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:17,代码来源:PackageAdminResolver.java

示例7: addExportedPackages

import org.osgi.service.packageadmin.ExportedPackage; //导入依赖的package包/类
/**
 * Adds the bundle exporting the given packages which are then imported by
 * the owning bundle. This applies to special imports (such as
 * Require-Bundle).
 * 
 * @param map
 * @param bundle
 * @param pkgs
 */
private void addExportedPackages(Map<Bundle, List<String>> map, Bundle bundle, ExportedPackage[] pkgs) {
	List<String> packages = map.get(bundle);
	if (packages == null) {
		packages = new ArrayList<String>(pkgs.length);
		map.put(bundle, packages);
	}
	for (int i = 0; i < pkgs.length; i++) {
		packages.add(pkgs[i].getName());
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:20,代码来源:PackageAdminResolver.java

示例8: setUpExport

import org.osgi.service.packageadmin.ExportedPackage; //导入依赖的package包/类
private void setUpExport(ExportedPackage exportedPackage, Bundle exportingBundle, Bundle[] importingBundles,
                         String name, Version version) {
    when(exportedPackage.getExportingBundle()).thenReturn(exportingBundle);
    when(exportedPackage.getName()).thenReturn(name);
    when(exportedPackage.getImportingBundles()).thenReturn(importingBundles);
    when(exportedPackage.getVersion()).thenReturn(version);
}
 
开发者ID:motech,项目名称:motech,代码行数:8,代码来源:ImportExportResolverTest.java

示例9: getExportedPackages

import org.osgi.service.packageadmin.ExportedPackage; //导入依赖的package包/类
public String[] getExportedPackages(Bundle bundle) {
	ExportedPackage[] pkgs = pa.getExportedPackages(bundle);
	if (pkgs == null)
		return new String[0];

	List<String> packages = new ArrayList<String>(pkgs.length);
	for (ExportedPackage exportedPackage : pkgs) {
		packages.add(exportedPackage.getName() + ";version=" + exportedPackage.getVersion());
	}

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

示例10: 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()]);
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:29,代码来源:DefaultOsgiConsole.java

示例11: addImportedBundle

import org.osgi.service.packageadmin.ExportedPackage; //导入依赖的package包/类
/**
 * Adds the imported bundle to the map of packages.
 * 
 * @param map
 * @param bundle
 * @param packageName
 */
private void addImportedBundle(Map map, ExportedPackage expPackage) {
	Bundle bnd = expPackage.getExportingBundle();
	List packages = (List) map.get(bnd);
	if (packages == null) {
		packages = new ArrayList(4);
		map.put(bnd, packages);
	}
	packages.add(new String(expPackage.getName()));
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:17,代码来源:PackageAdminResolver.java

示例12: addExportedPackages

import org.osgi.service.packageadmin.ExportedPackage; //导入依赖的package包/类
/**
 * Adds the bundle exporting the given packages which are then imported by
 * the owning bundle. This applies to special imports (such as
 * Require-Bundle).
 * 
 * @param map
 * @param bundle
 * @param pkgs
 */
private void addExportedPackages(Map map, Bundle bundle, ExportedPackage[] pkgs) {
	List packages = (List) map.get(bundle);
	if (packages == null) {
		packages = new ArrayList(pkgs.length);
		map.put(bundle, packages);
	}
	for (int i = 0; i < pkgs.length; i++) {
		packages.add(pkgs[i].getName());
	}
}
 
开发者ID:BeamFoundry,项目名称:spring-osgi,代码行数:20,代码来源:PackageAdminResolver.java

示例13: loadClasses

import org.osgi.service.packageadmin.ExportedPackage; //导入依赖的package包/类
/**
 * Load the Classes of names <code>klassNames</code>.
 * TODO : handle class version
 *
 * @param context    The BundleContext
 * @param klassNames The Classes names
 * @return The Classes of names <code>klassNames</code>
 * @throws ClassNotFoundException if we can't load one Class name of the list <code>klassNames</code>
 */
public static List<Class<?>> loadClasses(BundleContext context, List<String> klassNames) throws ClassNotFoundException {
    ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
    List<Class<?>> klass = new ArrayList<Class<?>>(klassNames.size());

    if (sref == null) {
        // no package admin !
        return klass;
    }
    try {
        PackageAdmin padmin = (PackageAdmin) context.getService(sref);
        for (String klassName : klassNames) {
            // extract package name
            String packageName = klassName.substring(0, klassName.lastIndexOf('.'));

            ExportedPackage pkg = padmin.getExportedPackage(packageName);
            if (pkg == null) {
                throw new ClassNotFoundException("No package found with name " + packageName + " while trying to load the class "
                        + klassName + ".");
            }
            klass.add(pkg.getExportingBundle().loadClass(klassName));
        }
        return klass;
    } finally {
        context.ungetService(sref);
    }
}
 
开发者ID:ow2-chameleon,项目名称:fuchsia,代码行数:36,代码来源:FuchsiaUtils.java

示例14: 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()]);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:71,代码来源:PackageAdminResolver.java

示例15: getVersion

import org.osgi.service.packageadmin.ExportedPackage; //导入依赖的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.ExportedPackage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。