Java Code Examples for org.osgi.framework.BundleContext

The following examples show how to use org.osgi.framework.BundleContext. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void start(BundleContext context) throws Exception {

    _LOG.debug("Starting the Shiro JAX-RS Authorization Feature");

    _registration = coalesce(
            configuration("org.apache.aries.jax.rs.shiro.authorization"),
            just(() -> {

                _LOG.debug("Using the default configuration for the Shiro JAX-RS Authorization Feature");

                Dictionary<String, Object> properties =
                    new Hashtable<>();

                properties.put(
                    Constants.SERVICE_PID,
                    "org.apache.aries.jax.rs.shiro.authorization");

                return properties;
            })
    ).map(this::filter)
     .flatMap(p -> register(Feature.class, new ShiroAuthorizationFeature(), p))
     .run(context);
}
 
Example 2
public void activate(final BundleContext bundleContext, final Map<String, Object> config) {
    url = (String) config.get("url");
    logger.debug("MongoDB URL {}", url);
    if (StringUtils.isBlank(url)) {
        logger.warn(
                "The MongoDB database URL is missing - please configure the mongodb:url parameter in openhab.cfg");
    }
    db = (String) config.get("database");
    logger.debug("MongoDB database {}", db);
    if (StringUtils.isBlank(db)) {
        logger.warn(
                "The MongoDB database name is missing - please configure the mongodb:database parameter in openhab.cfg");
    }
    collection = (String) config.get("collection");
    logger.debug("MongoDB collection {}", collection);
    if (StringUtils.isBlank(collection)) {
        logger.warn(
                "The MongoDB database collection is missing - please configure the mongodb:collection parameter in openhab.cfg");
    }

    disconnectFromDatabase();
    connectToDatabase();

    // connection has been established ... initialization completed!
    initialized = true;
}
 
Example 3
Source Project: smarthome   Source File: DiscoveryServiceManager.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Registers all {@link SceneDiscoveryService}s and {@link DeviceDiscoveryService}s of this
 * {@link DiscoveryServiceManager} to the given {@link BundleContext}.
 *
 * @param bundleContext (must not be null)
 */
public void registerDiscoveryServices(BundleContext bundleContext) {
    if (discoveryServices != null) {
        for (AbstractDiscoveryService service : discoveryServices.values()) {
            if (service instanceof SceneDiscoveryService) {
                this.discoveryServiceRegs.put(bridgeUID + ((SceneDiscoveryService) service).getID(),
                        bundleContext.registerService(DiscoveryService.class.getName(), service,
                                new Hashtable<String, Object>()));
            }
            if (service instanceof DeviceDiscoveryService) {
                this.discoveryServiceRegs.put(bridgeUID + ((DeviceDiscoveryService) service).getID(),
                        bundleContext.registerService(DiscoveryService.class.getName(), service,
                                new Hashtable<String, Object>()));
            }
            if (service instanceof ZoneTemperatureControlDiscoveryService) {
                this.discoveryServiceRegs.put(
                        bridgeUID + ((ZoneTemperatureControlDiscoveryService) service).getID(),
                        bundleContext.registerService(DiscoveryService.class.getName(), service,
                                new Hashtable<String, Object>()));
            }
        }
    }
}
 
Example 4
@Override
protected Entry<EventPoolManager> createService ( final UserInformation userInformation, final String configurationId, final BundleContext context, final Map<String, String> parameters ) throws Exception
{
    logger.info ( "Creating event pool '{}'", configurationId );

    final ConfigurationDataHelper cfg = new ConfigurationDataHelper ( parameters );

    final String filter = parameters.get ( "filter" );
    final Integer size = cfg.getIntegerChecked ( "size", "Need 'size' parameter" );

    final EventPoolManager manager = new EventPoolManager ( context, configurationId, filter, size );
    return new Entry<EventPoolManager> ( configurationId, manager );
}
 
