本文整理汇总了Java中org.osgi.framework.Bundle类的典型用法代码示例。如果您正苦于以下问题:Java Bundle类的具体用法?Java Bundle怎么用?Java Bundle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Bundle类属于org.osgi.framework包,在下文中一共展示了Bundle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startDependencyAsynch
import org.osgi.framework.Bundle; //导入依赖的package包/类
private void startDependencyAsynch(final Bundle bundle) {
System.out.println("starting dependency test bundle");
Runnable runnable = new Runnable() {
public void run() {
try {
bundle.start();
System.out.println("started dependency test bundle");
}
catch (BundleException ex) {
System.err.println("can't start bundle " + ex);
}
}
};
Thread thread = new Thread(runnable);
thread.setDaemon(false);
thread.setName("dependency test bundle");
thread.start();
}
示例2: getPlatformName
import org.osgi.framework.Bundle; //导入依赖的package包/类
public static String getPlatformName(BundleContext bundleContext) {
String vendorProperty = bundleContext.getProperty(Constants.FRAMEWORK_VENDOR);
String frameworkVersion = bundleContext.getProperty(Constants.FRAMEWORK_VERSION);
// get system bundle
Bundle bundle = bundleContext.getBundle(0);
String name = (String) bundle.getHeaders().get(Constants.BUNDLE_NAME);
String version = (String) bundle.getHeaders().get(Constants.BUNDLE_VERSION);
String symName = bundle.getSymbolicName();
StringBuilder buf = new StringBuilder();
buf.append(name);
buf.append(" ");
buf.append(symName);
buf.append("|");
buf.append(version);
buf.append("{");
buf.append(frameworkVersion);
buf.append(" ");
buf.append(vendorProperty);
buf.append("}");
return buf.toString();
}
示例3: installBundleFromApk
import org.osgi.framework.Bundle; //导入依赖的package包/类
private Bundle installBundleFromApk(String bundleName) throws Exception{
Bundle bundle = null;
findBundleSource(bundleName);
if(mTmpBundleSourceFile!=null){
bundle = Framework.installNewBundle(bundleName,mTmpBundleSourceFile);
}else if(mTmpBundleSourceInputStream!=null){
bundle = Framework.installNewBundle(bundleName,mTmpBundleSourceInputStream);
}else{
IOException e = new IOException("can not find bundle source file");
Map<String, Object> detail = new HashMap<>();
detail.put("installBundleFromApk",bundleName);
AtlasMonitor.getInstance().report(AtlasMonitor.CONTAINER_BUNDLE_SOURCE_MISMATCH, detail, e);
throw e;
}
return bundle;
}
示例4: getDataAsObject
import org.osgi.framework.Bundle; //导入依赖的package包/类
public Object getDataAsObject ( final Bundle bundle, final Object defaultValue )
{
try
{
final Object result = getDataAsObject ( bundle );
if ( result == null )
{
return defaultValue;
}
else
{
return result;
}
}
catch ( final Exception e )
{
return defaultValue;
}
}
示例5: getIcon
import org.osgi.framework.Bundle; //导入依赖的package包/类
protected Image getIcon(String fullPath) throws IOException {
if (fullPath==null) return defaultIcon;
if ("".equals(fullPath)) return defaultIcon;
try {
if (iconMap.containsKey(fullPath)) return iconMap.get(fullPath);
final String[] sa = fullPath.split("/");
final Bundle bundle = Platform.getBundle(sa[0]);
if (bundle==null) return defaultIcon;
if (bundle!=null) {
Image image = new Image(null, bundle.getResource(sa[1]+"/"+sa[2]).openStream());
iconMap.put(fullPath, image);
}
return iconMap.get(fullPath);
} catch (Exception ne) {
logger.debug("Cannot get icon for "+fullPath, ne);
return defaultIcon;
}
}
示例6: testInstallBundle
import org.osgi.framework.Bundle; //导入依赖的package包/类
@Test
public void testInstallBundle() throws Exception {
final String installCommand ="bundle:install mvn:"
+ OSGIFX_GROUP_ID + "/"
+ IT_DUMMY_BUNDLE_ARTIFACT_ID + "/"
+ PROJECT_VERSION;
session.execute(installCommand);
Bundle dummyBundle = null;
for (Bundle bundle : bundleContext.getBundles())
{
if (bundle.getSymbolicName() != null && bundle.getSymbolicName().equals(OSGIFX_GROUP_ID + "." + IT_DUMMY_BUNDLE_ARTIFACT_ID))
{
dummyBundle = bundle;
break;
}
}
assertNotNull(dummyBundle);
}
示例7: testInvocationWhenServiceNA
import org.osgi.framework.Bundle; //导入依赖的package包/类
public void testInvocationWhenServiceNA() throws Throwable {
// service n/a
ServiceReference reference = new MockServiceReference() {
public Bundle getBundle() {
return null;
}
};
interceptor = new ServiceStaticInterceptor(new MockBundleContext(), reference);
Object target = new Object();
Method m = target.getClass().getDeclaredMethod("hashCode", null);
MethodInvocation invocation = new MockMethodInvocation(m);
try {
interceptor.invoke(invocation);
fail("should have thrown exception");
}
catch (ServiceUnavailableException ex) {
// expected
}
}
示例8: findBundle
import org.osgi.framework.Bundle; //导入依赖的package包/类
private Bundle findBundle ( final String symbolicName )
{
final Bundle[] bundles = this.context.getBundles ();
if ( bundles == null )
{
return null;
}
for ( final Bundle bundle : bundles )
{
if ( bundle.getSymbolicName ().equals ( symbolicName ) )
{
return bundle;
}
}
return null;
}
示例9: isFullyStarted
import org.osgi.framework.Bundle; //导入依赖的package包/类
private boolean isFullyStarted(Bundle bundle) {
Component[] components = scrService.getComponents(bundle);
if (components != null) {
for (Component component : components) {
if (!isFullyStarted(component)) {
return false;
}
}
}
return true;
}
示例10: ungetService
import org.osgi.framework.Bundle; //导入依赖的package包/类
/**
* Called if a bundle releases the service (stop the scope).
*
* @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle,
* org.osgi.framework.ServiceRegistration, java.lang.Object)
*/
public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) {
try {
// tell the scope, it's an outside bundle that does the call
EXTERNAL_BUNDLE.set(Boolean.TRUE);
// unget object first
decoratedServiceFactory.ungetService(bundle, registration, service);
// then apply the destruction callback (if any)
Runnable callback = callbacks.remove(bundle);
if (callback != null)
callback.run();
}
finally {
// clean ThreadLocal
EXTERNAL_BUNDLE.set(null);
}
}
示例11: notifyFrameworkListeners
import org.osgi.framework.Bundle; //导入依赖的package包/类
/**
* notify all framework listeners.
*
* @param state the new state.
* @param bundle the bundle.
* @param throwable a throwable.
*/
static void notifyFrameworkListeners(final int state, final Bundle bundle, final Throwable throwable) {
if (frameworkListeners.isEmpty()) {
return;
}
final FrameworkEvent event = new FrameworkEvent(state);
final FrameworkListener[] listeners = frameworkListeners.toArray(new FrameworkListener[frameworkListeners.size()]);
for (int i = 0; i < listeners.length; i++) {
final FrameworkListener listener = listeners[i];
listener.frameworkEvent(event);
}
}
示例12: createIcons
import org.osgi.framework.Bundle; //导入依赖的package包/类
private void createIcons() {
icons = new HashMap<String, Image>(7);
final IConfigurationElement[] eles = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.scanning.api.generator");
for (IConfigurationElement e : eles) {
final String identity = e.getAttribute("id");
final String icon = e.getAttribute("icon");
if (icon !=null) {
final String cont = e.getContributor().getName();
final Bundle bundle= Platform.getBundle(cont);
final URL entry = bundle.getEntry(icon);
final ImageDescriptor des = ImageDescriptor.createFromURL(entry);
icons.put(identity, des.createImage());
}
}
}
示例13: testUnmanagedBundlesAreIgnoredForShutdownOrdering
import org.osgi.framework.Bundle; //导入依赖的package包/类
/**
* If the service of a managed bundle are consumed by an unmanaged bundle,
* that dependency should not affect the shutdown ordering as gemini blueprint is only responsible for
* orderly shutting down the bundles it is managing.
*/
public void testUnmanagedBundlesAreIgnoredForShutdownOrdering() throws Exception {
DependencyMockBundle a = new DependencyMockBundle("A");
DependencyMockBundle b = new DependencyMockBundle("B");
DependencyMockBundle c = new DependencyMockBundle("C");
DependencyMockBundle d = new DependencyMockBundle("D");
DependencyMockBundle e = new DependencyMockBundle("E");
DependencyMockBundle unmanaged = new DependencyMockBundle("F");
b.setDependentOn(c);
d.setDependentOn(e, -13, 12);
e.setDependentOn(d, 0, 14);
a.setDependentOn(unmanaged);
List<Bundle> order = getOrder(a, b, c, d, e);
assertOrder(order, c, a, b, d, e);
}
示例14: createApplicationContext
import org.osgi.framework.Bundle; //导入依赖的package包/类
public DelegatedExecutionOsgiBundleApplicationContext createApplicationContext(BundleContext bundleContext)
throws Exception {
Bundle bundle = bundleContext.getBundle();
ApplicationContextConfiguration config = new BlueprintContainerConfig(bundle);
String bundleName = OsgiStringUtils.nullSafeNameAndSymName(bundle);
if (log.isTraceEnabled())
log.trace("Created configuration " + config + " for bundle " + bundleName);
// it's not a spring bundle, ignore it
if (!config.isSpringPoweredBundle()) {
if (log.isDebugEnabled())
log.debug("No blueprint configuration found in bundle " + bundleName + "; ignoring it...");
return null;
}
log.info("Discovered configurations " + ObjectUtils.nullSafeToString(config.getConfigurationLocations())
+ " in bundle [" + bundleName + "]");
DelegatedExecutionOsgiBundleApplicationContext sdoac =
new OsgiBundleXmlApplicationContext(config.getConfigurationLocations());
sdoac.setBundleContext(bundleContext);
sdoac.setPublishContextAsService(config.isPublishContextAsService());
return sdoac;
}
示例15: getMelangeBundle
import org.osgi.framework.Bundle; //导入依赖的package包/类
/**
* Return a bundle with a .melange declaring 'language'
*/
public static Bundle getMelangeBundle(String languageName){
IConfigurationElement[] melangeLanguages = Platform
.getExtensionRegistry().getConfigurationElementsFor(
"fr.inria.diverse.melange.language");
String melangeBundleName = "";
for (IConfigurationElement lang : melangeLanguages) {
if(lang.getAttribute("id").equals(languageName)){
melangeBundleName = lang.getContributor().getName();
return Platform.getBundle(melangeBundleName);
}
}
return null;
}