List of usage examples for java.util Dictionary get
public abstract V get(Object key);
From source file:org.apache.felix.webconsole.internal.servlet.OsgiManager.java
/** * Returns the named property from the configuration. If the property does * not exist, the default value <code>def</code> is returned. * * @param config The properties from which to returned the named one * @param name The name of the property to return * @param def The default value if the named property does not exist * @return The value of the named property as a string or <code>def</code> * if the property does not exist *///from www. j a v a2s .c o m private int getProperty(Dictionary config, String name, int def) { Object value = config.get(name); if (value instanceof Number) { return ((Number) value).intValue(); } // try to convert the value to a number if (value != null) { try { return Integer.parseInt(value.toString()); } catch (NumberFormatException nfe) { // don't care } } // not a number, not convertible, not set, use default return def; }
From source file:org.apache.felix.webconsole.internal.compendium.ConfigManager.java
private void addConfigurationInfo(Configuration config, JSONWriter json, String locale) throws JSONException { if (config.getFactoryPid() != null) { json.key(factoryPID);// w ww . ja v a2 s. c om json.value(config.getFactoryPid()); } String currLocation; if (config.getBundleLocation() == null) { currLocation = "None"; } else { Bundle currBundle = this.getBundle(config.getBundleLocation()); Dictionary headersBook = currBundle.getHeaders(locale); String name = (String) headersBook.get(Constants.BUNDLE_NAME); if (name == null) { currLocation = currBundle.getSymbolicName(); } else { currLocation = name + " (" + currBundle.getSymbolicName() + ")"; } Version currVersion = Version.parseVersion((String) headersBook.get(Constants.BUNDLE_VERSION)); currLocation += ", Version " + currVersion.toString(); } json.key("bundleLocation"); json.value(currLocation); }
From source file:org.paxle.core.impl.RuntimeSettings.java
/** * @see ManagedService#updated(Dictionary) *//* w ww . jav a 2 s .c o m*/ @SuppressWarnings("unchecked") public void updated(Dictionary properties) throws ConfigurationException { if (properties == null) return; // loading current settings List<String> currentSettings = this.readSettings(); boolean changesDetected = false; // check all pre-defined options and update them in the currentSettings-list for (final OptEntry entry : OPTIONS) { final Object value = properties.get(entry.getPid()); if (value != null) changesDetected |= entry.update(currentSettings, value); } // check all other options and update the currentSettings-list final String valOthers = (String) properties.get(CM_OTHER_ENTRY.getPid()); if (valOthers != null) { final Set<String> otherSettings = new HashSet<String>(); final String[] valSplit = valOthers.split("[\\r\\n]"); for (int i = 0; i < valSplit.length; i++) { final String valOther = valSplit[i].trim(); if (valOther.length() > 0) try { for (String opt : StringTools.quoteSplit(valOther, " \t\f")) { opt = opt.trim(); if (opt.length() > 0) changesDetected |= updateSetting(otherSettings, opt); } } catch (ParseException e) { throw new ConfigurationException(CM_OTHER_ENTRY.getPid(), e.getMessage() + " at position " + e.getErrorOffset() + " in line " + i); } } /* check the currentSettings for any parameters that do not * - match a pre-defined option * - equal an user-specified option in otherSettings * and remove it. * This results in a list which only contains options which are either known or * explicitely specified by the user */ final Iterator<String> it = currentSettings.iterator(); outer: while (it.hasNext()) { final String setting = it.next(); for (final OptEntry entry : OPTIONS) if (setting.startsWith(entry.fixOpt)) continue outer; if (otherSettings.contains(setting)) continue; it.remove(); changesDetected = true; } // finally add all otherSettings to the currentSettings-list, which is for (final String setting : otherSettings) changesDetected |= updateSetting(currentSettings, setting); } if (changesDetected) { // write changes into file this.writeSettings(currentSettings); } }
From source file:org.openhab.binding.netatmo.internal.NetatmoBinding.java
/** * {@inheritDoc}/* ww w .j a v a 2s. co m*/ */ @Override public void updated(final Dictionary<String, ?> config) throws ConfigurationException { if (config != null) { final String refreshIntervalString = (String) config.get(CONFIG_REFRESH); if (isNotBlank(refreshIntervalString)) { this.refreshInterval = Long.parseLong(refreshIntervalString); } Enumeration<String> configKeys = config.keys(); while (configKeys.hasMoreElements()) { String configKey = configKeys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if (CONFIG_REFRESH.equals(configKey) || "service.pid".equals(configKey)) { continue; } String userid; String configKeyTail; if (configKey.contains(".")) { String[] keyElements = configKey.split("\\."); userid = keyElements[0]; configKeyTail = keyElements[1]; } else { userid = DEFAULT_USER_ID; configKeyTail = configKey; } OAuthCredentials credentials = credentialsCache.get(userid); if (credentials == null) { credentials = new OAuthCredentials(); credentialsCache.put(userid, credentials); } String value = (String) config.get(configKeyTail); if (CONFIG_CLIENT_ID.equals(configKeyTail)) { credentials.clientId = value; } else if (CONFIG_CLIENT_SECRET.equals(configKeyTail)) { credentials.clientSecret = value; } else if (CONFIG_REFRESH_TOKEN.equals(configKeyTail)) { credentials.refreshToken = value; } else if (CONFIG_PRESSURE_UNIT.equals(configKeyTail)) { try { pressureUnit = NetatmoPressureUnit.fromString(value); } catch (IllegalArgumentException e) { throw new ConfigurationException(configKey, "the value '" + value + "' is not valid for the configKey '" + configKey + "'"); } } else if (CONFIG_UNIT_SYSTEM.equals(configKeyTail)) { try { unitSystem = NetatmoUnitSystem.fromString(value); } catch (IllegalArgumentException e) { throw new ConfigurationException(configKey, "the value '" + value + "' is not valid for the configKey '" + configKey + "'"); } } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } setProperlyConfigured(true); } }
From source file:org.openhab.binding.freeswitch.internal.FreeswitchBinding.java
/** * @{inheritDoc}/*from ww w . j a va 2 s. c om*/ */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { logger.trace("updated() is called!"); if (config != null) { startWatchdog(); port = DEFAULT_PORT; host = (String) config.get("host"); password = (String) config.get("password"); String portString = (String) config.get("port"); if (StringUtils.isNotBlank(portString)) port = Integer.parseInt(portString); eventCache = new LinkedHashMap<String, Channel>(); mwiCache = new HashMap<String, FreeswitchBinding.MWIModel>(); itemMap = new LinkedHashMap<String, LinkedList<FreeswitchBindingConfig>>(); try { connect(); } catch (InboundConnectionFailure e) { logger.error("Could not connect to freeswitch server", e); //clean up disconnect(); } } else { //if we no longer have a config, make sure we are not connected and //that our watchdog thread is not running. stopWatchdog(); disconnect(); } }
From source file:org.openhab.binding.mpower.internal.MpowerBinding.java
/** * @{inheritDoc/*from w w w . j a va 2s .c o 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.openhab.binding.nest.internal.NestBinding.java
/** * {@inheritDoc}/*from w w w . j a v a 2 s .c o 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 nest:refresh=120000 String refreshIntervalString = (String) config.get(CONFIG_REFRESH); if (isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } Enumeration<String> configKeys = config.keys(); while (configKeys.hasMoreElements()) { String configKey = (String) configKeys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if (CONFIG_REFRESH.equals(configKey) || "service.pid".equals(configKey)) { continue; } String userid = DEFAULT_USER_ID; String configKeyTail = configKey; OAuthCredentials credentials = credentialsCache.get(userid); if (credentials == null) { credentials = new OAuthCredentials(userid); credentialsCache.put(userid, credentials); } String value = (String) config.get(configKey); if (CONFIG_CLIENT_ID.equals(configKeyTail)) { credentials.clientId = value; } else if (CONFIG_CLIENT_SECRET.equals(configKeyTail)) { credentials.clientSecret = value; } else if (CONFIG_PIN_CODE.equals(configKeyTail)) { credentials.pinCode = value; } else { throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown"); } } // Verify the completeness of each OAuthCredentials entry // to make sure we can get started. boolean properlyConfigured = true; for (String userid : credentialsCache.keySet()) { OAuthCredentials oauthCredentials = getOAuthCredentials(userid); String userString = (DEFAULT_USER_ID.equals(userid)) ? "" : (userid + "."); if (oauthCredentials.clientId == null) { logger.error("Required nest:{}{} is missing.", userString, CONFIG_CLIENT_ID); properlyConfigured = false; break; } if (oauthCredentials.clientSecret == null) { logger.error("Required nest:{}{} is missing.", userString, CONFIG_CLIENT_SECRET); properlyConfigured = false; break; } if (oauthCredentials.pinCode == null) { logger.error("Required nest:{}{} is missing.", userString, CONFIG_PIN_CODE); properlyConfigured = false; break; } // Load persistently stored values for this credential set oauthCredentials.load(); } setProperlyConfigured(properlyConfigured); } }
From source file:com.metaparadigm.jsonrpc.DictionarySerializer.java
public Object marshall(SerializerState state, Object o) throws MarshallException { Dictionary ht = (Dictionary) o; JSONObject obj = new JSONObject(); JSONObject mapdata = new JSONObject(); if (ser.getMarshallClassHints()) try {// www.j a va2s .c o m obj.put("javaClass", o.getClass().getName()); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { obj.put("map", mapdata); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Object key = null; Object val = null; try { Enumeration en = ht.keys(); while (en.hasMoreElements()) { key = en.nextElement(); val = ht.get(key); // only support String keys JSONObject put = mapdata.put(key.toString(), ser.marshall(state, val)); } } catch (MarshallException e) { throw new MarshallException("map key " + key + " " + e.getMessage()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return obj; }
From source file:org.codice.ddf.ui.admin.api.ConfigurationAdmin.java
/** * @see ConfigurationAdminMBean#getPropertiesForLocation(java.lang.String, java.lang.String) *///from w ww. j a v a 2s. c o m public Map<String, Object> getPropertiesForLocation(String pid, String location) throws IOException { if (pid == null || pid.length() < 1) { throw new IOException("Argument pid cannot be null or empty"); } Map<String, Object> propertiesTable = new HashMap<>(); Configuration config = configurationAdmin.getConfiguration(pid, location); Dictionary<String, Object> properties = config.getProperties(); if (properties != null) { Enumeration<String> keys = properties.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); propertiesTable.put(key, properties.get(key)); } } return propertiesTable; }
From source file:org.paxle.core.impl.MWComponent.java
@SuppressWarnings("unchecked") public void updated(Dictionary configuration) throws ConfigurationException { if (configuration == null) { /*// w w w. ja v a2 s . c om * Generate default configuration */ configuration = this.getDefaults(); } /* * Thread pool configuration */ Integer minIdle = (Integer) configuration.get(getFullPropertyName(PROP_POOL_MIN_IDLE)); this.pool.setMinIdle((minIdle == null) ? 0 : minIdle.intValue()); Integer maxIdle = (Integer) configuration.get(getFullPropertyName(PROP_POOL_MAX_IDLE)); this.pool.setMaxIdle((maxIdle == null) ? 8 : maxIdle.intValue()); Integer maxActive = (Integer) configuration.get(getFullPropertyName(PROP_POOL_MAX_ACTIVE)); this.pool.setMaxActive((maxActive == null) ? 8 : maxActive.intValue()); /* * Delay between job execution */ Integer delay = (Integer) configuration.get(getFullPropertyName(PROP_DELAY)); this.master.setDelay((delay == null) ? -1 : delay.intValue()); /* * Component actiontion status */ final Boolean active = (Boolean) configuration.get(getFullPropertyName(PROP_STATE_ACTIVE)); if (active != null) { this.stateCode = "OK"; this.setActiveState(active); } }