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


Java BundleContext.getBundles方法代码示例

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


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

示例1: initNamespaceHandlers

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
protected void initNamespaceHandlers(BundleContext extenderBundleContext) {
    nsManager = new NamespaceManager(extenderBundleContext);

    // register listener first to make sure any bundles in INSTALLED state
    // are not lost

    // if the property is defined and true, consider bundles in STARTED/LAZY-INIT state, otherwise use RESOLVED
    boolean nsResolved = !Boolean.getBoolean("org.eclipse.gemini.blueprint.ns.bundles.started");
    nsListener = new NamespaceBundleLister(nsResolved, this);
    extenderBundleContext.addBundleListener(nsListener);

    Bundle[] previousBundles = extenderBundleContext.getBundles();

    for (Bundle bundle : previousBundles) {
        // special handling for uber bundle being restarted
        if ((nsResolved && OsgiBundleUtils.isBundleResolved(bundle)) || (!nsResolved && OsgiBundleUtils.isBundleActive(bundle)) || bundleId == bundle.getBundleId()) {
            maybeAddNamespaceHandlerFor(bundle, false);
        } else if (OsgiBundleUtils.isBundleLazyActivated(bundle)) {
            maybeAddNamespaceHandlerFor(bundle, true);
        }
    }

    // discovery finished, publish the resolvers/parsers in the OSGi space
    nsManager.afterPropertiesSet();
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:26,代码来源:NamespaceHandlerActivator.java

示例2: findBundle

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
private static long findBundle(BundleContext context, String namePattern) {
	Bundle[] installedBundles = context.getBundles();
	for (int i = 0; i < installedBundles.length; i++) {
		Bundle bundle = installedBundles[i];
		if (bundle.getSymbolicName().matches(namePattern)) {
			return bundle.getBundleId();
		}
	}
	throw new RuntimeException("Cannot locate bundle with name pattern " + namePattern);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:11,代码来源:ProductLauncher.java

示例3: preLaodedBundlesNamePtterns

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
private static Set<String> preLaodedBundlesNamePtterns(BundleContext context) {
	Set<String> installedBundleDescriptions = new HashSet<>();
	Bundle[] installed0 = context.getBundles();
	for (int i = 0; i < installed0.length; i++) {
		String descriptor = installed0[i].getSymbolicName() + ".*";
		installedBundleDescriptions.add(descriptor);
	}
	return installedBundleDescriptions;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:10,代码来源:ProductLauncher.java

示例4: start

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
@Override
public void start(BundleContext ctx) {
    LOG.debug("Starting EclipseLink adapter");
    context = ctx;
    ctx.addBundleListener(this);
    
    for (Bundle b : ctx.getBundles()) {
        if ((b.getState() & (Bundle.ACTIVE | Bundle.STARTING | Bundle.RESOLVED | Bundle.STOPPING)) != 0) 
            handlePotentialEclipseLink(b);
    }
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:12,代码来源:Activator.java

示例5: loadClass

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
public static Class<?> loadClass ( final BundleContext ctx, final IConfigurationElement ele, final String attribute )
{
    final String clazzName = ele.getAttribute ( attribute );
    if ( clazzName == null || clazzName.isEmpty () )
    {
        return null;
    }

    final String bundleName = ele.getContributor ().getName ();

    logger.debug ( "Locating classs {} from {}", clazzName, bundleName );

    for ( final Bundle bundle : ctx.getBundles () )
    {
        if ( bundle.getSymbolicName ().equals ( bundleName ) )
        {
            try
            {
                return bundle.loadClass ( clazzName );
            }
            catch ( final ClassNotFoundException e )
            {
                // we give other bundles a chance
            }
        }
    }

    return null;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:30,代码来源:Factories.java

示例6: findBundle

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
private Class<?> findBundle ( final String symbolicName, final String clazzName )
{
    logger.debug ( "Find bundle with class - symbolicName: {}, className: {}", symbolicName, clazzName );

    final BundleContext context = FrameworkUtil.getBundle ( DefaultExecutableFactory.class ).getBundleContext ();

    for ( final Bundle bundle : context.getBundles () )
    {
        if ( !symbolicName.equals ( bundle.getSymbolicName () ) )
        {
            continue;
        }

        logger.debug ( "Checking bundle: {}", bundle.getSymbolicName () );

        Class<?> clazz;
        try
        {
            clazz = bundle.loadClass ( clazzName );
        }
        catch ( final ClassNotFoundException e )
        {
            logger.debug ( "Class could not be loaded", e );
            // we continue, since we might have multiple versions
            continue;
        }

        logger.debug ( "Success" );
        return clazz;
    }

    return null;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:34,代码来源:DefaultExecutableFactory.java

示例7: getBundle

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
private Bundle getBundle(String bundleName) {

		BundleContext bcontext = ServiceHolder.getContext();
		if (bcontext==null)    return null;
		if (bundleName==null) return null;
		Bundle[] bundles = bcontext.getBundles();
		for (Bundle bundle : bundles) {
			if (bundleName.equals(bundle.getSymbolicName())) {
				return bundle;
			}
		}
		return getOSGiBundle(bundleName, bcontext);
	}
 
开发者ID:eclipse,项目名称:scanning,代码行数:14,代码来源:TypeEditor.java

示例8: getBundle

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
private Bundle getBundle(String bundleName) {
	if (context==null)    return null;
	if (bundleName==null) return null;
	BundleContext bcontext = context.getBundleContext();
	Bundle[] bundles = bcontext.getBundles();
	for (Bundle bundle : bundles) {
		if (bundleName.equals(bundle.getSymbolicName())) {
			return bundle;
		}
	}
	return getOSGiBundle(bundleName);
}
 
开发者ID:eclipse,项目名称:scanning,代码行数:13,代码来源:PseudoSpringParser.java

示例9: findBundleBySymbolicName

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
/**
 * Finds an install bundle based by its symbolic name.
 * 
 * @param bundleContext OSGi bundle context
 * @param symbolicName bundle symbolic name
 * @return bundle matching the symbolic name (<code>null</code> if none is
 *         found)
 */
public static Bundle findBundleBySymbolicName(BundleContext bundleContext, String symbolicName) {
	Assert.notNull(bundleContext, "bundleContext is required");
	Assert.hasText(symbolicName, "a not-null/not-empty symbolicName isrequired");

	Bundle[] bundles = bundleContext.getBundles();
	for (int i = 0; i < bundles.length; i++) {
		if (symbolicName.equals(bundles[i].getSymbolicName())) {
			return bundles[i];
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:21,代码来源:OsgiBundleUtils.java

示例10: postProcessBundleContext

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
protected void postProcessBundleContext(BundleContext platformBundleContext) throws Exception {
	if (shouldWaitForSpringBundlesContextCreation()) {
		boolean debug = logger.isDebugEnabled();
		boolean trace = logger.isTraceEnabled();
		if (debug) {
			logger.debug("Looking for Spring/OSGi powered bundles to wait for...");
           }

		// determine Spring/OSGi bundles
		Bundle[] bundles = platformBundleContext.getBundles();
           for (Bundle bundle : bundles) {
               String bundleName = OsgiStringUtils.nullSafeSymbolicName(bundle);
               if (OsgiBundleUtils.isBundleActive(bundle)) {
                   if (isSpringDMManaged(bundle) && ConfigUtils.getPublishContext(bundle.getHeaders())) {
                       if (debug) {
                           logger.debug("Bundle [" + bundleName + "] triggers a context creation; waiting for it");
                       }
                       // use platformBundleContext
                       waitOnContextCreation(platformBundleContext, bundleName, getDefaultWaitTime());
                   } else if (trace) {
                       logger.trace("Bundle [" + bundleName + "] does not trigger a context creation.");
                   }
               } else {
                   if (trace) {
                       logger.trace("Bundle [" + bundleName + "] is not active (probably a fragment); ignoring");
                   }
               }
           }
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:31,代码来源:AbstractSynchronizedOsgiTests.java

示例11: testActivation

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
public void testActivation() throws Exception {
    ModuleSystem ms = Main.getModuleSystem();
    mgr = ms.getManager();
    mgr.mutexPrivileged().enterWriteAccess();
    Enumeration en;
    int checks = 0;
    
    System.setProperty("activated.checkentries", "/org/test/x.txt");
    try {
        m1 = mgr.create(simpleModule, null, false, false, false);
        mgr.enable(m1);

        Class<?> main = m1.getClassLoader().loadClass("org.activate.Main");
        Object s = main.getField("start").get(null);
        assertNotNull("Bundle started, its context provided", s);

        BundleContext bc = (BundleContext)s;
        StringBuilder sb = new StringBuilder();
        for (Bundle b : bc.getBundles()) {
            URL root = b.getEntry("/");
            if (root == null) {
                sb.append("No root URL for ").append(b.getSymbolicName()).append("\n");
            }
            
            en = b.findEntries("/", null, true);
            if (en == null) {
                sb.append("No entries for ").append(b.getSymbolicName()).append("\n");
                continue;
            }
            while (en.hasMoreElements()) {
                URL u = (URL) en.nextElement();
                final String ef = u.toExternalForm();
                int pref = ef.indexOf("/org/");
                int last = ef.lastIndexOf("/");
                if (pref != -1 && last != -1) {
                    String entry = ef.substring(pref + 1, last + 1);
                    assertTrue("/ is at the end", entry.endsWith("/"));
                    checks++;
                    final URL found = b.getEntry(entry);
                    assertNotNull("Entry found " + entry + " in " + b.getSymbolicName(), found);
                    
                    URL notFound = b.getEntry("non/existent/entry/");
                    assertNull("Entries for non-existing entries are not found", notFound);
                }
            }
        }
        if (sb.length() > 0) {
            fail(sb.toString());
        }
        if (checks == 0) {
            fail("There shall be some checks for entries");
        }
        String text = System.getProperty("activated.entry");
        assertEquals("Ahoj", text);

        String localURL = System.getProperty("activated.entry.local");
        assertNotNull("bundleentry read OK", localURL);
        assertTrue("external file is referred as file:/.... = " + localURL, localURL.startsWith("file:/"));
        assertEquals("Ahoj", readLine(localURL));

        String fileURL = System.getProperty("activated.entry.file");
        assertNotNull("fileURL found", fileURL);
        assertTrue("file:/..... = " + fileURL, fileURL.startsWith("file:/"));
        assertEquals("Ahoj", readLine(fileURL));

        mgr.disable(m1);

        Object e = main.getField("stop").get(null);
        assertNotNull("Bundle stopped, its context provided", e);
    } finally {
        mgr.mutexPrivileged().exitWriteAccess();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:74,代码来源:ExternalDirectoryTest.java

示例12: getBundles

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
/**
 * Returns all bundles that are currently loaded.
 * @return the bundle array
 */
public Bundle[] getBundles() {
	BundleContext bc = this.getBundleContext(); 
	if (bc==null) return null;
	return bc.getBundles();
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:10,代码来源:BundleEvaluator.java

示例13: debugClassLoading

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
/**
 * Tries (through a best-guess attempt) to figure out why a given class
 * could not be found. This method will search the given bundle and its
 * classpath to determine the reason for which the class cannot be loaded.
 * 
 * <p/> This method tries to be effective especially when the dealing with
 * {@link NoClassDefFoundError} caused by failure of loading transitive
 * classes (such as getting a NCDFE when loading <code>foo.A</code>
 * because <code>bar.B</code> cannot be found).
 * 
 * @param bundle the bundle to search for (and which should do the loading)
 * @param className the name of the class that failed to be loaded in dot
 * format (i.e. java.lang.Thread)
 * @param rootClassName the name of the class that triggered the loading
 * (i.e. java.lang.Runnable)
 */
public static void debugClassLoading(Bundle bundle, String className, String rootClassName) {
	boolean trace = log.isTraceEnabled();
	if (!trace)
		return;

	Dictionary dict = bundle.getHeaders();
	String bname = dict.get(Constants.BUNDLE_NAME) + "(" + dict.get(Constants.BUNDLE_SYMBOLICNAME) + ")";
	if (trace)
		log.trace("Could not find class [" + className + "] required by [" + bname + "] scanning available bundles");

	BundleContext context = OsgiBundleUtils.getBundleContext(bundle);
	int pkgIndex = className.lastIndexOf('.');
	// Reject global packages
	if (pkgIndex < 0) {
		if (trace)
			log.trace("Class is not in a package, its unlikely that this will work");
		return;
	}
	
	String packageName = className.substring(0, pkgIndex);

	Version iversion = hasImport(bundle, packageName);
	if (iversion != null && context != null) {
		if (trace)
			log.trace("Class is correctly imported as version [" + iversion + "], checking providing bundles");
		Bundle[] bundles = context.getBundles();
		for (int i = 0; i < bundles.length; i++) {
			if (bundles[i].getBundleId() != bundle.getBundleId()) {
				Version exported = checkBundleForClass(bundles[i], className, iversion);
				// Everything looks ok, but is the root bundle importing the
				// dependent class also?
				if (exported != null && exported.equals(iversion) && rootClassName != null) {
					for (int j = 0; j < bundles.length; j++) {
						Version rootexport = hasExport(bundles[j], rootClassName.substring(0,
							rootClassName.lastIndexOf('.')));
						if (rootexport != null) {
							// TODO -- this is very rough, check the bundle
							// classpath also.
							Version rootimport = hasImport(bundles[j], packageName);
							if (rootimport == null || !rootimport.equals(iversion)) {
								if (trace)
									log.trace("Bundle [" + OsgiStringUtils.nullSafeNameAndSymName(bundles[j])
											+ "] exports [" + rootClassName + "] as version [" + rootexport
											+ "] but does not import dependent package [" + packageName
											+ "] at version [" + iversion + "]");
							}
						}
					}
				}
			}
		}
	}
	if (hasExport(bundle, packageName) != null) {
		if (trace)
			log.trace("Class is exported, checking this bundle");
		checkBundleForClass(bundle, className, iversion);
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:75,代码来源:DebugUtils.java


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