List of usage examples for java.util Dictionary keys
public abstract Enumeration<K> keys();
From source file:org.eclipse.smarthome.io.transport.mqtt.MqttService.java
@Override public void updated(Dictionary<String, ?> properties) throws ConfigurationException { // load broker configurations from configuration file if (properties == null || properties.isEmpty()) { return;/* w w w. j av a 2 s . c o m*/ } Enumeration<String> keys = properties.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (key.equals("service.pid")) { // ignore the only non-broker property.. continue; } String[] subkeys = key.split("\\."); if (subkeys.length != 2) { logger.debug("MQTT Broker property '{}' should have the format 'broker.propertykey'", key); continue; } String value = (String) properties.get(key); String name = subkeys[0].toLowerCase(); String property = subkeys[1]; if (StringUtils.isBlank(value)) { logger.trace("Property is empty: {}", key); continue; } else { logger.trace("Processing property: {} = {}", key, value); } MqttBrokerConnection conn = brokerConnections.get(name); if (conn == null) { conn = new MqttBrokerConnection(name); brokerConnections.put(name, conn); } if (property.equals("url")) { conn.setUrl(value); } else if (property.equals("user")) { conn.setUser(value); } else if (property.equals("pwd")) { conn.setPassword(value); } else if (property.equals("qos")) { conn.setQos(Integer.parseInt(value)); } else if (property.equals("retain")) { conn.setRetain(Boolean.parseBoolean(value)); } else if (property.equals("async")) { conn.setAsync(Boolean.parseBoolean(value)); } else if (property.equals("clientId")) { conn.setClientId(value); } else { logger.warn("Unrecognized property: {}", key); } } logger.info("MQTT Service initialization completed."); for (MqttBrokerConnection con : brokerConnections.values()) { try { con.start(); } catch (Exception e) { logger.error("Error starting broker connection {} : {}", con.getName(), e.getMessage()); } } }
From source file:org.codice.ddf.configuration.admin.ConfigurationAdminMigratableTest.java
private Map<String, Object> convertToMap(Dictionary<String, ?> dictionary) { Map<String, Object> map = new HashMap<>(); Enumeration<String> keys = dictionary.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); map.put(key, dictionary.get(key)); }//from w w w .j a v a 2s .c o m return map; }
From source file:org.openhab.binding.modbus.internal.ModbusConfiguration.java
@Override @SuppressWarnings("rawtypes") public void updated(Dictionary config) throws ConfigurationException { // remove all known items if configuration changed Collections.synchronizedMap(modbusSlaves).clear(); if (config != null) { Enumeration keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; }/*from w ww. ja v a 2s . c om*/ Matcher matcher = EXTRACT_MODBUS_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { if ("poll".equals(key)) { poll = Integer.valueOf((String) config.get(key)); } else if ("writemultipleregisters".equals(key)) { ModbusSlave.setWriteMultipleRegisters(Boolean.valueOf(config.get(key).toString())); } else { logger.debug("given modbus-slave-config-key '" + key + "' does not follow the expected pattern 'poll' or '<slaveId>.<connection|id|start|length|type>'"); } continue; } matcher.reset(); matcher.find(); String slave = matcher.group(2); ModbusSlave modbusSlave = Collections.synchronizedMap(modbusSlaves).get(slave); if (modbusSlave == null) { if (matcher.group(1).equals(TCP_PREFIX)) { modbusSlave = new ModbusTcpSlave(slave); } else if (matcher.group(1).equals(SERIAL_PREFIX)) { modbusSlave = new ModbusSerialSlave(slave); } else throw new ConfigurationException(slave, "the given slave type '" + slave + "' is unknown"); Collections.synchronizedMap(modbusSlaves).put(slave, modbusSlave); } String configKey = matcher.group(3); String value = (String) config.get(key); if ("connection".equals(configKey)) { String[] chunks = value.split(":"); if (modbusSlave instanceof ModbusTcpSlave) { ((ModbusTcpSlave) modbusSlave).setHost(chunks[0]); if (chunks.length == 2) { ((ModbusTcpSlave) modbusSlave).setPort(Integer.valueOf(chunks[1])); } } else if (modbusSlave instanceof ModbusSerialSlave) { ((ModbusSerialSlave) modbusSlave).setPort(chunks[0]); if (chunks.length == 2) { ((ModbusSerialSlave) modbusSlave).setBaud(Integer.valueOf(chunks[1])); } } } else if ("start".equals(configKey)) { modbusSlave.setStart(Integer.valueOf(value)); } else if ("length".equals(configKey)) { modbusSlave.setLength(Integer.valueOf(value)); } else if ("id".equals(configKey)) { modbusSlave.setId(Integer.valueOf(value)); } else if ("type".equals(configKey)) { if (ArrayUtils.contains(ModbusBindingProvider.SLAVE_DATA_TYPES, value)) { modbusSlave.setType(value); } else { throw new ConfigurationException(configKey, "the given slave type '" + value + "' is invalid"); } } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } } // connect instances to modbus slaves for (ModbusSlave slave : Collections.synchronizedMap(modbusSlaves).values()) { slave.connect(); } }
From source file:org.openhab.binding.mpower.internal.MpowerBinding.java
/** * @{inheritDoc// w w w.java 2 s . co m */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { // clean up first shutDown(); Enumeration<String> keys = config.keys(); // // put all configurations into a nice structure // HashMap<String, MpowerConfig> bindingConfigs = new HashMap<String, MpowerConfig>(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (CONFIG_REFRESH.equals(key)) { // global refresh = watchdog String reconn = (String) config.get(CONFIG_REFRESH); refreshInterval = Long.parseLong(reconn); continue; } String mpowerId = StringUtils.substringBefore(key, "."); String configOption = StringUtils.substringAfterLast(key, "."); if (!"service".equals(mpowerId)) { MpowerConfig aConfig = null; if (bindingConfigs.containsKey(mpowerId)) { aConfig = bindingConfigs.get(mpowerId); } else { aConfig = new MpowerConfig(); aConfig.setId(mpowerId); bindingConfigs.put(mpowerId, aConfig); } if (CONFIG_USERNAME.equals(configOption)) { aConfig.setUser((String) config.get(key)); } if (CONFIG_PASSWORD.equals(configOption)) { aConfig.setPassword((String) config.get(key)); } if (CONFIG_HOST.equals(configOption)) { aConfig.setHost((String) config.get(key)); } if (CONFIG_REFRESH.equals(configOption)) { Long refresh = Long.parseLong((String) config.get(key)); aConfig.setRefreshInterval(refresh); } } } // // now start the connectors // for (Map.Entry<String, MpowerConfig> entry : bindingConfigs.entrySet()) { MpowerConfig aConfig = entry.getValue(); if (aConfig.isValid()) { logger.debug("Creating and starting new connector ", aConfig.getId()); MpowerSSHConnector connector = new MpowerSSHConnector(aConfig.getHost(), aConfig.getId(), aConfig.getUser(), aConfig.getPassword(), aConfig.getRefreshInterval(), this); connectors.put(aConfig.getId(), connector); connector.start(); } else { logger.warn("Invalid mPower configuration"); } } setProperlyConfigured(true); } }
From source file:org.sakaiproject.nakamura.solr.MultiMasterSolrClient.java
private Map<String, Object> toMap(@SuppressWarnings("rawtypes") Dictionary properties) { Builder<String, Object> b = ImmutableMap.builder(); for (Enumeration<?> e = properties.keys(); e.hasMoreElements();) { String k = (String) e.nextElement(); b.put(k, properties.get(k));/*from www. ja v a 2s . c o m*/ } return b.build(); }
From source file:org.sakaiproject.kernel.mailman.impl.MailmanManagerImpl.java
@SuppressWarnings("unchecked") public void updated(Dictionary config) throws ConfigurationException { LOGGER.info("Got config update"); Builder<String, String> builder = ImmutableMap.builder(); for (Enumeration<?> e = config.keys(); e.hasMoreElements();) { String k = (String) e.nextElement(); builder.put(k, (String) config.get(k)); }/* w ww .j a va2 s . c o m*/ configMap = builder.build(); }
From source file:org.openhab.io.transport.mqtt.MqttService.java
@Override public void updated(Dictionary<String, ?> properties) throws ConfigurationException { // load broker configurations from configuration file if (properties == null || properties.isEmpty()) { return;/* ww w . j a v a 2 s .c o m*/ } Enumeration<String> keys = properties.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (key.equals("service.pid")) { // ignore the only non-broker property.. continue; } String[] subkeys = key.split("\\."); if (subkeys.length != 2) { logger.debug("MQTT Broker property '{}' should have the format 'broker.propertykey'", key); continue; } String value = (String) properties.get(key); String name = subkeys[0].toLowerCase(); String property = subkeys[1]; if (StringUtils.isBlank(value)) { logger.trace("Property is empty: {}", key); continue; } else { logger.trace("Processing property: {} = {}", key, value); } MqttBrokerConnection conn = brokerConnections.get(name); if (conn == null) { conn = new MqttBrokerConnection(name); brokerConnections.put(name, conn); } if (property.equals("url")) { conn.setUrl(value); } else if (property.equals("user")) { conn.setUser(value); } else if (property.equals("pwd")) { conn.setPassword(value); } else if (property.equals("qos")) { conn.setQos(Integer.parseInt(value)); } else if (property.equals("retain")) { conn.setRetain(Boolean.parseBoolean(value)); } else if (property.equals("async")) { conn.setAsync(Boolean.parseBoolean(value)); } else if (property.equals("clientId")) { conn.setClientId(value); } else if (property.equals("lwt")) { MqttWillAndTestament will = MqttWillAndTestament.fromString(value); logger.debug("Setting last will: {}", will); conn.setLastWill(will); } else if (property.equals("keepAlive")) { conn.setKeepAliveInterval(Integer.parseInt(value)); } else { logger.warn("Unrecognized property: {}", key); } } logger.info("MQTT Service initialization completed."); for (MqttBrokerConnection con : brokerConnections.values()) { try { con.start(); } catch (Exception e) { logger.error("Error starting broker connection", e); } } }
From source file:org.openhab.binding.energenie.internal.EnergenieBinding.java
/** * @{inheritDoc}/*from w w w . ja v a2s . co m*/ */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; } Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { logger.debug("given config key '" + key + "' does not follow the expected pattern '<id>.<host|password>'"); continue; } matcher.reset(); matcher.find(); String deviceId = matcher.group(1); DeviceConfig deviceConfig = deviceConfigs.get(deviceId); if (deviceConfig == null) { deviceConfig = new DeviceConfig(deviceId); deviceConfigs.put(deviceId, deviceConfig); } String configKey = matcher.group(2); String value = (String) config.get(key); if ("host".equals(configKey)) { deviceConfig.host = value; pmsIpConfig.put(deviceId, value); } else if ("password".equals(configKey)) { deviceConfig.password = value; pmsPasswordConfig.put(deviceId, value); } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } String refreshIntervalString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } setProperlyConfigured(true); } }
From source file:ch.entwine.weblounge.contentrepository.impl.ContentRepositoryServiceFactory.java
/** * {@inheritDoc}//from www . j a v a 2 s . c o m * * @see org.osgi.service.cm.ManagedServiceFactory#updated(java.lang.String, * java.util.Dictionary) */ public void updated(String pid, Dictionary properties) throws ConfigurationException { // is this an update to an existing service? if (services.containsKey(pid)) { ServiceRegistration registration = services.get(pid); ManagedService service = (ManagedService) bundleCtx.getService(registration.getReference()); service.updated(properties); } // Create a new content repository service instance else { String className = (String) properties.get(OPT_TYPE); if (StringUtils.isBlank(className)) { className = repositoryType; } Class<ContentRepository> repositoryImplementation; ContentRepository repository = null; try { repositoryImplementation = (Class<ContentRepository>) Class.forName(className); repository = repositoryImplementation.newInstance(); repository.setEnvironment(environment); repository.setSerializer(serializer); // If this is a managed service, make sure it's configured properly // before the site is connected if (repository instanceof ManagedService) { Dictionary<Object, Object> finalProperties = new Hashtable<Object, Object>(); // Add the default configuration according to the repository type Dictionary<Object, Object> configuration = loadConfiguration(repository.getType()); if (configuration != null) { for (Enumeration<Object> keys = configuration.keys(); keys.hasMoreElements();) { Object key = keys.nextElement(); Object value = configuration.get(key); if (value instanceof String) value = ConfigurationUtils.processTemplate((String) value); finalProperties.put(key, value); } } // Overwrite the default configuration with what was passed in for (Enumeration<Object> keys = properties.keys(); keys.hasMoreElements();) { Object key = keys.nextElement(); Object value = properties.get(key); if (value instanceof String) value = ConfigurationUtils.processTemplate((String) value); finalProperties.put(key, value); } // push the repository configuration ((ManagedService) repository).updated(finalProperties); } // Register the service String serviceType = ContentRepository.class.getName(); properties.put("service.pid", pid); services.put(pid, bundleCtx.registerService(serviceType, repository, properties)); } catch (ClassNotFoundException e) { throw new ConfigurationException(OPT_TYPE, "Repository implementation class " + className + " not found", e); } catch (InstantiationException e) { throw new ConfigurationException(OPT_TYPE, "Error instantiating repository implementation class " + className + " not found", e); } catch (IllegalAccessException e) { throw new ConfigurationException(OPT_TYPE, "Error accessing repository implementation class " + className + " not found", e); } } }
From source file:org.openhab.binding.panasonictv.internal.PanasonicTVBinding.java
/** * @{inheritDoc//from ww w.j av a2s. c o m */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { String refreshIntervalString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } for (Enumeration<?> e = config.keys(); e.hasMoreElements();) { String tv = (String) e.nextElement(); if (tv.equalsIgnoreCase("service.pid") || tv.equalsIgnoreCase("refresh")) { continue; } logger.info("TV registered '" + tv + "' with IP '" + config.get(tv) + "'"); registeredTVs.put(tv, config.get(tv).toString()); } if (registeredTVs.isEmpty()) { logger.debug("No TV was registered in config file"); } } }