當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。