Example 5
Source Project: neoscada   Source File: HSDBItemController.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public HSDBItemController ( final String id, final ScheduledExecutorService executor, final BundleContext context, final HSDBValueSource source )
{
    this.source = source;

    final Map<String, Variant> properties = new HashMap<String, Variant> ();

    final HistoricalItemInformation information = new HistoricalItemInformation ( id, properties );
    this.item = new HSDBHistoricalItem ( executor, source, information );

    final Dictionary<String, Object> serviceProperties = new Hashtable<String, Object> ();
    serviceProperties.put ( Constants.SERVICE_PID, id );
    serviceProperties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
    this.handle = context.registerService ( HistoricalItem.class, this.item, serviceProperties );
}
 
Example 6
public void start(BundleContext bc) throws IOException
{
  ServiceReference sRef =
    bc.getServiceReference(UserService.class.getName());
  if (sRef != null) {
    UserService us = (UserService) bc.getService(sRef);
    if (us != null) {
      us.login("joek");
    }
    bc.ungetService(sRef);
  }
}
 
Example 7
Source Project: wisdom   Source File: InVivoRunner.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link InVivoRunner}.
 *
 * @param context the bundle context, used to retrieve services
 * @param clazz   the class.
 * @throws InitializationError if the class cannot be initialized, because for instance services cannot be found
 */
public InVivoRunner(BundleContext context, Class<?> clazz) throws InitializationError {
    super(clazz);
    // Set time factor.
    TimeUtils.TIME_FACTOR = Integer.getInteger("TIME_FACTOR", 1); //NOSONAR
    if (TimeUtils.TIME_FACTOR == 1) {
        TimeUtils.TIME_FACTOR = Integer.getInteger("time.factor", 1); //NOSONAR
    }
    this.helper = new OSGiHelper(context);
}
 
Example 8
Source Project: tmxeditor8   Source File: Activator.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void start(BundleContext context) throws Exception {
	super.start(context);
	plugin = this;

	DbServiceProviderImpl service = new DbServiceProviderImpl();
	oracleServiceRegistration = context.registerService(DBServiceProvider.class, service, null);
}
 
Example 9
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void stop ( final BundleContext context ) throws Exception
{
    this.configAdminTracker.close ();

    instance = null;
}
 
Example 10
Source Project: neoscada   Source File: ServiceImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public ServiceImpl ( final BundleContext context, final Executor executor ) throws InvalidSyntaxException
{
    super ( context, executor );

    this.context = context;
    this.monitorSubscriptions = new SubscriptionManager<String> ();
    this.eventSubscriptions = new SubscriptionManager<String> ();

    // create akn handler
    this.aknTracker = new ServiceTracker<AknHandler, AknHandler> ( context, AknHandler.class, null );
}
 
Example 11
Source Project: ContentAssist   Source File: Activator.java    License: MIT License 5 votes vote down vote up
/**
 * Performs actions when when the plug-in is shut down.
 * @param context the bundle context for this plug-in
 * @throws Exception if this this plug-in fails to stop
 */
@Override
public void stop(BundleContext context) throws Exception {
    Recorder.getInstance().stop();
    
    super.stop(context);
    
    plugin = null;
}
 
Example 12
Source Project: hana-native-adapters   Source File: Activator.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void start(BundleContext bundleContext) throws Exception {		
	
	PropertyConfigurator.configure("log4j.properties");
       logger.info("### BQAdapter start");
       
	Activator.context = bundleContext;

	BQAdapterFactory srv = new BQAdapterFactory();
	adapterRegistration = context.registerService(AdapterFactory.class.getName(),srv ,null);
}
 
Example 13
Source Project: neoscada   Source File: TestingMonitor.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public TestingMonitor ( final BundleContext context, final Executor executor, final EventProcessor eventProcessor, final String sourceName )
{
    super ( sourceName, executor, null, eventProcessor );
    this.scheduler.scheduleAtFixedRate ( new Runnable () {

        @Override
        public void run ()
        {
            TestingMonitor.this.tick ();
        }
    }, 1000, 1000, TimeUnit.MILLISECONDS );
}
 
