List of usage examples for java.util Dictionary get
public abstract V get(Object key);
From source file:org.openhab.binding.plugwise.internal.PlugwiseBinding.java
@SuppressWarnings("rawtypes") @Override/*from ww w . ja v a 2 s . c om*/ public void updated(Dictionary config) throws ConfigurationException { if (config != null) { // First of all make sure the Stick gets set up 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; } Matcher matcher = EXTRACT_PLUGWISE_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { logger.error("given plugwise-config-key '" + key + "' does not follow the expected pattern '<PlugwiseId>.<mac|port|interval>'"); continue; } matcher.reset(); matcher.find(); String plugwiseID = matcher.group(1); if (plugwiseID.equals("stick")) { if (stick == null) { String configKey = matcher.group(2); String value = (String) config.get(key); if ("port".equals(configKey)) { stick = new Stick(value, this); logger.info("Plugwise added Stick connected to serial port {}", value); } else if ("interval".equals(configKey)) { // do nothing for now. we will set in the second run } else if ("retries".equals(configKey)) { // do nothing for now. we will set in the second run } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } } } if (stick != null) { // re-run through the configuration and setup the remaining devices 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_PLUGWISE_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { logger.error("given plugwise-config-key '" + key + "' does not follow the expected pattern '<PlugwiseId>.<mac|port>'"); continue; } matcher.reset(); matcher.find(); String plugwiseID = matcher.group(1); if (plugwiseID.equals("stick")) { String configKey = matcher.group(2); String value = (String) config.get(key); if ("interval".equals(configKey)) { stick.setInterval(Integer.valueOf(value)); logger.info("Setting the interval to send ZigBee PDUs to {} ms", value); } else if ("retries".equals(configKey)) { stick.setRetries(Integer.valueOf(value)); logger.info("Setting the maximum number of attempts to send a message to ", value); } else if ("port".equals(configKey)) { //ignore } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } PlugwiseDevice device = stick.getDeviceByName(plugwiseID); if (device == null && !plugwiseID.equals("stick")) { String configKey = matcher.group(2); String value = (String) config.get(key); String MAC = null; if ("mac".equals(configKey)) { MAC = value; } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } if (!MAC.equals("")) { if (plugwiseID.equals("circleplus")) { if (stick.getDeviceByMAC(MAC) == null) { device = new CirclePlus(MAC, stick); logger.info("Plugwise added Circle+ with MAC address: {}", MAC); } } else { if (stick.getDeviceByMAC(MAC) == null) { device = new Circle(MAC, stick, plugwiseID); logger.info("Plugwise added Circle with MAC address: {}", MAC); } } stick.plugwiseDeviceCache.add(device); } } } setProperlyConfigured(true); } else { logger.error("Plugwise needs at least one Stick in order to operate"); } } }
From source file:org.codice.ddf.admin.core.impl.AdminConsoleService.java
/** * @see AdminConsoleServiceMBean#updateForLocation(java.lang.String, java.lang.String, * java.util.Map)/* ww w . j a v a2 s. com*/ */ public void updateForLocation(final String pid, String location, Map<String, Object> configurationTable) throws IOException { if (pid == null || pid.length() < 1) { throw loggedException(ILLEGAL_PID_MESSAGE); } if (configurationTable == null) { throw loggedException(ILLEGAL_TABLE_MESSAGE); } final Configuration config = configurationAdmin.getConfiguration(pid, location); if (isPermittedToViewService(config.getPid())) { final Metatype metatype = configurationAdminImpl.findMetatypeForConfig(config); if (metatype == null) { throw loggedException("Could not find metatype for " + pid); } final List<Map.Entry<String, Object>> configEntries = new ArrayList<>(); CollectionUtils.addAll(configEntries, configurationTable.entrySet().iterator()); CollectionUtils.transform(configEntries, new CardinalityTransformer(metatype.getAttributeDefinitions(), pid)); final Dictionary<String, Object> configProperties = config.getProperties(); final Dictionary<String, Object> newConfigProperties = (configProperties != null) ? configProperties : new Hashtable<>(); // If the configuration entry is a password, and its updated configuration value is // "password", do not update the password. for (Map.Entry<String, Object> configEntry : configEntries) { final String configEntryKey = configEntry.getKey(); Object configEntryValue = sanitizeUIConfiguration(pid, configEntryKey, configEntry.getValue()); if (configEntryValue.equals("password")) { for (Map<String, Object> metatypeProperties : metatype.getAttributeDefinitions()) { if (metatypeProperties.get("id").equals(configEntry.getKey()) && AttributeDefinition.PASSWORD == (Integer) metatypeProperties.get("type") && configProperties != null) { configEntryValue = configProperties.get(configEntryKey); break; } } } newConfigProperties.put(configEntryKey, configEntryValue); } config.update(newConfigProperties); } }
From source file:org.apache.felix.webconsole.internal.compendium.ConfigManager.java
private Dictionary mergeWithMetaType(Dictionary propsDictionary, ObjectClassDefinition classDef, JSONWriter jsonWriter) throws JSONException { if (propsDictionary == null) { propsDictionary = new Hashtable(); }//w w w . j a va2 s.c o m if (classDef != null) { jsonWriter.key("title"); jsonWriter.value(classDef.getName()); if (classDef.getDescription() != null) { jsonWriter.key("description"); jsonWriter.value(classDef.getDescription()); } AttributeDefinition[] currAttrDef = classDef.getAttributeDefinitions(ObjectClassDefinition.ALL); if (currAttrDef != null) { JSONArray propertyList = new JSONArray(); for (int i = 0; i < currAttrDef.length; i++) { jsonWriter.key(currAttrDef[i].getID()); jsonWriter.object(); Object idValue = propsDictionary.get(currAttrDef[i].getID()); if (idValue == null) { idValue = currAttrDef[i].getDefaultValue(); if (idValue == null) { if (currAttrDef[i].getCardinality() == 0) { idValue = ""; } else { idValue = new String[0]; } } } jsonWriter.key("name"); jsonWriter.value(currAttrDef[i].getName()); jsonWriter.key("type"); if (currAttrDef[i].getOptionLabels() != null && currAttrDef[i].getOptionLabels().length > 0) { jsonWriter.object(); jsonWriter.key("labels"); jsonWriter.value(Arrays.asList(currAttrDef[i].getOptionLabels())); jsonWriter.key("values"); jsonWriter.value(Arrays.asList(currAttrDef[i].getOptionValues())); jsonWriter.endObject(); } else { jsonWriter.value(currAttrDef[i].getType()); } if (currAttrDef[i].getCardinality() == 0) { // scalar if (idValue instanceof Vector) { idValue = ((Vector) idValue).get(0); } else if (idValue.getClass().isArray()) { idValue = Array.get(idValue, 0); } jsonWriter.key("value"); jsonWriter.value(idValue); } else { if (idValue instanceof Vector) { idValue = new JSONArray((Vector) idValue); } else if (idValue.getClass().isArray()) { idValue = new JSONArray(Arrays.asList((Object[]) idValue)); } else { JSONArray tmp = new JSONArray(); tmp.put(idValue); idValue = tmp; } jsonWriter.key("values"); jsonWriter.value(idValue); } if (currAttrDef[i].getDescription() != null) { jsonWriter.key("description"); jsonWriter.value(currAttrDef[i].getDescription()); } jsonWriter.endObject(); propertyList.put(currAttrDef[i].getID()); } jsonWriter.key("propertylist"); jsonWriter.value(propertyList); } // nothing more to display propsDictionary = null; } return propsDictionary; }
From source file:org.ops4j.pax.web.extender.war.internal.WebXmlObserver.java
private void fireEvent(String topic, Bundle bundle, Dictionary<String, Object> failure) { if (eventAdminService != null) { Dictionary<String, Object> properties = new Hashtable<String, Object>(); properties.put("bundle.symbolicName", bundle.getSymbolicName()); properties.put("bundle.id", bundle.getBundleId()); properties.put("bundle", bundle); properties.put("bundle.version", bundle.getHeaders().get(Constants.BUNDLE_VERSION)); String webContextPath = (String) bundle.getHeaders().get("Web-ContextPath"); if (webContextPath == null || webContextPath.length() == 0) webContextPath = (String) bundle.getHeaders().get("Webapp-Context"); //PAX fallback properties.put("context.path", webContextPath); properties.put("timestamp", System.currentTimeMillis()); properties.put("extender.bundle", bundleContext.getBundle()); properties.put("extender.bundle.id", bundleContext.getBundle().getBundleId()); properties.put("extender.bundle.symbolicName", bundleContext.getBundle().getSymbolicName()); properties.put("extender.bundle.version", bundleContext.getBundle().getHeaders().get(Constants.BUNDLE_VERSION)); if (failure != null) { Enumeration<String> keys = failure.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); properties.put(key, failure.get(key)); }//from w ww . j av a 2 s.c om } Event event = new Event(topic, properties); this.eventAdminService.postEvent(event); } if (logService != null) { this.logService.log(LogService.LOG_DEBUG, topic); } }
From source file:org.openhab.binding.pulseaudio.internal.PulseaudioBinding.java
@SuppressWarnings("rawtypes") public void updated(Dictionary<String, ?> config) throws ConfigurationException { 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; }/*w ww. j a va 2 s .com*/ Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key); if (!matcher.matches()) { logger.debug("given pulseaudio-config-key '" + key + "' does not follow the expected pattern '<serverId>.<host|port>'"); continue; } matcher.reset(); matcher.find(); String serverId = matcher.group(1); PulseaudioServerConfig serverConfig = serverConfigCache.get(serverId); if (serverConfig == null) { serverConfig = new PulseaudioServerConfig(); serverConfigCache.put(serverId, serverConfig); } String configKey = matcher.group(2); String value = (String) config.get(key); if ("host".equals(configKey)) { serverConfig.host = value; } else if ("port".equals(configKey)) { serverConfig.port = Integer.valueOf(value); } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } connectAllPulseaudioServers(); } }
From source file:org.openhab.binding.tcp.AbstractDatagramChannelBinding.java
/** * {@inheritDoc}//from w w w .j a va 2 s .c o m */ @SuppressWarnings("rawtypes") @Override public void updated(Dictionary config) throws ConfigurationException { if (config != null) { String bufferString = (String) config.get("buffersize"); if (StringUtils.isNotBlank(bufferString)) { maximumBufferSize = Integer.parseInt((bufferString)); } else { logger.info("The maximum buffer will be set to the default value of {}", maximumBufferSize); } String reconnectString = (String) config.get("retryinterval"); if (StringUtils.isNotBlank(reconnectString)) { reconnectInterval = Integer.parseInt((reconnectString)); } else { logger.info("The interval to retry connection setups will be set to the default value of {}", reconnectInterval); } String cronString = (String) config.get("reconnectcron"); if (StringUtils.isNotBlank(cronString)) { reconnectCron = cronString; } else { logger.info("The cron job to reset connections will be set to the default value of {}", reconnectCron); } String portString = (String) config.get("port"); if (StringUtils.isNotBlank(portString)) { listenerPort = Integer.parseInt((portString)); } else { logger.info("The port to listen for incoming connections will be set to the default value of {}", listenerPort); } String shareString = (String) config.get("itemsharedconnections"); if (StringUtils.isNotBlank(shareString)) { itemShareChannels = Boolean.parseBoolean(shareString); } else { logger.info("The setting to share channels within an Item will be set to the default value of {}", itemShareChannels); } String shareString2 = (String) config.get("bindingsharedconnections"); if (StringUtils.isNotBlank(shareString2)) { bindingShareChannels = Boolean.parseBoolean(shareString2); } else { logger.info( "The setting to share channels between the items with the same direction will be set to the default vaulue of {}", bindingShareChannels); } String shareString3 = (String) config.get("directionssharedconnections"); if (StringUtils.isNotBlank(shareString3)) { directionsShareChannels = Boolean.parseBoolean(shareString3); } else { logger.info( "The setting to share channels between directions will be set to the default vaulue of {}", bindingShareChannels); } String shareString4 = (String) config.get("addressmask"); if (StringUtils.isNotBlank(shareString4)) { useAddressMask = Boolean.parseBoolean(shareString4); } else { logger.info( "The setting to use address masks for incoming connections will be set to the default value of {}", useAddressMask); } if (useAddressMask && directionsShareChannels) { logger.warn( "The setting to share channels between directions is not compatible with the setting to use address masks. We will override the setting to share between directions"); directionsShareChannels = false; } if (bindingShareChannels && !itemShareChannels) { logger.warn( "The setting to share channels in the binding is not compatible with the setting to share channels within items. We will override the setting to share between items"); itemShareChannels = true; } if (directionsShareChannels && (!bindingShareChannels || !itemShareChannels)) { logger.warn( "The setting to share channels between directions is not compatible with the setting to share channels between items or within items. We will override the settings"); itemShareChannels = true; bindingShareChannels = true; } String refreshString = (String) config.get("refreshinterval"); if (StringUtils.isNotBlank(refreshString)) { refreshInterval = Long.parseLong((refreshString)); } else { logger.info("The refresh interval of the worker thread will be set to the default value of {}", refreshInterval); } if (listenerPort != 0) { configureListenerChannel(); } setProperlyConfigured(true); } }
From source file:org.openhab.io.squeezeserver.SqueezeServer.java
@Override public synchronized void updated(Dictionary<String, ?> config) throws ConfigurationException { // disconnect first in case the config has changed for an existing // instance//from w w w .j av a2 s . c om disconnect(); host = null; cliPort = DEFAULT_CLI_PORT; webPort = DEFAULT_WEB_PORT; language = DEFAULT_LANGUAGE; playersById.clear(); playersByMacAddress.clear(); if (config == null || config.isEmpty()) { logger.warn("Empty or null configuration. Ignoring."); return; } 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 serverMatcher = SERVER_CONFIG_PATTERN.matcher(key); Matcher playerMatcher = PLAYER_CONFIG_PATTERN.matcher(key); Matcher languageMatcher = LANGUAGE_CONFIG_PATTERN.matcher(key); String value = (String) config.get(key); if (serverMatcher.matches()) { String serverConfig = serverMatcher.group(2); if (serverConfig.equals("host") && StringUtils.isNotBlank(value)) { host = value; } else if (serverConfig.equals("cliport") && StringUtils.isNotBlank(value)) { cliPort = Integer.valueOf(value); } else if (serverConfig.equals("webport") && StringUtils.isNotBlank(value)) { webPort = Integer.valueOf(value); } } else if (playerMatcher.matches()) { String playerId = playerMatcher.group(1); String macAddress = value; SqueezePlayer player = new SqueezePlayer(this, playerId, macAddress); playersById.put(playerId.toLowerCase(), player); playersByMacAddress.put(macAddress.toLowerCase(), player); } else if (languageMatcher.matches() && StringUtils.isNotBlank(value)) { language = value; } else { logger.warn("Unexpected or unsupported configuration: " + key + ". Ignoring."); } } if (StringUtils.isEmpty(host)) throw new ConfigurationException("host", "No Squeeze Server host specified - this property is mandatory"); if (playersById.size() == 0) throw new ConfigurationException("host", "No Squeezebox players specified - there must be at least one player"); // attempt to connect using our new config connect(); }
From source file:org.openhab.binding.digitalstrom.internal.DigitalSTROMBinding.java
/** * @{inheritDoc/*from w w w. j a v a 2s.c o m*/ */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { String refreshIntervalStr = (String) config.get("refreshinterval"); if (StringUtils.isNotBlank(refreshIntervalStr)) { granularity = Integer.parseInt(refreshIntervalStr); } String uriStr = (String) config.get("uri"); if (StringUtils.isNotBlank(uriStr)) { uri = uriStr; } String connectTimeoutStr = (String) config.get("connectTimeout"); if (StringUtils.isNotBlank(connectTimeoutStr)) { connectTimeout = Integer.parseInt(connectTimeoutStr); } String readTimeoutStr = (String) config.get("readTimeout"); if (StringUtils.isNotBlank(readTimeoutStr)) { readTimeout = Integer.parseInt(readTimeoutStr); } String applicationTokenStr = (String) config.get("loginToken"); if (StringUtils.isNotBlank(applicationTokenStr)) { applicationToken = applicationTokenStr; } String userStr = (String) config.get("user"); if (StringUtils.isNotBlank(userStr)) { user = userStr; } String passwordStr = (String) config.get("password"); if (StringUtils.isNotBlank(passwordStr)) { password = passwordStr; } this.digitalSTROM = new DigitalSTROMJSONImpl(uri, connectTimeout, readTimeout); registerDigitalSTROMEventListener(); startSensorJobExecutor(); initializeDevices(); setProperlyConfigured(true); } }
From source file:org.energy_home.jemma.ah.internal.hac.lib.HacService.java
/** * Checks and adds or updates some properties contained in * the configuration. The props dictionary is changed. * /* w w w. j a va 2 s . c o m*/ * @param c * The Configuration Admin configuration. * @param props * The new property set * @param name * The name of the property of c that must not be overridden. * @throws HacException */ private void checkAndUpdateProperties(IManagedAppliance managedAppliance, Configuration c, Dictionary props) throws HacException { // don't override the appliance type property. Fatal error if // this property is not set for the appliance Dictionary oldProps = c.getProperties(); String applianceType = (String) oldProps.get(IAppliance.APPLIANCE_TYPE_PROPERTY); if (applianceType == null) { // FIXME: nella configurazione NON compare mai la ah.app.type // property!!!!! Perche? LOG.warn(IAppliance.APPLIANCE_TYPE_PROPERTY + " property not found in record"); } // Restore some key properties: it seems it does not associate to new service registration properties // that are not included in last change to configuration (it also avoid to have some properties // can contains invalid values) props.put(IAppliance.APPLIANCE_TYPE_PROPERTY, managedAppliance.getDescriptor().getType()); props.put(IAppliance.APPLIANCE_PID, managedAppliance.getPid()); props.put(IAppliance.APPLIANCE_EPS_IDS_PROPERTY, managedAppliance.getEndPointIds()); props.put(IAppliance.APPLIANCE_EPS_TYPES_PROPERTY, managedAppliance.getEndPointTypes()); props.put(IAppliance.APPLIANCE_EPS_IDS_PROPERTY, managedAppliance.getEndPointIds()); props.put(IAppliance.APPLIANCE_EPS_TYPES_PROPERTY, managedAppliance.getEndPointTypes()); Dictionary customConfig = managedAppliance.getCustomConfiguration(); if (customConfig != null) { for (Enumeration e = customConfig.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); // Custom properties that are invalid are filtered if (key.startsWith(IAppliance.APPLIANCE_CUSTOM_PROPERTIES_PREXIF)) ; props.put(key, customConfig.get(key)); } } //TODO: check merge, 5 lines below were missing in 3.3.0 // For compatibility with old applications (i.e. green@home), appliance common property is always managed manageMultiEndPointConfiguration(props, oldProps, IAppliance.APPLIANCE_NAME_PROPERTY, IAppliance.END_POINT_NAMES_PROPERTY); manageMultiEndPointConfiguration(props, oldProps, IAppliance.APPLIANCE_CATEGORY_PID_PROPERTY, IAppliance.END_POINT_CATEGORY_PIDS_PROPERTY); manageMultiEndPointConfiguration(props, oldProps, IAppliance.APPLIANCE_LOCATION_PID_PROPERTY, IAppliance.END_POINT_LOCATION_PIDS_PROPERTY); manageMultiEndPointConfiguration(props, oldProps, IAppliance.APPLIANCE_ICON_PROPERTY, IAppliance.END_POINT_LOCATION_PIDS_PROPERTY); }
From source file:org.openhab.binding.tcp.AbstractSocketChannelBinding.java
/** * {@inheritDoc}/*from www . j av a 2 s .c o m*/ */ @SuppressWarnings("rawtypes") @Override public void updated(Dictionary config) throws ConfigurationException { if (config != null) { String bufferString = (String) config.get("buffersize"); if (StringUtils.isNotBlank(bufferString)) { maximumBufferSize = Integer.parseInt((bufferString)); } else { logger.info("The maximum buffer will be set to the default value of {}", maximumBufferSize); } String reconnectString = (String) config.get("retryinterval"); if (StringUtils.isNotBlank(reconnectString)) { reconnectInterval = Integer.parseInt((reconnectString)); } else { logger.info("The interval to retry connection setups will be set to the default value of {}", reconnectInterval); } String cronString = (String) config.get("reconnectcron"); if (StringUtils.isNotBlank(cronString)) { reconnectCron = cronString; } else { logger.info("The cron job to reset connections will be set to the default value of {}", reconnectCron); } String queueString = (String) config.get("queue"); if (StringUtils.isNotBlank(queueString)) { queueUntilConnected = Boolean.parseBoolean(queueString); } else { logger.info( "The setting to queue write operation until a channel gets connected will be set to the default value of {}", queueUntilConnected); } String portString = (String) config.get("port"); if (StringUtils.isNotBlank(portString)) { listenerPort = Integer.parseInt((portString)); } else { logger.info("The port to listen for incoming connections will be set to the default value of {}", listenerPort); } String shareString = (String) config.get("itemsharedconnections"); if (StringUtils.isNotBlank(shareString)) { itemShareChannels = Boolean.parseBoolean(shareString); } else { logger.info("The setting to share channels within an Item will be set to the default value of {}", itemShareChannels); } String shareString2 = (String) config.get("bindingsharedconnections"); if (StringUtils.isNotBlank(shareString2)) { bindingShareChannels = Boolean.parseBoolean(shareString2); } else { logger.info( "The setting to share channels between the items with the same direction will be set to the default value of {}", bindingShareChannels); } String shareString3 = (String) config.get("directionssharedconnections"); if (StringUtils.isNotBlank(shareString3)) { directionsShareChannels = Boolean.parseBoolean(shareString3); } else { logger.info( "The setting to share channels between directions will be set to the default value of {}", bindingShareChannels); } String shareString4 = (String) config.get("addressmask"); if (StringUtils.isNotBlank(shareString4)) { useAddressMask = Boolean.parseBoolean(shareString4); } else { logger.info( "The setting to use address masks for incoming connections will be set to the default value of {}", useAddressMask); } if (useAddressMask && directionsShareChannels) { logger.warn( "The setting to share channels between directions is not compatible with the setting to use address masks. We will override the setting to share between directions"); directionsShareChannels = false; } if (bindingShareChannels && !itemShareChannels) { logger.warn( "The setting to share channels in the binding is not compatible with the setting to share channels within items. We will override the setting to share between items"); itemShareChannels = true; } if (directionsShareChannels && (!bindingShareChannels || !itemShareChannels)) { logger.warn( "The setting to share channels between directions is not compatible with the setting to share channels between items or within items. We will override the settings"); itemShareChannels = true; bindingShareChannels = true; } String refreshString = (String) config.get("refreshinterval"); if (StringUtils.isNotBlank(refreshString)) { refreshInterval = Long.parseLong((refreshString)); } else { logger.info("The refresh interval of the worker thread will be set to the default value of {}", refreshInterval); } if (listenerPort != 0) { configureListenerChannel(); } setProperlyConfigured(true); } }