Java Code Examples for org.osgi.service.cm.ConfigurationAdmin#getConfiguration()
The following examples show how to use
org.osgi.service.cm.ConfigurationAdmin#getConfiguration() .
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
Source File: VoiceManagerTest.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Before public void setUp() throws IOException { voiceManager = getService(VoiceManager.class, VoiceManagerImpl.class); assertNotNull(voiceManager); BundleContext context = bundleContext; ttsService = new TTSServiceStub(context); sink = new SinkStub(); voice = new VoiceStub(); source = new AudioSourceStub(); registerService(sink); registerService(voice); Dictionary<String, Object> voiceConfig = new Hashtable<String, Object>(); voiceConfig.put(CONFIG_DEFAULT_TTS, ttsService.getId()); ConfigurationAdmin configAdmin = super.getService(ConfigurationAdmin.class); Configuration configuration = configAdmin.getConfiguration(PID); configuration.update(voiceConfig); audioManager = new AudioManagerStub(); registerService(audioManager); }
Example 2
Source File: InterpretCommandTest.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Before public void setUp() throws IOException, InterruptedException { ttsService = new TTSServiceStub(); hliStub = new HumanLanguageInterpreterStub(); voice = new VoiceStub(); registerService(voice); registerService(hliStub); registerService(ttsService); Dictionary<String, Object> config = new Hashtable<String, Object>(); config.put(CONFIG_DEFAULT_TTS, ttsService.getId()); config.put(CONFIG_DEFAULT_HLI, hliStub.getId()); config.put(CONFIG_DEFAULT_VOICE, voice.getUID()); ConfigurationAdmin configAdmin = super.getService(ConfigurationAdmin.class); String pid = "org.eclipse.smarthome.voice"; Configuration configuration = configAdmin.getConfiguration(pid); configuration.update(config); }
Example 3
Source File: DeployedCMData.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void uninstall() throws BundleException { final ConfigurationAdmin ca = DirDeployerImpl.caTracker.getService(); if (pids != null && ca != null) { for (final String pid : pids) { try { final Configuration cfg = ca.getConfiguration(pid, null); cfg.delete(); installedCfgs.remove(pid); deleteFilePidToCmPidEntry(pid); } catch (final IOException e) { DirDeployerImpl.log("Failed to uninstall configuration with pid '" + pid + "': " + e.getMessage(), e); } } saveState(); pids = null; } }
Example 4
Source File: VoiceManagerTest.java From openhab-core with Eclipse Public License 2.0 | 6 votes |
@Before public void setUp() throws IOException { voiceManager = getService(VoiceManager.class, VoiceManagerImpl.class); assertNotNull(voiceManager); BundleContext context = bundleContext; ttsService = new TTSServiceStub(context); sink = new SinkStub(); voice = new VoiceStub(); source = new AudioSourceStub(); registerService(sink); registerService(voice); Dictionary<String, Object> voiceConfig = new Hashtable<>(); voiceConfig.put(CONFIG_DEFAULT_TTS, ttsService.getId()); ConfigurationAdmin configAdmin = super.getService(ConfigurationAdmin.class); Configuration configuration = configAdmin.getConfiguration(VoiceManagerImpl.CONFIGURATION_PID); configuration.update(voiceConfig); audioManager = new AudioManagerStub(); registerService(audioManager); }
Example 5
Source File: DeployedCMData.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void uninstall() throws BundleException { final ConfigurationAdmin ca = DirDeployerImpl.caTracker.getService(); if (pids != null && ca != null) { for (final String pid : pids) { try { final Configuration cfg = ca.getConfiguration(pid, null); cfg.delete(); installedCfgs.remove(pid); deleteFilePidToCmPidEntry(pid); } catch (final IOException e) { DirDeployerImpl.log("Failed to uninstall configuration with pid '" + pid + "': " + e.getMessage(), e); } } saveState(); pids = null; } }
Example 6
Source File: InterpretCommandTest.java From openhab-core with Eclipse Public License 2.0 | 6 votes |
@Before public void setUp() throws IOException, InterruptedException { ttsService = new TTSServiceStub(); hliStub = new HumanLanguageInterpreterStub(); voice = new VoiceStub(); registerService(voice); registerService(hliStub); registerService(ttsService); Dictionary<String, Object> config = new Hashtable<>(); config.put(CONFIG_DEFAULT_TTS, ttsService.getId()); config.put(CONFIG_DEFAULT_HLI, hliStub.getId()); config.put(CONFIG_DEFAULT_VOICE, voice.getUID()); ConfigurationAdmin configAdmin = super.getService(ConfigurationAdmin.class); Configuration configuration = configAdmin.getConfiguration(VoiceManagerImpl.CONFIGURATION_PID); configuration.update(config); }
Example 7
Source File: LogConfigImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * *************** Called from set methods ********************* */ private void updateConfig() { try { final ServiceReference<ConfigurationAdmin> sr = bc .getServiceReference(ConfigurationAdmin.class); if (sr != null) { final ConfigurationAdmin ca = bc.getService(sr); if (ca != null) { final Configuration conf = ca.getConfiguration(pid); if (conf != null) { conf.update(configCollection); } } bc.ungetService(sr); } } catch (final IOException io) { } catch (final java.lang.IllegalArgumentException iae) { } catch (final java.lang.IllegalStateException ise) { } }
Example 8
Source File: UsbSerialDiscoveryServiceTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
private void setBackgroundDiscovery(boolean status) throws IOException, InterruptedException { ConfigurationAdmin configAdmin = getService(ConfigurationAdmin.class); Configuration configuration = configAdmin.getConfiguration("discovery.usbserial"); Hashtable<String, Object> properties = new Hashtable<>(); properties.put(CONFIG_PROPERTY_BACKGROUND_DISCOVERY, Boolean.valueOf(status)); configuration.update(properties); // wait until the configuration is actually set in the usbSerialDiscoveryService waitForAssert(() -> { assertThat(usbSerialDiscoveryService.isBackgroundDiscoveryEnabled(), is(status)); }, 1000, 100); }
Example 9
Source File: OSGiTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
protected void setDefaultLocale(Locale locale) throws Exception { assertThat(locale, is(notNullValue())); ConfigurationAdmin configAdmin = (ConfigurationAdmin) getService( Class.forName("org.osgi.service.cm.ConfigurationAdmin")); assertThat(configAdmin, is(notNullValue())); LocaleProvider localeProvider = (LocaleProvider) getService( Class.forName("org.eclipse.smarthome.core.i18n.LocaleProvider")); assertThat(localeProvider, is(notNullValue())); Configuration config = configAdmin.getConfiguration("org.eclipse.smarthome.core.i18nprovider", null); assertThat(config, is(notNullValue())); Dictionary<String, Object> properties = config.getProperties(); if (properties == null) { properties = new Hashtable<>(); } properties.put("language", locale.getLanguage()); properties.put("script", locale.getScript()); properties.put("region", locale.getCountry()); properties.put("variant", locale.getVariant()); config.update(properties); waitForAssert(new Closure<Object>(null) { private static final long serialVersionUID = -5083904877474902686L; public Object doCall() { assertThat(localeProvider.getLocale(), is(locale)); return null; } }); }
Example 10
Source File: ThingManagerOSGiJavaTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private void configureAutoLinking(Boolean on) throws IOException { ConfigurationAdmin configAdmin = getService(ConfigurationAdmin.class); org.osgi.service.cm.Configuration config = configAdmin.getConfiguration("org.eclipse.smarthome.links", null); Dictionary<String, Object> properties = config.getProperties(); if (properties == null) { properties = new Hashtable<>(); } properties.put("autoLinks", on.toString()); config.update(properties); }
Example 11
Source File: BindingInfoI18nTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void assertUsingDefaultLocale() throws Exception { // Set german locale ConfigurationAdmin configAdmin = getService(ConfigurationAdmin.class); Configuration config = configAdmin.getConfiguration("org.eclipse.smarthome.core.i18nprovider", null); Dictionary<String, String> localeCfg = new Hashtable<>(); localeCfg.put("language", "de"); localeCfg.put("country", "DE"); config.update(localeCfg); // before running the test with a default locale make sure the locale has been set LocaleProvider localeProvider = getService(LocaleProvider.class); waitForAssert(() -> assertThat(localeProvider.getLocale().toString(), is("de"))); int initialNumberOfBindingInfos = bindingInfoRegistry.getBindingInfos().size(); // install test bundle Bundle bundle = SyntheticBundleInstaller.install(bundleContext, TEST_BUNDLE_NAME); assertThat(bundle, is(notNullValue())); Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos(/* use default locale */ null); assertThat(bindingInfos.size(), is(initialNumberOfBindingInfos + 1)); BindingInfo bindingInfo = bindingInfos.iterator().next(); assertThat(bindingInfo, is(notNullValue())); assertThat(bindingInfo.getName(), is("Yahoo Wetter Binding")); assertThat(bindingInfo.getDescription(), is( "Das Yahoo Wetter Binding stellt verschiedene Wetterdaten wie die Temperatur, die Luftfeuchtigkeit und den Luftdruck für konfigurierbare Orte vom yahoo Wetterdienst bereit")); }
Example 12
Source File: MDNSDiscoveryServiceOSGiTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
private void setBackgroundDiscoveryViaConfigAdmin(boolean status) throws IOException { ConfigurationAdmin configAdmin = getService(ConfigurationAdmin.class); assertThat(configAdmin, is(notNullValue())); Configuration configuration = configAdmin.getConfiguration("discovery.mdns"); Hashtable<String, Object> properties = new Hashtable<>(); properties.put(CONFIG_PROPERTY_BACKGROUND_DISCOVERY, Boolean.valueOf(status)); configuration.update(properties); }
Example 13
Source File: Utils.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Method to update pax-logging configuration. */ public static void updateLoggingConfiguration() throws IOException { ConfigurationAdmin configurationAdmin = ConfigurationHolder.getInstance().getConfigAdminService(); Configuration configuration = configurationAdmin.getConfiguration(Constants.PAX_LOGGING_CONFIGURATION_PID, "?"); configuration.update(); }
Example 14
Source File: VoiceManagerTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Test public void startDialogWithoutPassingAnyParameters() throws IOException, InterruptedException { sttService = new STTServiceStub(); ksService = new KSServiceStub(); ttsService = new TTSServiceStub(); hliStub = new HumanLanguageInterpreterStub(); source = new AudioSourceStub(); registerService(sttService); registerService(ksService); registerService(ttsService); registerService(hliStub); registerService(source); Dictionary<String, Object> config = new Hashtable<>(); config.put(CONFIG_KEYWORD, "word"); config.put(CONFIG_DEFAULT_STT, sttService.getId()); config.put(CONFIG_DEFAULT_KS, ksService.getId()); config.put(CONFIG_DEFAULT_HLI, hliStub.getId()); config.put(CONFIG_DEFAULT_VOICE, voice.getUID()); ConfigurationAdmin configAdmin = super.getService(ConfigurationAdmin.class); Configuration configuration = configAdmin.getConfiguration(VoiceManagerImpl.CONFIGURATION_PID); configuration.update(config); waitForAssert(() -> { try { voiceManager.startDialog(); } catch (Exception ex) { // if the configuration is not updated yet the startDialog method will throw and exception which will // break the test } assertTrue(ksService.isWordSpotted()); }); }
Example 15
Source File: UsbSerialDiscoveryServiceTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private void setBackgroundDiscovery(boolean status) throws IOException, InterruptedException { ConfigurationAdmin configAdmin = getService(ConfigurationAdmin.class); Configuration configuration = configAdmin.getConfiguration("discovery.usbserial"); Hashtable<String, Object> properties = new Hashtable<>(); properties.put(CONFIG_PROPERTY_BACKGROUND_DISCOVERY, Boolean.valueOf(status)); configuration.update(properties); // wait until the configuration is actually set in the usbSerialDiscoveryService waitForAssert(() -> { assertThat(usbSerialDiscoveryService.isBackgroundDiscoveryEnabled(), is(status)); }, 1000, 100); }
Example 16
Source File: BindingInfoI18nTest.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
@Test public void assertUsingDefaultLocale() throws Exception { // Set german locale ConfigurationAdmin configAdmin = getService(ConfigurationAdmin.class); assertThat(configAdmin, is(notNullValue())); Configuration config = configAdmin.getConfiguration(I18nProviderImpl.CONFIGURATION_PID, null); assertThat(config, is(notNullValue())); Dictionary<String, Object> properties = config.getProperties(); if (properties == null) { properties = new Hashtable<>(); } properties.put("language", "de"); properties.put("region", "DE"); config.update(properties); // before running the test with a default locale make sure the locale has been set LocaleProvider localeProvider = getService(LocaleProvider.class); assertThat(localeProvider, is(notNullValue())); waitForAssert(() -> assertThat(localeProvider.getLocale().toString(), is("de_DE"))); bindingInstaller.exec(TEST_BUNDLE_NAME, () -> { // use default locale Set<BindingInfo> bindingInfos = bindingInfoRegistry.getBindingInfos(null); BindingInfo bindingInfo = bindingInfos.iterator().next(); assertThat(bindingInfo, is(notNullValue())); assertThat(bindingInfo.getName(), is("Yahoo Wetter Binding")); assertThat(bindingInfo.getDescription(), is( "Das Yahoo Wetter Binding stellt verschiedene Wetterdaten wie die Temperatur, die Luftfeuchtigkeit und den Luftdruck für konfigurierbare Orte vom yahoo Wetterdienst bereit")); }); }
Example 17
Source File: BasicTeleportedIT.java From sling-samples with Apache License 2.0 | 5 votes |
@Test public void testConfigAdmin() throws IOException { final String pid = "TEST_" + getClass().getName() + UUID.randomUUID(); // demonstrate that we can access OSGi services from teleported tests final ConfigurationAdmin ca = teleporter.getService(ConfigurationAdmin.class); assertNotNull("Teleporter should provide a ConfigurationAdmin", ca); final Configuration cfg = ca.getConfiguration(pid); assertNotNull("Expecting to get a Configuration", cfg); assertEquals("Expecting the correct pid", pid, cfg.getPid()); }
Example 18
Source File: CMCommands.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
public int cmdCreate(Dictionary<?, ?> opts, Reader in, PrintWriter out, Session session) { int retcode = 1; // 1 initially not set to 0 until end of try block setCurrent(session, null); setEditingDict(session); final String pid = (String) opts.get("pid"); final boolean createFactoryConfiguration = opts.get("-f") != null; ConfigurationAdmin srvCA = null; Configuration templateCfg = null; try { srvCA = getCA(); final String template = (String) opts.get("template"); if (template != null) { final Configuration[] templates = getConfigurations(out, session, srvCA, template); if (templates == null || templates.length == 0) { throw new Exception("Template didn't match any configurations. " + "Remove the template parameter or change " + "your it to match exactly one " +"configuration."); } else if (templates.length == 1) { templateCfg = templates[0]; if (pid.equals(templateCfg.getPid())) { throw new Exception("template configuration has the same PID as " +"the new one."); } } else { throw new Exception("Template matched " + templates.length + " configurations. Refine your selection " +"to match exactly one configuration."); } } Configuration cfg = null; if (createFactoryConfiguration) { cfg = srvCA.createFactoryConfiguration(pid, null); } else { final Configuration[] exisitingCfgs = srvCA .listConfigurations("(" + Constants.SERVICE_PID + "=" + pid + ")"); if (exisitingCfgs != null && exisitingCfgs.length == 1) { throw new Exception("A configuration with PID '" + pid + "' already exists."); } cfg = srvCA.getConfiguration(pid, null); } if (cfg == null) { throw new Exception("Failed creating configuration with PID: '" + pid +"'."); } if (templateCfg != null) { cfg.update(templateCfg.getProperties()); } setCurrent(session, cfg); retcode = 0; // Success! } catch (final Exception e) { out.print("Create failed. Details:"); final String reason = e.getMessage(); out.println(reason == null ? "<unknown>" : reason); } finally { if (srvCA != null) { bc.ungetService(refCA); } } return retcode; }
Example 19
Source File: SayCommandTest.java From openhab-core with Eclipse Public License 2.0 | 4 votes |
@Test public void testSayCommand() throws IOException { String[] methodParameters = new String[2]; methodParameters[0] = SUBCMD_SAY; if (defaultTTSService != null) { Dictionary<String, Object> config = new Hashtable<>(); config.put(CONFIG_DEFAULT_TTS, defaultTTSService); ConfigurationAdmin configAdmin = super.getService(ConfigurationAdmin.class); Configuration configuration = configAdmin.getConfiguration(VoiceManagerImpl.CONFIGURATION_PID); configuration.update(config); } if (ttsServiceMockShouldBeRegistered) { registerService(ttsService); } if (shouldItemsBePassed) { VolatileStorageService volatileStorageService = new VolatileStorageService(); registerService(volatileStorageService); ManagedThingProvider managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class); assertNotNull(managedThingProvider); ItemRegistry itemRegistry = getService(ItemRegistry.class); assertNotNull(itemRegistry); Item item = new StringItem("itemName"); if (shouldItemsBeRegistered) { itemRegistry.add(item); } methodParameters[1] = "%" + item.getName() + "%"; if (shouldMultipleItemsBeRegistered) { Item item1 = new StringItem("itemName1"); itemRegistry.add(item1); Item item2 = new StringItem("itemName2"); itemRegistry.add(item2); Item item3 = new StringItem("itemName3"); itemRegistry.add(item3); methodParameters[1] = "%itemName.%"; } } else { methodParameters[1] = "hello"; } extensionService.execute(methodParameters, console); assertThat(sink.isStreamProcessed(), is(shouldStreamBeExpected)); }
Example 20
Source File: SayCommandTest.java From smarthome with Eclipse Public License 2.0 | 4 votes |
@Test public void testSayCommand() throws IOException { String[] methodParameters = new String[2]; methodParameters[0] = SUBCMD_SAY; if (defaultTTSService != null) { Dictionary<String, Object> config = new Hashtable<String, Object>(); config.put(CONFIG_DEFAULT_TTS, defaultTTSService); ConfigurationAdmin configAdmin = super.getService(ConfigurationAdmin.class); String pid = "org.eclipse.smarthome.voice"; Configuration configuration = configAdmin.getConfiguration(pid); configuration.update(config); } if (TTSServiceMockShouldBeRegistered) { registerService(ttsService); } if (shouldItemsBePassed) { VolatileStorageService volatileStorageService = new VolatileStorageService(); registerService(volatileStorageService); ManagedThingProvider managedThingProvider = getService(ThingProvider.class, ManagedThingProvider.class); assertNotNull(managedThingProvider); ItemRegistry itemRegistry = getService(ItemRegistry.class); assertNotNull(itemRegistry); Item item = new StringItem("itemName"); if (shouldItemsBeRegistered) { itemRegistry.add(item); } methodParameters[1] = "%" + item.getName() + "%"; if (shouldMultipleItemsBeRegistered) { Item item1 = new StringItem("itemName1"); itemRegistry.add(item1); Item item2 = new StringItem("itemName2"); itemRegistry.add(item2); Item item3 = new StringItem("itemName3"); itemRegistry.add(item3); methodParameters[1] = "%itemName.%"; } } else { methodParameters[1] = "hello"; } extensionService.execute(methodParameters, console); assertThat(sink.isStreamProcessed(), is(shouldStreamBeExpected)); }