Example 14
Source Project: attic-stratos   Source File: MenuAdminClient.java    License: Apache License 2.0 5 votes vote down vote up
private void setDefaultMenus(String loggedInUserName,
                             boolean isSuperTenant,
                             ArrayList<String> userPermission,
                             HttpServletRequest request) {
    BundleContext bundleContext = CarbonUIUtil.getBundleContext();
    if (bundleContext != null) {
        ServiceReference reference = bundleContext.getServiceReference(CarbonUIDefinitions.class.getName());
        CarbonUIDefinitions carbonUIDefinitions;
        if (reference != null) {
            carbonUIDefinitions = (CarbonUIDefinitions) bundleContext.getService(reference);
            Menu[] userMenus = carbonUIDefinitions.getMenuDefinitions(loggedInUserName,
                        isSuperTenant, userPermission,request);
            if (userMenus != null) {
                Set<Menu> menuList = new LinkedHashSet<Menu>();
                menuList.addAll(Arrays.<Menu>asList(userMenus));
                Menu[] customMenus =
                        (Menu[]) request.getSession().getAttribute(USER_CUSTOM_MENU_ITEMS);
                if (customMenus != null) {
                    menuList.addAll(Arrays.<Menu>asList(customMenus));
                }
                menus = menuList.toArray(new Menu[menuList.size()]);
            	if (log.isDebugEnabled()) {
                    log.debug("Found exiting menu items in OSGI context");
                }
            }
        }
    }
}
 
Example 15
private boolean initCodeElementService(){
	BundleContext context =
		FrameworkUtil.getBundle(ReChargeTarmedOpenCons.class).getBundleContext();
	serviceRef = context.getServiceReference(ICodeElementService.class);
	if (serviceRef != null) {
		codeElementService = context.getService(serviceRef);
		return true;
	} else {
		return false;
	}
}
 
Example 16
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void stop ( final BundleContext bundleContext ) throws Exception
{
    this.factory.dispose ();
    this.executor.shutdown ();
    this.factory = null;
    this.executor = null;
}
 
Example 17
public PackageAdminTestSuite (BundleContext bc) {
  super("PackageAdminTestSuite");
  this.bc = bc;
  this.bu = bc.getBundle();

  addTest(new Setup());
  addTest(new Frame0187a());
  addTest(new Frame0200a());
  addTest(new Frame215a());
  addTest(new Frame220b());
  addTest(new Cleanup());
}
 
Example 18
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void start ( final BundleContext context ) throws Exception
{
    this.service = new FactoryImpl ( context );

    final Dictionary<String, Object> properties = new Hashtable<> ();
    properties.put ( Constants.SERVICE_DESCRIPTION, "A factory for parser components" );
    properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
    properties.put ( ConfigurationAdministrator.FACTORY_ID, org.eclipse.scada.da.server.component.parser.factory.Constants.FACTORY_ID );

    this.handle = context.registerService ( ConfigurationFactory.class, this.service, properties );
}
 
Example 19
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void stop ( final BundleContext bundleContext ) throws Exception
{
    this.tracker.close ();

    if ( this.injector != null )
    {
        this.injector.dispose ();
        this.injector = null;
    }

    Activator.context = null;
}
 
Example 20
@Test
public void loadClassWithNullCustomClassloader() throws ClassNotFoundException{
  OSGiStartProcessEngineStep step = new OSGiStartProcessEngineStep(mock(ProcessEngineXml.class), mock(BundleContext.class));
  String clazz = "java.lang.Object";
  Class<? extends Object> loadedClazz = step.loadClass(clazz, null, null);
  assertThat(loadedClazz.getName(), is(Object.class.getName()));
}
 
Example 21
/** The default constructor. */
public EventTableModel(BundleContext bc) {
  super();
  final String capacityS = bc.getProperty(CAPACITY_PROP_NAME);
  if (null!=capacityS && capacityS.length()>0) {
    try {
      capacity = Integer.parseInt(capacityS.trim());
    } catch (NumberFormatException nfe){
    }
  }
  if (capacity>0) {
    entries.ensureCapacity(capacity);
  }
}
 
