當前位置: 首頁>>代碼示例>>Java>>正文


Java Bundle.getHeaders方法代碼示例

本文整理匯總了Java中org.osgi.framework.Bundle.getHeaders方法的典型用法代碼示例。如果您正苦於以下問題:Java Bundle.getHeaders方法的具體用法?Java Bundle.getHeaders怎麽用?Java Bundle.getHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.osgi.framework.Bundle的用法示例。


在下文中一共展示了Bundle.getHeaders方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: bundleChanged

import org.osgi.framework.Bundle; //導入方法依賴的package包/類
public @Override void bundleChanged(BundleEvent event) {
        Bundle bundle = event.getBundle();
        switch (event.getType()) {
        case BundleEvent.STARTED:
//            System.err.println("started " + bundle.getSymbolicName());
            Dictionary<?,?> headers = bundle.getHeaders();
            load(queue.offer(bundle, provides(headers), requires(headers), needs(headers)));
            break;
        case BundleEvent.STOPPED:
//            System.err.println("stopped " + bundle.getSymbolicName());
            if (framework.getState() == Bundle.STOPPING) {
//                System.err.println("fwork stopping during " + bundle.getSymbolicName());
//                ActiveQueue.stop();
            } else {
                unload(queue.retract(bundle));
            }
            break;
        }
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:Activator.java

示例2: isBundleLazyActivated

import org.osgi.framework.Bundle; //導入方法依賴的package包/類
/**
 * Indicates if the given bundle is lazily activated or not. That is, the
 * bundle has a lazy activation policy and a STARTING state. Bundles that
 * have been lazily started but have been activated will return false.
 * 
 * <p/>
 * On OSGi R4.0 platforms, this method will always return false.
 * 
 * @param bundle OSGi bundle
 * @return true if the bundle is lazily activated, false otherwise.
 */
@SuppressWarnings("unchecked")
public static boolean isBundleLazyActivated(Bundle bundle) {
	Assert.notNull(bundle, "bundle is required");

	if (OsgiPlatformDetector.isR41()) {
		if (bundle.getState() == Bundle.STARTING) {
			Dictionary<String, String> headers = bundle.getHeaders();
			if (headers != null) {
				Object val = headers.get(Constants.BUNDLE_ACTIVATIONPOLICY);
				if (val != null) {
					String value = ((String) val).trim();
					return (value.startsWith(Constants.ACTIVATION_LAZY));
				}
			}
		}
	}
	return false;
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:30,代碼來源:OsgiBundleUtils.java

示例3: processLoadedBundles

import org.osgi.framework.Bundle; //導入方法依賴的package包/類
private void processLoadedBundles() {
        List<Bundle> toLoad = new ArrayList<Bundle>();
        for (Bundle b : context.getBundles()) {
            if (b.getState() == Bundle.ACTIVE) {
                Dictionary<?,?> headers = b.getHeaders();
                toLoad.addAll(queue.offer(b, provides(headers), requires(headers), needs(headers)));
            }
        }
//        System.err.println("processing already loaded bundles: " + toLoad);
        load(toLoad);
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:Activator.java

示例4: getPersistenceUnits

import org.osgi.framework.Bundle; //導入方法依賴的package包/類
/**
 * This method locates persistence descriptor files based on a combination of the default location
 * "META-INF/persistence.xml" and the Meta-Persistence header. Note that getEntry is used to ensure we do
 * not alter the state of the bundle Note also that web application bundles will never return persistence
 * descriptors
 * 
 * @param bundle The bundle to search
 * @return persistence units located in the bundle
 */
public static Collection<PersistenceUnit> getPersistenceUnits(Bundle bundle) {
    Collection<PersistenceUnit> punits = new ArrayList<PersistenceUnit>();
    Dictionary<String, String> headers = bundle.getHeaders();
    String metaPersistence = headers.get(PERSISTENCE_UNIT_HEADER);

    Set<String> locations = new HashSet<String>();
    if (metaPersistence == null) {
        return punits;
    }

    if (!metaPersistence.isEmpty()) {
        // Split apart the header to get the individual entries
        for (String s : metaPersistence.split(",")) {
            locations.add(s.trim());
        }
    }
    
    if (!locations.contains(DEFAULT_PERSISTENCE_LOCATION)) {
        locations.add(DEFAULT_PERSISTENCE_LOCATION);
    }

    // Find the file and add it to our list
    for (String location : locations) {
        try {
            InputStream is = locateFile(bundle, location);
            if (is != null) {
                parse(bundle, is, punits);
            }
        } catch (Exception e) {
            LOG.error("exception.while.locating.descriptor", e);
            return Collections.emptySet();
        }
    }
    
    return punits;
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:46,代碼來源:PersistenceUnitParser.java

示例5: testFragment1Headers

import org.osgi.framework.Bundle; //導入方法依賴的package包/類
public void testFragment1Headers() throws Exception {
	Bundle fragment1 =
			OsgiBundleUtils.findBundleBySymbolicName(bundleContext, "org.eclipse.gemini.blueprint.iandt.io.fragment.1");
	Dictionary fragment1Headers = fragment1.getHeaders();
	assertNotNull(fragment1Headers.get("Fragment-Header"));
	assertNotNull(fragment1Headers.get("Fragment1-Header"));
	assertNull(fragment1Headers.get("Fragment2-Header"));
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:9,代碼來源:FragmentIoTests.java

示例6: testFragment2Headers

import org.osgi.framework.Bundle; //導入方法依賴的package包/類
public void testFragment2Headers() throws Exception {
	Bundle fragment1 =
			OsgiBundleUtils.findBundleBySymbolicName(bundleContext, "org.eclipse.gemini.blueprint.iandt.io.fragment.2");
	Dictionary fragment1Headers = fragment1.getHeaders();
	assertNotNull(fragment1Headers.get("Fragment-Header"));
	assertNull(fragment1Headers.get("Fragment1-Header"));
	assertNotNull(fragment1Headers.get("Fragment2-Header"));
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:9,代碼來源:FragmentIoTests.java

示例7: BlueprintContainerConfig

import org.osgi.framework.Bundle; //導入方法依賴的package包/類
public BlueprintContainerConfig(Bundle bundle) {
	super(bundle, new BlueprintConfigurationScanner());

	Dictionary headers = bundle.getHeaders();

	hasTimeout = BlueprintConfigUtils.hasTimeout(headers);
	long option = BlueprintConfigUtils.getTimeOut(headers);
	// no need to translate into ms
	timeout = (option >= 0 ? option : ConfigUtils.DIRECTIVE_TIMEOUT_DEFAULT * 1000);
	createAsync = BlueprintConfigUtils.getCreateAsync(headers);
	waitForDep = BlueprintConfigUtils.getWaitForDependencies(headers);
	publishContext = BlueprintConfigUtils.getPublishContext(headers);

	StringBuilder buf = new StringBuilder();
	buf.append("Blueprint Config [Bundle=");
	buf.append(OsgiStringUtils.nullSafeSymbolicName(bundle));
	buf.append("]isBlueprintBundle=");
	buf.append(isSpringPoweredBundle());
	buf.append("|async=");
	buf.append(createAsync);
	buf.append("|graceperiod=");
	buf.append(waitForDep);
	buf.append("|publishCtx=");
	buf.append(publishContext);
	buf.append("|timeout=");
	buf.append(timeout);
	buf.append("ms");
	toString = buf.toString();

	if (log.isTraceEnabled()) {
		log.trace("Configuration: " + toString);
	}
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:34,代碼來源:BlueprintContainerConfig.java

示例8: nullSafeSymbolicName

import org.osgi.framework.Bundle; //導入方法依賴的package包/類
/**
 * Returns the given <code>Bundle</code> symbolic name.
 * 
 * @param bundle OSGi bundle (can be <code>null</code>)
 * @return the bundle, symbolic name
 */
public static String nullSafeSymbolicName(Bundle bundle) {
	if (bundle == null)
		return NULL_STRING;

	Dictionary headers = bundle.getHeaders();

	if (headers == null)
		return NULL_STRING;

	return (String) (bundle.getSymbolicName() == null ? NULL_STRING : bundle.getSymbolicName());
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:18,代碼來源:OsgiStringUtils.java

示例9: nullSafeNameAndSymName

import org.osgi.framework.Bundle; //導入方法依賴的package包/類
/**
 * Returns the bundle name and symbolic name - useful when logging bundle info.
 * 
 * @param bundle OSGi bundle (can be null)
 * @return the bundle name and symbolic name
 */
public static String nullSafeNameAndSymName(Bundle bundle) {
	if (bundle == null)
		return NULL_STRING;

	Dictionary dict = bundle.getHeaders();

	if (dict == null)
		return NULL_STRING;

	StringBuilder buf = new StringBuilder();
	String name = (String) dict.get(org.osgi.framework.Constants.BUNDLE_NAME);
	if (name == null)
		buf.append(NULL_STRING);
	else
		buf.append(name);
	buf.append(" (");
	String sname = (String) dict.get(org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME);

	if (sname == null)
		buf.append(NULL_STRING);
	else
		buf.append(sname);

	buf.append(")");

	return buf.toString();
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:34,代碼來源:OsgiStringUtils.java

示例10: hasImport

import org.osgi.framework.Bundle; //導入方法依賴的package包/類
/**
 * Get the version of a package import from a bundle.
 * 
 * @param bundle
 * @param packageName
 * @return
 */
private static Version hasImport(Bundle bundle, String packageName) {
	Dictionary dict = bundle.getHeaders();
	// Check imports
	String imports = (String) dict.get(Constants.IMPORT_PACKAGE);
	Version v = getVersion(imports, packageName);
	if (v != null) {
		return v;
	}
	// Check for dynamic imports
	String dynimports = (String) dict.get(Constants.DYNAMICIMPORT_PACKAGE);
	if (dynimports != null) {
		for (StringTokenizer strok = new StringTokenizer(dynimports, COMMA); strok.hasMoreTokens();) {
			StringTokenizer parts = new StringTokenizer(strok.nextToken(), SEMI_COLON);
			String pkg = parts.nextToken().trim();
			if (pkg.endsWith(".*") && packageName.startsWith(pkg.substring(0, pkg.length() - 2)) || pkg.equals("*")) {
				Version version = Version.emptyVersion;
				for (; parts.hasMoreTokens();) {
					String modifier = parts.nextToken().trim();
					if (modifier.startsWith("version")) {
						version = Version.parseVersion(modifier.substring(modifier.indexOf(EQUALS) + 1).trim());
					}
				}
				return version;
			}
		}
	}
	return null;
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:36,代碼來源:DebugUtils.java

示例11: debugClassLoading

import org.osgi.framework.Bundle; //導入方法依賴的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

示例12: hasExport

import org.osgi.framework.Bundle; //導入方法依賴的package包/類
private static Version hasExport(Bundle bundle, String packageName) {
	Dictionary dict = bundle.getHeaders();
	return getVersion((String) dict.get(Constants.EXPORT_PACKAGE), packageName);
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:5,代碼來源:DebugUtils.java

示例13: nullSafeName

import org.osgi.framework.Bundle; //導入方法依賴的package包/類
/**
 * Returns the name of the given <code>Bundle</code> in a null-safe manner.
 * 
 * @param bundle OSGi bundle (can be <code>null</code>)
 * @return bundle name
 */
public static String nullSafeName(Bundle bundle) {
	if (bundle == null)
		return NULL_STRING;

	Dictionary headers = bundle.getHeaders();

	if (headers == null)
		return NULL_STRING;

	String name = (String) headers.get(org.osgi.framework.Constants.BUNDLE_NAME);

	return (name == null ? NULL_STRING : name);

}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:21,代碼來源:OsgiStringUtils.java


注:本文中的org.osgi.framework.Bundle.getHeaders方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。