use of org.osgi.service.cm.ConfigurationException in project openhab1-addons by openhab.
the class SonosBinding method updated.
@Override
@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {
if (config != null) {
Enumeration keys = config.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
// don't want to process here ...
if ("service.pid".equals(key)) {
continue;
}
if ("pollingPeriod".equals(key)) {
pollingPeriod = Integer.parseInt((String) config.get(key));
logger.debug("Setting polling period to {} ms", pollingPeriod);
continue;
}
Matcher matcher = EXTRACT_SONOS_CONFIG_PATTERN.matcher(key);
if (!matcher.matches()) {
logger.debug("given sonos-config-key '" + key + "' does not follow the expected pattern '<sonosId>.<udn>'");
continue;
}
matcher.reset();
matcher.find();
String sonosID = matcher.group(1);
SonosZonePlayer sonosConfig = sonosZonePlayerCache.getById(sonosID);
if (sonosConfig == null) {
sonosConfig = new SonosZonePlayer(sonosID, self);
sonosZonePlayerCache.add(sonosConfig);
}
String configKey = matcher.group(2);
String value = (String) config.get(key);
if ("udn".equals(configKey)) {
sonosConfig.setUdn(new UDN(value));
logger.debug("Add predefined Sonos device with UDN {}", sonosConfig.getUdn());
} else {
throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown");
}
}
}
setProperlyConfigured(true);
}
use of org.osgi.service.cm.ConfigurationException in project felix by apache.
the class TestManagedServiceConfigurableProperties method testDynamicStringInstance2.
@Test
public void testDynamicStringInstance2() {
ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
assertNotNull("Check FS availability", fooRef);
String fooP = (String) fooRef.getProperty("foo");
Integer barP = (Integer) fooRef.getProperty("bar");
String bazP = (String) fooRef.getProperty("baz");
assertEquals("Check foo equality", fooP, "foo");
assertEquals("Check bar equality", barP, new Integer(2));
assertEquals("Check baz equality", bazP, "baz");
ServiceReference msRef = osgiHelper.getServiceReferenceByPID(ManagedService.class.getName(), "instance");
assertNotNull("Check ManagedService availability", msRef);
// Configuration of baz
Dictionary<String, Object> conf = new Hashtable<String, Object>();
conf.put("baz", "zab");
conf.put("foo", "oof");
conf.put("bar", "0");
ManagedService ms = (ManagedService) osgiHelper.getContext().getService(msRef);
try {
ms.updated(conf);
} catch (ConfigurationException e) {
fail("Configuration Exception : " + e);
}
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
fooP = (String) fooRef.getProperty("foo");
barP = (Integer) fooRef.getProperty("bar");
bazP = (String) fooRef.getProperty("baz");
assertEquals("Check foo equality", fooP, "oof");
assertEquals("Check bar equality", barP, new Integer(0));
assertEquals("Check baz equality", bazP, "zab");
// Check field value
FooService fs = (FooService) osgiHelper.getContext().getService(fooRef);
Properties p = fs.fooProps();
fooP = (String) p.get("foo");
barP = (Integer) p.get("bar");
assertEquals("Check foo field equality", fooP, "oof");
assertEquals("Check bar field equality", barP, new Integer(0));
osgiHelper.getContext().ungetService(fooRef);
osgiHelper.getContext().ungetService(msRef);
}
use of org.osgi.service.cm.ConfigurationException in project felix by apache.
the class TestManagedServiceConfigurableProperties method testDynamicInstance3.
@Test
public void testDynamicInstance3() {
ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance3.getInstanceName());
assertNotNull("Check FS availability", fooRef);
Object fooP = fooRef.getProperty("foo");
Object barP = fooRef.getProperty("bar");
Object bazP = fooRef.getProperty("baz");
// No values ... no properties.
assertEquals("Check foo equality", fooP, null);
assertEquals("Check bar equality", barP, null);
assertEquals("Check baz equality", bazP, null);
ServiceReference msRef = osgiHelper.getServiceReferenceByPID(ManagedService.class.getName(), "instance-3");
assertNotNull("Check ManagedServiceFactory availability", msRef);
// Configuration of baz
Dictionary<String, Object> conf = new Hashtable<String, Object>();
conf.put("baz", "zab");
conf.put("foo", "oof");
conf.put("bar", new Integer(0));
ManagedService ms = (ManagedService) osgiHelper.getContext().getService(msRef);
try {
ms.updated(conf);
} catch (ConfigurationException e) {
fail("Configuration Exception : " + e);
}
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance3.getInstanceName());
fooP = (String) fooRef.getProperty("foo");
barP = (Integer) fooRef.getProperty("bar");
bazP = (String) fooRef.getProperty("baz");
assertEquals("Check foo equality", fooP, "oof");
assertEquals("Check bar equality", barP, new Integer(0));
assertEquals("Check baz equality", bazP, "zab");
// Check field value
FooService fs = (FooService) osgiHelper.getContext().getService(fooRef);
Properties p = fs.fooProps();
fooP = (String) p.get("foo");
barP = (Integer) p.get("bar");
assertEquals("Check foo field equality", fooP, "oof");
assertEquals("Check bar field equality", barP, new Integer(0));
osgiHelper.getContext().ungetService(fooRef);
osgiHelper.getContext().ungetService(msRef);
}
use of org.osgi.service.cm.ConfigurationException in project felix by apache.
the class TestManagedServiceConfigurableProperties method testDynamicInstance1.
@Test
public void testDynamicInstance1() {
ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance1.getInstanceName());
assertNotNull("Check FS availability", fooRef);
String fooP = (String) fooRef.getProperty("foo");
Integer barP = (Integer) fooRef.getProperty("bar");
String bazP = (String) fooRef.getProperty("baz");
assertEquals("Check foo equality", fooP, "foo");
assertEquals("Check bar equality", barP, new Integer(2));
assertEquals("Check baz equality", bazP, "baz");
ServiceReference msRef = osgiHelper.getServiceReferenceByPID(ManagedService.class.getName(), "FooProvider-3");
assertNotNull("Check ManagedServiceFactory availability", msRef);
// Configuration of baz
Dictionary<String, Object> conf = new Hashtable<String, Object>();
conf.put("baz", "zab");
conf.put("foo", "oof");
conf.put("bar", new Integer(0));
ManagedService ms = (ManagedService) osgiHelper.getContext().getService(msRef);
try {
ms.updated(conf);
} catch (ConfigurationException e) {
fail("Configuration Exception : " + e);
}
// Re-check props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance1.getInstanceName());
fooP = (String) fooRef.getProperty("foo");
barP = (Integer) fooRef.getProperty("bar");
bazP = (String) fooRef.getProperty("baz");
assertEquals("Check foo equality", fooP, "oof");
assertEquals("Check bar equality", barP, new Integer(0));
assertEquals("Check baz equality", bazP, "zab");
// Check field value
FooService fs = (FooService) osgiHelper.getContext().getService(fooRef);
Properties p = fs.fooProps();
fooP = (String) p.get("foo");
barP = (Integer) p.get("bar");
assertEquals("Check foo field equality", fooP, "oof");
assertEquals("Check bar field equality", barP, new Integer(0));
osgiHelper.getContext().ungetService(fooRef);
osgiHelper.getContext().ungetService(msRef);
}
use of org.osgi.service.cm.ConfigurationException in project felix by apache.
the class TestManagedServiceConfigurableProperties method testStaticInstance2.
@Test
public void testStaticInstance2() {
ServiceReference fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
assertNotNull("Check FS availability", fooRef);
String fooP = (String) fooRef.getProperty("foo");
Integer barP = (Integer) fooRef.getProperty("bar");
String bazP = (String) fooRef.getProperty("baz");
assertEquals("Check foo equality -1", fooP, "foo");
assertEquals("Check bar equality -1", barP, new Integer(2));
assertEquals("Check baz equality -1", bazP, "baz");
ServiceReference msRef = osgiHelper.getServiceReferenceByPID(ManagedService.class.getName(), "instance");
assertNotNull("Check ManagedService availability", msRef);
// Configuration of baz
Dictionary<String, Object> conf = new Hashtable<String, Object>();
conf.put("baz", "zab");
conf.put("bar", new Integer(2));
conf.put("foo", "foo");
ManagedService ms = (ManagedService) osgiHelper.getContext().getService(msRef);
try {
ms.updated(conf);
} catch (ConfigurationException e) {
fail("Configuration Exception : " + e);
}
// Recheck props
fooRef = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance2.getInstanceName());
fooP = (String) fooRef.getProperty("foo");
barP = (Integer) fooRef.getProperty("bar");
bazP = (String) fooRef.getProperty("baz");
assertEquals("Check foo equality -2", fooP, "foo");
assertEquals("Check bar equality -2", barP, new Integer(2));
assertEquals("Check baz equality -2", bazP, "zab");
osgiHelper.getContext().ungetService(fooRef);
osgiHelper.getContext().ungetService(msRef);
}
Aggregations