use of org.osgi.service.cm.ConfigurationException in project openhab1-addons by openhab.
the class AlarmDecoderBinding method parseTcpConfig.
/**
* Parses and stores the tcp configuration string of the binding configuration.
* Expected form is tcp:hostname:port
*
* @param parts config string, split on ':'
* @throws ConfigurationException
*/
private void parseTcpConfig(String[] parts) throws ConfigurationException {
if (parts.length != 3) {
throw new ConfigurationException("alarmdecoder:connect", "need hostname and port separated by :");
}
m_tcpHostName = parts[1];
try {
m_tcpPort = Integer.parseInt(parts[2]);
} catch (NumberFormatException e) {
throw new ConfigurationException("alarmdecoder:connect", "tcp port not numeric!");
}
logger.debug("got tcp configuration: {}:{}", m_tcpHostName, m_tcpPort);
}
use of org.osgi.service.cm.ConfigurationException in project openhab1-addons by openhab.
the class AstroConfig method parse.
/**
* Parses and validates the properties in the openhab.cfg.
*/
public void parse(Dictionary<String, ?> properties) throws ConfigurationException {
valid = false;
String cfgLatitude = (String) properties.get(AstroConfig.CONFIG_KEY_LATITUDE);
String cfgLongitude = (String) properties.get(AstroConfig.CONFIG_KEY_LONGITUDE);
if (StringUtils.isBlank(cfgLatitude) || StringUtils.isBlank(cfgLongitude)) {
throw new ConfigurationException("astro", "Parameters latitude and longitude are mandatory and must be configured. Please check your openhab.cfg!");
}
try {
latitude = Double.parseDouble(cfgLatitude);
longitude = Double.parseDouble(cfgLongitude);
} catch (NumberFormatException ex) {
throw new ConfigurationException("astro", "Parameters latitude and/or longitude in wrong format. Please check your openhab.cfg!");
}
interval = parseInt(properties, CONFIG_KEY_INTERVAL, 0);
valid = true;
}
use of org.osgi.service.cm.ConfigurationException in project openhab1-addons by openhab.
the class CULIntertechnoBinding method parseOptionalNumericParameter.
private Integer parseOptionalNumericParameter(String key, Dictionary<String, ?> config) throws ConfigurationException {
String valueString = (String) config.get(key);
int value = 0;
if (!StringUtils.isEmpty(valueString)) {
try {
value = Integer.parseInt(valueString);
return value;
} catch (NumberFormatException e) {
throw new ConfigurationException(key, "Can't parse number");
}
}
return null;
}
use of org.osgi.service.cm.ConfigurationException in project openhab1-addons by openhab.
the class ConfigurationHandler method fillupConfig.
/**
* Fills in the configuration into the configuration object and adds it to the {@link OHConfig}.
*
* @param ohtfDevice The device specific configuration object {@link OHTFDevice}.
* @param deviceConfig The device configuration as {@code Map} of {@code Strings}.
* @throws ConfigurationException
*/
private void fillupConfig(OHTFDevice<?, ?> ohtfDevice, Map<String, String> deviceConfig) throws ConfigurationException {
String uid = deviceConfig.get(ConfigKey.uid.name());
if (uid == null || uid.equals("")) {
// das kommt hier gar nie an
logger.error("===== uid missing");
throw new ConfigurationException(deviceConfig.toString(), "config is an invalid missing uid: openhab.cfg has to be fixed!");
} else {
logger.debug("*** uid is \"{}\"", uid);
}
ohtfDevice.setUid(uid);
String subid = deviceConfig.get(ConfigKey.subid.name());
if (subid != null) {
if (!ohtfDevice.isValidSubId(subid)) {
throw new ConfigurationException(subid, String.format("\"%s\" is an invalid subId: openhab.cfg has to be fixed!", subid));
}
logger.trace("fillupConfig ohtfDevice subid {}", subid);
ohtfDevice.setSubid(subid);
}
if (ohConfig.getConfigByTFId(uid, subid) != null) {
throw new ConfigurationException(String.format("uid: %s subId: %s", uid, subid), String.format("%s: duplicate device config for uid \"%s\" and subId \"%s\": fix openhab.cfg", LoggerConstants.CONFIG, uid, subid));
}
String symbolicName = deviceConfig.get(ConfigKeyAdmin.ohId.name());
if (ohConfig.getConfigByOHId(symbolicName) != null) {
throw new ConfigurationException(String.format("symbolic name: %s", symbolicName), String.format("%s: duplicate device config for symbolic name \"%s\": fix openhab.cfg", LoggerConstants.CONFIG, symbolicName));
}
ohtfDevice.setOhid(symbolicName);
EObject tfConfig = ohtfDevice.getTfConfig();
EList<EStructuralFeature> features = null;
if (tfConfig != null) {
features = tfConfig.eClass().getEAllStructuralFeatures();
}
ArrayList<String> configKeyList = new ArrayList<String>();
for (ConfigKeyAdmin configKey : ConfigKeyAdmin.values()) {
configKeyList.add(configKey.toString());
}
for (String property : deviceConfig.keySet()) {
if (configKeyList.contains(property)) {
continue;
} else {
logger.trace("{} found property {}", LoggerConstants.CONFIG, property);
}
if (features != null) {
for (EStructuralFeature feature : features) {
logger.trace("found feature: {}", feature.getName());
if (feature.getName().equals(property)) {
logger.trace("{} feature type {}", LoggerConstants.CONFIG, feature.getEType().getInstanceClassName());
logger.debug("configuring feature: {} for uid {} subid {}", feature.getName(), uid, subid);
String className = feature.getEType().getInstanceClassName();
if (className.equals("int") || className.equals("java.lang.Integer")) {
tfConfig.eSet(feature, Integer.parseInt(deviceConfig.get(property)));
} else if (className.equals("short") || className.equals("java.lang.Short")) {
tfConfig.eSet(feature, Short.parseShort(deviceConfig.get(property)));
} else if (className.equals("long") || className.equals("java.lang.Long")) {
tfConfig.eSet(feature, Long.parseLong(deviceConfig.get(property)));
} else if (className.equals("boolean") || className.equals("java.lang.Boolean")) {
logger.debug("{} found boolean value", LoggerConstants.CONFIG);
tfConfig.eSet(feature, Boolean.parseBoolean(deviceConfig.get(property)));
} else if (className.equals("java.lang.String")) {
logger.debug("{} found String value", LoggerConstants.CONFIG);
tfConfig.eSet(feature, deviceConfig.get(property));
} else if (className.equals("java.math.BigDecimal")) {
logger.debug("{} found BigDecimal value", LoggerConstants.CONFIG);
tfConfig.eSet(feature, new BigDecimal(deviceConfig.get(property)));
// } else if (feature.getEType().getInstanceClassName().equals("EList")){
// logger.debug("{} found EList value", LoggerConstants.CONFIG);
// List<String> strings = new
// ArrayList<String>(Arrays.asList(deviceConfig.get(property).trim().split("\\s+")));
// tfConfig.eSet(feature, strings);
} else {
throw new ConfigurationException(feature.getName(), "unsupported configuration type needed: " + className);
}
break;
}
}
}
}
ohConfig.getOhTfDevices().add(ohtfDevice);
}
use of org.osgi.service.cm.ConfigurationException in project openhab1-addons by openhab.
the class EpsonProjectorBinding method updated.
/**
* {@inheritDoc}
*/
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
logger.debug("Configuration updated, config {}", config != null ? true : false);
if (config != null) {
if (deviceConfigCache == null) {
deviceConfigCache = new HashMap<String, DeviceConfig>();
}
String granularityString = (String) config.get("granularity");
if (StringUtils.isNotBlank(granularityString)) {
granularity = Integer.parseInt(granularityString);
}
Enumeration<String> keys = config.keys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
// don't want to process here ...
if ("service.pid".equals(key)) {
continue;
}
Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key);
if (!matcher.matches()) {
logger.warn("given config key '" + key + "' does not follow the expected pattern '<id>.<host|port>'");
continue;
}
matcher.reset();
matcher.find();
String deviceId = matcher.group(1);
DeviceConfig deviceConfig = deviceConfigCache.get(deviceId);
if (deviceConfig == null) {
logger.debug("Added new device {}", deviceId);
deviceConfig = new DeviceConfig(deviceId);
deviceConfigCache.put(deviceId, deviceConfig);
}
String configKey = matcher.group(2);
String value = (String) config.get(key);
if ("serialPort".equals(configKey)) {
deviceConfig.serialPort = value;
} else if ("host".equals(configKey)) {
deviceConfig.host = value;
} else if ("port".equals(configKey)) {
deviceConfig.port = Integer.valueOf(value);
} else {
throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown");
}
}
setProperlyConfigured(true);
}
}
Aggregations