List of usage examples for java.util Dictionary get
public abstract V get(Object key);
From source file:org.openhab.binding.aleoncean.internal.AleonceanBinding.java
@Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); Object val = config.get(key); LOGGER.debug("Parse config: {}; {}", key, val); }//from w ww. ja v a 2 s. c om WorkerReply reply; /* * Set the ESP3 port. */ final String valuePort = (String) config.get(CONFIG_PORT); if (StringUtils.isBlank(valuePort)) { LOGGER.warn("You need to setup the port that should be used for the ESP3 interface."); return; } reply = worker.addAndWaitForReply(new WorkerItemESP3Port(valuePort), 1, TimeUnit.MINUTES); if (reply.getReplyCode() != WorkerReplyCode.OK) { LOGGER.warn("Something went wrong ({}) enqueue set ESP3 port.", reply.getReplyCode()); return; } /* * Set the base ID if entry is available. */ final String valueBaseId = (String) config.get(CONFIG_BASEID); if (StringUtils.isNotBlank(valueBaseId)) { try { EnOceanId baseId = new EnOceanId(valueBaseId); reply = worker.addAndWaitForReply(new WorkerItemSetBaseId(baseId), 1, TimeUnit.MINUTES); if (reply.getReplyCode() != WorkerReplyCode.OK) { LOGGER.warn("Something went wrong ({}) set base id.", reply.getReplyCode()); return; } } catch (IllegalArgumentException ex) { LOGGER.warn("Something went wrong parsing the base id.", ex); return; } } LOGGER.debug("The configuration was successfully updated."); // Seems only to be used by AbstractActiveBinding and not by AbstractBinding. //setProperlyConfigured(true); } else { LOGGER.warn( "You need to set at least the port for ESP3 hardware if you want to use the aleoncean binding."); } }
From source file:org.openhab.binding.samsungac.internal.SamsungAcBinding.java
/** * @{inheritDoc/* w w w.ja v a 2 s . c o m*/ */ public void updated(Dictionary<String, ?> config) throws ConfigurationException { Enumeration<String> keys = config.keys(); String refreshIntervalString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); logger.info("Refresh interval set to " + refreshIntervalString + " ms"); } else { logger.info("No refresh interval configured, using default: " + refreshInterval + " ms"); } Map<String, AirConditioner> hosts = new HashMap<String, AirConditioner>(); while (keys.hasMoreElements()) { String key = keys.nextElement(); logger.debug("Configuration key is: " + key); if ("service.pid".equals(key)) { continue; } String[] parts = key.split("\\."); String hostname = parts[0]; AirConditioner host = hosts.get(hostname); if (host == null) { host = new AirConditioner(); } String value = ((String) config.get(key)).trim(); if ("host".equals(parts[1])) { host.setIpAddress(value); } if ("mac".equals(parts[1])) { host.setMacAddress(value); } if ("token".equals(parts[1])) { host.setToken(value); } hosts.put(hostname, host); } nameHostMapper = hosts; if (nameHostMapper == null || nameHostMapper.size() == 0) { setProperlyConfigured(false); Map<String, Map<String, String>> discovered = SsdpDiscovery.discover(); if (discovered != null && discovered.size() > 0) { for (Map<String, String> ac : discovered.values()) { if (ac.get("IP") != null && ac.get("MAC_ADDR") != null) logger.warn( "We found air conditioner. Please put the following in your configuration file: " + "\r\n samsungac:<ACNAME>.host=" + ac.get("IP") + "\r\n samsungac:<ACNAME>.mac=" + ac.get("MAC_ADDR")); } } else { logger.warn("No Samsung Air Conditioner has been configured, and we could not find one either"); } } else { setProperlyConfigured(true); } }
From source file:org.apache.ace.configurator.ConfiguratorTest.java
@Test(groups = { UNIT }) public void testPropertySubstitution() throws Exception { String pid = "test-subst"; Properties initial = new Properties(); initial.put("key1", "leading ${foo.${bar}} middle ${baz} trailing"); initial.put("bar", "a"); initial.put("foo.a", "text"); initial.put("baz", "word"); // ACE-401: use some weird log4j conversion pattern in our config file, should not confuse the Configurator's // substitution algorithm... initial.put("key2", "%d{ISO8601} | %-5.5p | %C | %X{bundle.name} | %m%n"); // unknown and partially unknown variables shouldn't get substituted... initial.put("key3", "${qux} ${quu.${bar}} ${baz.${bar}}"); saveConfiguration(pid, initial);//from w ww . j a v a 2 s.co m Dictionary<String, ?> config = getAndWaitForConfigurationUpdate(pid); assertNotNull(config, "No configuration received from configurator"); assertEquals(config.get("key1"), "leading text middle word trailing", "Substitution failed!"); assertEquals(config.get("key2"), "%d{ISO8601} | %-5.5p | %C | %X{bundle.name} | %m%n", "Substitution failed!"); assertEquals(config.get("key3"), "${qux} ${quu.${bar}} ${baz.${bar}}", "Substitution failed!"); }
From source file:org.openhab.binding.intertechno.internal.CULIntertechnoBinding.java
/** * @{inheritDoc//www. j a v a2 s . co m */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { // to override the default refresh interval one has to add a // parameter to openhab.cfg like // <bindingName>:refresh=<intervalInMs> String refreshIntervalString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } Integer repititions = parseOptionalNumericParameter(KEY_REPITIONS, config); if (repititions != null) { this.repititions = repititions.intValue(); } Integer wavelength = parseOptionalNumericParameter(KEY_WAVE_LENGTH, config); if (wavelength != null) { this.wavelength = wavelength.intValue(); } // Parse device last, so we already know all relevant parameter String deviceName = (String) config.get(KEY_DEVICE_NAME); if (StringUtils.isEmpty(deviceName)) { setProperlyConfigured(false); throw new ConfigurationException(KEY_DEVICE_NAME, "The device mustn't be empty"); } else { setNewDeviceName(deviceName); } setProperlyConfigured(true); } }
From source file:org.apache.ace.configurator.ConfiguratorTest.java
@Test(groups = { UNIT }) public void testPropertySubstitutionFromContext() throws Exception { String pid = "test-subst"; Properties initialConfiguration = createProperties(); initialConfiguration.put("subst", "${contextProp}"); saveConfiguration(pid, initialConfiguration); Dictionary<String, ?> configuration = getAndWaitForConfigurationUpdate(pid); assertNotNull(configuration, "No configuration received from configurator"); assertEquals(configuration.get("subst"), "contextVal", "Substitution failed"); }
From source file:org.eclipse.virgo.kernel.artifact.bundle.BundleBridgeTests.java
@Test public void testBuildDictionary() throws ArtifactGenerationException, IOException { File testFile = new File(System.getProperty("user.home") + "/virgo-build-cache/ivy-cache/repository/org.eclipse.virgo.mirrored/javax.servlet/3.0.0.v201112011016/javax.servlet-3.0.0.v201112011016.jar"); ArtifactDescriptor inputArtefact = BUNDLE_BRIDGE.generateArtifactDescriptor(testFile); Dictionary<String, String> dictionary = BundleBridge.convertToDictionary(inputArtefact); JarFile testJar = new JarFile(testFile); Attributes attributes = testJar.getManifest().getMainAttributes(); testJar.close();/*from w w w. j a v a 2 s . c om*/ assertEquals("Failed to match regenerated " + Constants.BUNDLE_SYMBOLICNAME, dictionary.get(Constants.BUNDLE_SYMBOLICNAME), attributes.getValue(Constants.BUNDLE_SYMBOLICNAME)); assertEquals("Failed to match regenerated " + Constants.BUNDLE_VERSION, dictionary.get(Constants.BUNDLE_VERSION), attributes.getValue(Constants.BUNDLE_VERSION)); assertEquals("Failed to match regenerated " + BUNDLE_MANIFEST_VERSION_HEADER_NAME, dictionary.get(BUNDLE_MANIFEST_VERSION_HEADER_NAME), attributes.getValue(BUNDLE_MANIFEST_VERSION_HEADER_NAME)); assertEquals("Failed to match regenerated " + BUNDLE_NAME_HEADER_NAME, dictionary.get(BUNDLE_NAME_HEADER_NAME), attributes.getValue(BUNDLE_NAME_HEADER_NAME)); }
From source file:org.openhab.binding.yamahareceiver.internal.YamahaReceiverBinding.java
@Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { logger.debug(BINDING_NAME + " updated"); try {/*from w w w. j av a 2 s. co m*/ // Process device configuration if (config != null) { String refreshIntervalString = (String) config.get("refresh"); if (StringUtils.isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } // parse all configured receivers // ( yamahareceiver:<uid>.host=10.0.0.2 ) Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (key.endsWith(CONFIG_KEY_HOST)) { // parse host String host = (String) config.get(key); int separatorIdx = key.indexOf('.'); // no uid => one device => use default UID String uid = separatorIdx == -1 ? DEFAULT_DEVICE_UID : key.substring(0, separatorIdx); // proxy is stateless. keep them in a map in the // binding. proxies.put(uid, new YamahaReceiverProxy(host)); } } setProperlyConfigured(true); } } catch (Throwable t) { logger.error("Error configuring " + getName(), t); } }
From source file:net.cellar.hazelcast.HazelcastGroupManager.java
public void init() throws Exception { //Add group to configuration try {//from w w w . j a va 2 s . c o m Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE); Dictionary<String, String> properties = configuration.getProperties(); String groups = properties.get(Configurations.GROUPS_KEY); Set<String> groupNames = convertStringToSet(groups); if (groupNames != null && !groupNames.isEmpty()) { for (String groupName : groupNames) { registerGroup(groupName); } } } catch (IOException e) { logger.error("Error reading group configuration"); } }
From source file:org.inaetics.pubsub.impl.discovery.etcd.EtcdDiscoveryManager.java
/** * Implementation of ManagedService/*w w w . j a v a2 s . c om*/ */ @Override public void updated(Dictionary<String, ?> properties) throws ConfigurationException { if (properties != null) { if (properties.get("url") != null) { this.etcdUrl = (String) properties.get("url"); } if (properties.get("TTL") != null) { this.TTL = (Integer) properties.get("TTL"); } if (properties.get("TTLRefresh") != null) { this.TTLRefresh = (Integer) properties.get("TTLRefresh"); } } }
From source file:com.adobe.acs.commons.httpcache.store.jcr.impl.JCRHttpCacheStoreImpl.java
@Activate protected void activate(ComponentContext context) { Dictionary<?, ?> properties = context.getProperties(); cacheRootPath = PropertiesUtil.toString(properties.get(PN_ROOTPATH), DEFAULT_ROOTPATH) + "/" + JCRHttpCacheStoreConstants.ROOT_NODE_NAME; bucketTreeDepth = PropertiesUtil.toInteger(properties.get(PN_BUCKETDEPTH), DEFAULT_BUCKETDEPTH); deltaSaveThreshold = PropertiesUtil.toInteger(properties.get(PN_SAVEDELTA), DEFAULT_SAVEDELTA); expireTimeInSeconds = PropertiesUtil.toInteger(properties.get(PN_EXPIRETIMEINSECONDS), DEFAULT_EXPIRETIMEINSECONDS); }