Package org.osgi.framework

Examples of org.osgi.framework.BundleContext


  /**
   * Get a list with all bundles on the target BC.
   */
  public static Bundle[] getTargetBC_getBundles()
  {
    final BundleContext tbc = getTargetBC();
    if(null != tbc) {
      return tbc.getBundles();
    }
    return null;
  }
View Full Code Here


  /**
   * Get a specific bundle on the target BC.
   */
  public static Bundle getTargetBC_getBundle(final long bid)
  {
    final BundleContext tbc = getTargetBC();
    if(null != tbc) {
      return tbc.getBundle(bid);
    }
    return null;
  }
View Full Code Here

  /**
   * Get a property value from the target BC.
   */
  public static String getTargetBC_getProperty(final String key)
  {
    final BundleContext tbc = getTargetBC();
    if(null != tbc) {
      return tbc.getProperty(key);
    }
    return null;
  }
View Full Code Here

      for(int i = 0; i < names.length; i++) {
        System.out.println(" " + names[i]);
       
      }
      */
      BundleContext regBC = sr.getBundle().getBundleContext();
      reg = regBC.registerService(Object.class.getName(), dispatcher, props);
    } else {
      // System.out.println("no names in " + cg);
    }
  }
View Full Code Here

            if (function instanceof CommandProxy) {
                Field contextField = function.getClass().getDeclaredField("context");
                Field referenceField = function.getClass().getDeclaredField("reference");
                contextField.setAccessible(true);
                referenceField.setAccessible(true);
                BundleContext context = (BundleContext) contextField.get(function);
                ServiceReference reference = (ServiceReference) referenceField.get(function);
                Object target = context.getService(reference);
                try {
                    if (target instanceof Function) {
                        function = (Function) target;
                    }
                } finally {
                    context.ungetService(reference);
                }
            }
        } catch (Throwable t) {
        }
        return function;
View Full Code Here

    private ListBundleServices listServices;

    @SuppressWarnings("unchecked")
    public ListServicesTest() {
        listServices = new ListBundleServices();
        BundleContext bundleContext = new TestBundleFactory().createBundleContext();
        listServices.setBundleContext(bundleContext);
        listServices.setBundleService(new BundleServiceImpl(bundleContext, Collections.EMPTY_LIST));
    }
View Full Code Here

            expect(ref.getBundle()).andReturn(bundle);
        }
    }

    public BundleContext createBundleContext() {
        BundleContext bundleContext = createMock(BundleContext.class);
        Bundle[] bundles = createBundles();
        expect(bundleContext.getBundles()).andReturn(bundles).anyTimes();
        expect(bundleContext.getBundle(0)).andReturn(null).anyTimes();
        expect(bundleContext.getBundle(1)).andReturn(bundles[0]).anyTimes();
        expect(bundleContext.getBundle(2)).andReturn(bundles[1]).anyTimes();
        replay(bundleContext);
        return bundleContext;
    }
View Full Code Here

            lock.release();
        }
    }

    protected void setStartLevel(int level) throws Exception {
        BundleContext ctx = framework.getBundleContext();
        ServiceReference[] refs = ctx.getServiceReferences(StartLevel.class.getName(), null);
        StartLevel sl = (StartLevel) ctx.getService(refs[0]);
        sl.setStartLevel(level);
    }
View Full Code Here

    public void run(IProgressMonitor monitor) {
        MultiStatus status = new MultiStatus(Plugin.PLUGIN_ID, 0, Messages.ResolveOperation_errorOverview, null);

        // Start a coordination
        BundleContext bc = Plugin.getDefault().getBundleContext();
        ServiceReference coordSvcRef = bc.getServiceReference(Coordinator.class.getName());
        Coordinator coordinator = coordSvcRef != null ? (Coordinator) bc.getService(coordSvcRef) : null;
        Coordination coordination = coordinator != null ? coordinator.begin(ResolveOperation.class.getName(), 0) : null;

        // Begin resolve
        ResolveProcess resolve = new ResolveProcess();
        ResolverLogger logger = new ResolverLogger();
        try {
            ResolverImpl felixResolver = new ResolverImpl(logger);

            ReporterLogService log = new ReporterLogService(Central.getWorkspace());
            Map<Resource,List<Wire>> wirings = resolve.resolveRequired(model, Central.getWorkspace(), felixResolver, callbacks, log);
            result = new ResolutionResult(Outcome.Resolved, wirings, null, status, logger.getLog());
            if (coordination != null)
                coordination.end();
        } catch (ResolveCancelledException e) {
            result = new ResolutionResult(Outcome.Cancelled, null, null, status, logger.getLog());

            if (coordination != null)
                coordination.fail(e);
        } catch (ResolutionException e) {
            status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, e.getLocalizedMessage(), e));
            result = new ResolutionResult(Outcome.Unresolved, null, null, status, logger.getLog());

            if (coordination != null)
                coordination.fail(e);
        } catch (Exception e) {
            status.add(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Exception during resolution.", e));
            result = new ResolutionResult(Outcome.Error, null, null, status, logger.getLog());

            if (coordination != null)
                coordination.fail(e);
        } finally {
            if (coordinator != null)
                bc.ungetService(coordSvcRef);
        }
    }
View Full Code Here

            } catch (Exception e) {
                logger.logError("Unable to instantiate build listener: " + elem.getAttribute("name"), e);
            }
        }

        BundleContext context = FrameworkUtil.getBundle(BuildListeners.class).getBundleContext();

        listenerTracker = new ServiceTracker<BuildListener,BuildListener>(context, BuildListener.class, null);
        listenerTracker.open();
    }
View Full Code Here

TOP

Related Classes of org.osgi.framework.BundleContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.