本文整理匯總了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;
}