Example 22
private EventAdmin findEventAdmin(BundleContext ctx) {
  ServiceReference<EventAdmin> ref = ctx.getServiceReference(EventAdmin.class);
  EventAdmin eventAdmin = null;
  if (ref != null) {
    eventAdmin = ctx.getService(ref);
  }
  return eventAdmin;
}
 
Example 23
@Override
public void stop(BundleContext bc) throws Exception {
  if(msfr != null) {
    msfr.unregister();
  }
  if(sr != null) {
    sr.unregister();
  }
  factory.destroyAll();
}
 
Example 24
Source Project: wisdom   Source File: FactoryModelTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testFactories() throws Exception {
    Factory factory1 = mock(Factory.class);
    when(factory1.getName()).thenReturn("factory-1");

    Factory factory2 = mock(Factory.class);
    when(factory2.getName()).thenReturn("factory-2");

    HandlerFactory factory3 = mock(HandlerFactory.class);
    when(factory3.getName()).thenReturn("factory-3");
    when(factory3.getHandlerName()).thenReturn("h:factory-3");

    ServiceReference<Factory> ref1 = mock(ServiceReference.class);
    ServiceReference<Factory> ref2 = mock(ServiceReference.class);

    ServiceReference<HandlerFactory> ref3 = mock(ServiceReference.class);

    BundleContext context = mock(BundleContext.class);
    when(context.getServiceReferences(Factory.class, null)).thenReturn(ImmutableList.of(ref1, ref2));
    when(context.getServiceReferences(HandlerFactory.class, null)).thenReturn(ImmutableList.of(ref3));

    when(context.getService(ref1)).thenReturn(factory1);
    when(context.getService(ref2)).thenReturn(factory2);
    when(context.getService(ref3)).thenReturn(factory3);

    List<FactoryModel> models = FactoryModel.factories(context);
    assertThat(models).hasSize(3);
}
 
Example 25
Source Project: fuchsia   Source File: DefaultExportationLinker.java    License: Apache License 2.0 5 votes vote down vote up
public DefaultExportationLinker(BundleContext context) {
    this.bundleContext = context;
    processProperties();

    linkerManagement = new LinkerManagement<ExportDeclaration, ExporterService>(bundleContext, exporterServiceFilter, exportDeclarationFilter);
    exportersManager = linkerManagement.getBindersManager();
    declarationsManager = linkerManagement.getDeclarationsManager();
}
 
Example 26
Source Project: siddhi   Source File: SiddhiExtensionLoader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to load the Siddhi extensions.
 *
 * @param siddhiExtensionsMap reference map for the Siddhi extension
 * @param extensionHolderMap  reference map for the Siddhi extension holder
 */
public static void loadSiddhiExtensions(Map<String, Class> siddhiExtensionsMap,
                                        ConcurrentHashMap<Class, AbstractExtensionHolder> extensionHolderMap) {
    loadLocalExtensions(siddhiExtensionsMap, extensionHolderMap);
    BundleContext bundleContext = ReferenceHolder.getInstance().getBundleContext();
    if (bundleContext != null) {
        loadExtensionOSGI(bundleContext, siddhiExtensionsMap, extensionHolderMap);
    }
}
 
Example 27
Source Project: roboconf-platform   Source File: HttpClientFactoryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testNonTrivialConstructor() {

	BundleContext bundleContext = Mockito.mock( BundleContext.class );
	HttpClientFactory factory = new HttpClientFactory( bundleContext );
	Assert.assertEquals( bundleContext, factory.bundleContext );
}
 
Example 28
Source Project: neoscada   Source File: Activator.java    License: Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void start ( final BundleContext context ) throws Exception
{
    super.start ( context );
    plugin = this;
}
 
Example 29
Source Project: Pydev   Source File: RefactoringPlugin.java    License: Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This method is called upon plug-in activation
 */
@Override
public void start(BundleContext context) throws Exception {
    super.start(context);
}
 
Example 30
Source Project: micro-integrator   Source File: FileBasedClaimBuilder.java    License: Apache License 2.0 4 votes vote down vote up
public static void setBundleContext(BundleContext bundleContext) {
    FileBasedClaimBuilder.bundleContext = bundleContext;
}