List of usage examples for java.util Dictionary get
public abstract V get(Object key);
From source file:org.openhab.binding.pca301.internal.PCA301Binding.java
/** * @{inheritDoc//from ww w . j a v a2 s . c o m */ public void updated(Dictionary<String, ?> config) throws ConfigurationException { logger.debug("Received new config"); if (config != null) { // configuration has changed, close JeeLink device if necessary if (device != null) { if (device.isOpen()) { device.close(); } device.removeListener(this); device = null; } // reset channels and cache synchronized (channels) { channels.clear(); } synchronized (cache) { cache.clear(); } // read serial port name final String port = (String) config.get(KEY_PORT); if (StringUtils.isBlank(port)) { logger.error("Port of JeeLink device is missing"); throw new ConfigurationException(KEY_PORT, "The port can't be empty"); } // read retry count, default is zero int retryCount = 0; final String retryCountValue = (String) config.get(KEY_RETRY_COUNT); if (StringUtils.isNotBlank(retryCountValue)) { try { retryCount = Integer.parseInt(retryCountValue); } catch (final NumberFormatException e) { logger.error("Failed to read retry count value: " + retryCountValue, e); } } // create and open JeeLink device device = new JeeLinkDevice(port, retryCount); device.addListener(this); device.open(); } }
From source file:org.apache.felix.webconsole.internal.compendium.ComponentsServlet.java
private void listComponentProperties(JSONWriter jsonWriter, Component inputComponent) { Dictionary propsBook = inputComponent.getProperties(); if (propsBook != null) { JSONArray myBuf = new JSONArray(); TreeSet bookKeys = new TreeSet(Collections.list(propsBook.keys())); for (Iterator keyIter = bookKeys.iterator(); keyIter.hasNext();) { final String key = (String) keyIter.next(); final StringBuffer strBuffer = new StringBuffer(); strBuffer.append(key).append(" = "); Object prop = propsBook.get(key); if (prop.getClass().isArray()) { prop = Arrays.asList((Object[]) prop); }/*from ww w .j a va 2s . c o m*/ strBuffer.append(prop); myBuf.put(strBuffer.toString()); } printKeyVal(jsonWriter, "Properties", myBuf); } }
From source file:net.solarnetwork.node.settings.ca.CASettingsService.java
@Override public Object getSettingValue(SettingSpecifierProvider provider, SettingSpecifier setting) { if (setting instanceof KeyedSettingSpecifier<?>) { KeyedSettingSpecifier<?> keyedSetting = (KeyedSettingSpecifier<?>) setting; if (keyedSetting.isTransient()) { return keyedSetting.getDefaultValue(); }/*from w w w . j ava 2s .com*/ final String providerUID = provider.getSettingUID(); final String instanceUID = (provider instanceof FactorySettingSpecifierProvider ? ((FactorySettingSpecifierProvider) provider).getFactoryInstanceUID() : null); try { Configuration conf = getConfiguration(providerUID, instanceUID); @SuppressWarnings("unchecked") Dictionary<String, ?> props = conf.getProperties(); Object val = (props == null ? null : props.get(keyedSetting.getKey())); if (val == null) { val = keyedSetting.getDefaultValue(); } return val; } catch (IOException e) { throw new RuntimeException(e); } catch (InvalidSyntaxException e) { throw new RuntimeException(e); } } return null; }
From source file:org.openhab.binding.openpaths.internal.OpenPathsBinding.java
/** * @{inheritDoc//from ww w . j a va 2s. c o m */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { openPathsUsers = new HashMap<String, OpenPathsUser>(); locations = new HashMap<String, Location>(); if (config != null) { Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); String value = (String) config.get(key); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; } if ("refresh".equals(key)) { if (StringUtils.isNotBlank(value)) { refreshInterval = Long.parseLong(value); logger.trace("Config: refresh=" + this.refreshInterval); } } else if ("geofence".equals(key)) { // only for backward compatibility / as fallback if (StringUtils.isNotBlank(value)) { geoFence = Float.parseFloat(value); logger.trace("Config: geofence=" + this.geoFence); } } else if (key.endsWith("lat")) { String[] keyParts = key.split("\\."); if (keyParts.length != 2) { throw new ConfigurationException(key, "Invalid OpenPaths user location lattitude: " + key); } if (StringUtils.isNotBlank(value)) { float lat = Float.parseFloat(value); String name = keyParts[0]; if (locations.containsKey(name)) { locations.get(name).setLatitude(lat); logger.trace("Config: new Location " + name + "(" + locations.get(name) + ")"); } else { Location loc = new Location(); loc.setLatitude(lat); logger.trace("Config: update Location " + name + "(" + locations.get(name) + ")"); locations.put(name, loc); } } } else if (key.endsWith("long")) { String[] keyParts = key.split("\\."); if (keyParts.length != 2) { throw new ConfigurationException(key, "Invalid OpenPaths user location longitude: " + key); } if (StringUtils.isNotBlank(value)) { float lon = Float.parseFloat(value); String name = keyParts[0]; if (locations.containsKey(name)) { locations.get(name).setLongitude(lon); logger.trace("Config: new Location " + name + "(" + locations.get(name) + ")"); } else { Location loc = new Location(); loc.setLongitude(lon); logger.trace("Config: update Location " + name + "(" + locations.get(name) + ")"); locations.put(name, loc); } } } else if (key.endsWith("geofence") && !key.equals("geofence")) { String[] keyParts = key.split("\\."); if (keyParts.length != 2) { throw new ConfigurationException(key, "Invalid OpenPaths user location geofence: " + key); } if (StringUtils.isNotBlank(value)) { float fence = Float.parseFloat(value); String name = keyParts[0]; if (locations.containsKey(name)) { locations.get(name).setGeofence(fence); logger.trace("Config: new Location " + name + "(" + locations.get(name) + ")"); } else { Location loc = new Location(); loc.setGeofence(fence); logger.trace("Config: update Location " + name + "(" + locations.get(name) + ")"); locations.put(name, loc); } } } else if (key.endsWith("key")) { String[] keyParts = key.split("\\."); if (keyParts.length != 2) { throw new ConfigurationException(key, "Invalid OpenPaths user key: " + key); } String name = keyParts[0]; String configKey = keyParts[1]; if (!openPathsUsers.containsKey(name)) { openPathsUsers.put(name, new OpenPathsUser(name)); } OpenPathsUser openPathsUser = openPathsUsers.get(name); if (configKey.equalsIgnoreCase("accesskey")) { openPathsUser.setAccessKey(value); } else if (configKey.equalsIgnoreCase("secretkey")) { openPathsUser.setSecretKey(value); } else { throw new ConfigurationException(key, "Unrecognised configuration parameter: " + configKey); } } } if (!locations.containsKey("home")) throw new ConfigurationException("home.lat", "No location specified for 'home'"); setProperlyConfigured(true); } }
From source file:com.hexidec.ekit.component.RelativeImageView.java
private void initialize(Element elem) { synchronized (this) { bLoading = true;/* w w w . j a va 2 s. c o m*/ fWidth = 0; fHeight = 0; } int width = 0; int height = 0; boolean customWidth = false; boolean customHeight = false; try { fElement = elem; // request image from document's cache AttributeSet attr = elem.getAttributes(); if (isURL()) { URL src = getSourceURL(); if (src != null) { Dictionary cache = (Dictionary) getDocument().getProperty(IMAGE_CACHE_PROPERTY); if (cache != null) { fImage = (Image) cache.get(src); } else { fImage = Toolkit.getDefaultToolkit().getImage(src); } } } else { // load image from relative path String src = (String) fElement.getAttributes().getAttribute(HTML.Attribute.SRC); src = processSrcPath(src); fImage = Toolkit.getDefaultToolkit().createImage(src); try { waitForImage(); } catch (InterruptedException ie) { fImage = null; // possibly replace with the ImageBroken icon, if that's what is happening } catch (Exception ex) { fImage = null; // trap a null exception or other exception that puts the image pointer into an empty or ambiguous state } } // get height & width from params or image or defaults height = getIntAttr(HTML.Attribute.HEIGHT, -1); customHeight = (height > 0); if (!customHeight && fImage != null) { height = fImage.getHeight(this); } if (height <= 0) { height = DEFAULT_HEIGHT; } width = getIntAttr(HTML.Attribute.WIDTH, -1); customWidth = (width > 0); if (!customWidth && fImage != null) { width = fImage.getWidth(this); } if (width <= 0) { width = DEFAULT_WIDTH; } if (fImage != null) { if (customHeight && customWidth) { Toolkit.getDefaultToolkit().prepareImage(fImage, height, width, this); } else { Toolkit.getDefaultToolkit().prepareImage(fImage, -1, -1, this); } } } finally { synchronized (this) { bLoading = false; if (customHeight || fHeight == 0) { fHeight = height; } if (customWidth || fWidth == 0) { fWidth = width; } } } }
From source file:org.openhab.binding.plum.PlumActiveBinding.java
@Override public void updated(Dictionary<String, ?> properties) throws ConfigurationException { logger.warn(//from w w w .jav a 2 s . c om "The Plum Binding does not support runtime updates. Restart OpenHAB for item changes to take effect"); HashMap<String, String> newConfig = new HashMap<String, String>(); if (m_config == null) { logger.debug("seems like our configuration has been erased, will reset everything!"); // turn config into new HashMap for (Enumeration<String> e = properties.keys(); e.hasMoreElements();) { String key = e.nextElement(); String value = properties.get(key).toString(); newConfig.put(key, value); } m_config = newConfig; if (m_config.containsKey("refresh")) { try { m_refreshInterval = Long.parseLong(m_config.get("refresh")); setProperlyConfigured(true); } catch (NumberFormatException e) { logger.error( "Are you sure you provided a numerical value for the openhab.cfg option plum:refresh?"); } } } }
From source file:net.wasdev.wlp.netflixoss.archaius.Activator.java
@Override public void updated(Dictionary<String, ?> properties) throws ConfigurationException { LOGGER.entering(CLASSNAME, "updated", properties); try {//from w ww .j av a 2 s. co m if (properties != null) { ServiceReference configurationAdminReference = bContext .getServiceReference(ConfigurationAdmin.class.getName()); if (configurationAdminReference != null) { ConfigurationAdmin configAdmin = (ConfigurationAdmin) bContext .getService(configurationAdminReference); Set<String> nestedKeys = new HashSet<String>(); Enumeration<String> keys = properties.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); Object val = properties.get(key); if (val instanceof String[]) { nestedKeys.addAll(generateKeyVals(configAdmin, key, (String[]) val)); } } for (Iterator<String> it = configuration.getKeys(); it.hasNext();) { String key = it.next(); if (!nestedKeys.contains(key)) { LOGGER.fine("Removing key \'" + key + "\'"); configuration.clearProperty(key); } } } } else { LOGGER.fine("Removing all keys"); configuration.clear(); } } catch (Exception e) { RuntimeException re = new RuntimeException("Failed to retrieve properties", e); LOGGER.throwing(CLASSNAME, "updated", re); throw re; } LOGGER.exiting(CLASSNAME, "updated"); }
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;/*from ww w .ja v a 2s.com*/ } 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.openhab.binding.epsonprojector.internal.EpsonProjectorBinding.java
/** * @{inheritDoc//from ww w .j a v a 2s . c o m */ @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 = (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.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); } }