本文整理汇总了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;
}
}
示例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;
}
示例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);
}
示例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;
}
示例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"));
}
示例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"));
}
示例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);
}
}
示例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());
}
示例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();
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}