List of usage examples for java.util Dictionary keys
public abstract Enumeration<K> keys();
From source file:org.energy_home.jemma.ah.internal.greenathome.GreenathomeAppliance.java
public static Map convertToMap(Dictionary source) { Map sink = new HashMap(source.size()); for (Enumeration keys = source.keys(); keys.hasMoreElements();) { Object key = keys.nextElement(); sink.put(key, source.get(key));//from w ww . j a v a 2 s . co m } return sink; }
From source file:org.opencastproject.capture.impl.SchedulerImpl.java
/** * Updates the scheduler with new configuration data. {@inheritDoc} * /*from www .ja v a 2 s. c o m*/ * @see org.osgi.service.cm.ManagedService#updated(Dictionary) */ //@Override @SuppressWarnings("unchecked") private void updated(Dictionary properties) throws ConfigurationException { log.debug("Scheduler updated."); if (properties == null) { log.debug("Null properties in updated!"); throw new ConfigurationException("Null properties in updated!", "null"); } else if (properties.size() == 0) { log.debug("0 size properties in updated!"); throw new ConfigurationException( "Properties object empty in updated, this should be a scheduler configuration!", "empty"); } // Clone the properties. Note that we can't use serialization to do this because the Dictionary above is actually a // org.apache.felix.cm.impl.CaseInsensitiveDictionary schedProps = new Properties(); Enumeration<String> keys = properties.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); schedProps.put(key, properties.get(key)); } try { localCalendarCacheURL = new File(configService.getItem(CaptureParameters.CAPTURE_SCHEDULE_CACHE_URL)) .toURI().toURL(); } catch (NullPointerException e) { log.warn("Invalid location specified for {} unable to cache scheduling data.", CaptureParameters.CAPTURE_SCHEDULE_CACHE_URL); } catch (MalformedURLException e) { log.warn("Invalid location specified for {} unable to cache scheduling data.", CaptureParameters.CAPTURE_SCHEDULE_CACHE_URL); } updateCalendar(); }
From source file:org.galicaster.dashboard.DashboardService.java
@SuppressWarnings("unchecked") protected void activate(ComponentContext cc) throws URISyntaxException { // Initialize the object to hold the agent's properties agentPasswords = new Properties(); if ((cc == null) || (cc.getProperties() == null)) { mode = MODE_DEFAULT;/*from www . j a v a 2 s. com*/ logger.debug("Setting default functioning mode: {}", mode.toString()); pingTimeout = PING_TIMEOUT_DEFAULT; logger.debug("Setting default ping timeout: {}", pingTimeout); snapshotTimeout = SNAPSHOT_TIMEOUT_DEFAULT; logger.debug("Setting default snapshot timeout: {}", snapshotTimeout); snapshotPeriod = SNAPSHOT_PERIOD_DEFAULT; logger.debug("Setting default snapshot period: {}", snapshotPeriod); maxConcurrentSnapshots = MAX_CONCURRENT_DEFAULT; logger.debug("Setting default maximum concurrent snapshots: {}", maxConcurrentSnapshots); defaultPassword = DEFAULT_PASSWORD_DEFAULT; logger.debug("Setting default VNC password default: {}", DEFAULT_PASSWORD_DEFAULT); } else { // Get the component properties Dictionary<String, Object> properties = cc.getProperties(); // Get the functioning mode. String strMode = (String) properties.get(MODE_PROPERTY); if (strMode != null) { try { mode = Mode.valueOf(strMode.toUpperCase()); } catch (IllegalArgumentException iae) { logger.warn("Invalid functioning mode found in configuration file: {}", strMode); mode = MODE_DEFAULT; logger.debug("Setting default functioning mode: {}", mode.toString()); } } // Read the properties that control the "snapshot taking" process try { pingTimeout = Integer.parseInt((String) properties.get(PING_TIMEOUT_PROPERTY)); } catch (Exception e) { pingTimeout = PING_TIMEOUT_DEFAULT; } try { snapshotTimeout = Integer.parseInt((String) properties.get(SNAPSHOT_TIMEOUT_PROPERTY)); } catch (Exception e) { pingTimeout = SNAPSHOT_TIMEOUT_DEFAULT; } try { snapshotPeriod = Long.parseLong((String) properties.get(SNAPSHOT_PERIOD_PROPERTY)); } catch (Exception e) { snapshotPeriod = SNAPSHOT_PERIOD_DEFAULT; } try { maxConcurrentSnapshots = Integer.parseInt((String) properties.get(MAX_CONCURRENT_PROPERTY)); } catch (Exception e) { maxConcurrentSnapshots = MAX_CONCURRENT_DEFAULT; } // Get the default VNC password, if it is defined in the config file defaultPassword = (String) properties.get(DEFAULT_PASSWORD_PROPERTY); if (defaultPassword == null) defaultPassword = DEFAULT_PASSWORD_DEFAULT; // Get the passwords per agent, if specified in the config file Pattern propertyPattern = Pattern.compile(PASSWORD_REGEXP); for (Enumeration<String> keys = properties.keys(); keys.hasMoreElements();) { String key = keys.nextElement(); Matcher match = propertyPattern.matcher(key); if (match.matches()) { agentPasswords.setProperty(match.group(1), (String) properties.get(match.group())); } } } // If the mode is PULL, set the security information and start the snapshot threads accordingly if (mode == Mode.PULL) { // Set security information this.systemAccount = cc.getBundleContext().getProperty("org.opencastproject.security.digest.user"); DefaultOrganization defaultOrg = new DefaultOrganization(); securityService.setOrganization(defaultOrg); securityService .setUser(new JaxbUser(systemAccount, defaultOrg, new JaxbRole(GLOBAL_ADMIN_ROLE, defaultOrg))); // Start the threads that take the snapshots periodicSnapshots = Executors.newScheduledThreadPool(maxConcurrentSnapshots); Map<String, Agent> knownAgents = captureAgentStateService.getKnownAgents(); Random randGen = new Random(); for (Map.Entry<String, Agent> entry : knownAgents.entrySet()) { SnapshotWithDeadline task = new SnapshotWithDeadline(entry.getValue(), tempDir, agentPasswords.getProperty(entry.getKey(), defaultPassword), snapshotTimeout, TimeUnit.SECONDS); periodicSnapshots.scheduleAtFixedRate(task, randGen.nextLong() % snapshotPeriod, snapshotPeriod, TimeUnit.SECONDS); } } logger.info("Galicaster Service activated"); }
From source file:org.openhab.binding.ecobee.internal.EcobeeBinding.java
/** * {@inheritDoc}// w w w.j ava2s .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 ecobee:refresh=240000 String refreshIntervalString = (String) config.get(CONFIG_REFRESH); if (isNotBlank(refreshIntervalString)) { refreshInterval = Long.parseLong(refreshIntervalString); } // to override the default HTTP timeout one has to add a // parameter to openhab.cfg like ecobee:timeout=20000 String timeoutString = (String) config.get(CONFIG_TIMEOUT); if (isNotBlank(timeoutString)) { AbstractRequest.setHttpRequestTimeout(Integer.parseInt(timeoutString)); } // to override the default usage of Fahrenheit one has to add a // parameter to openhab.cfg, as in ecobee:tempscale=C String tempScaleString = (String) config.get(CONFIG_TEMP_SCALE); if (isNotBlank(tempScaleString)) { try { Temperature.setLocalScale(Temperature.Scale.forValue(tempScaleString)); } catch (IllegalArgumentException iae) { throw new ConfigurationException(CONFIG_TEMP_SCALE, "Unsupported temperature scale '" + tempScaleString + "'."); } } 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) || CONFIG_TIMEOUT.equals(configKey) || CONFIG_TEMP_SCALE.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(userid); credentialsCache.put(userid, credentials); } String value = (String) config.get(configKey); if (CONFIG_APP_KEY.equals(configKeyTail)) { credentials.appKey = value; } else if (CONFIG_SCOPE.equals(configKeyTail)) { credentials.scope = 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.appKey == null) { logger.error("Required ecobee:{}{} is missing.", userString, CONFIG_APP_KEY); properlyConfigured = false; break; } if (oauthCredentials.scope == null) { logger.error("Required ecobee:{}{} is missing.", userString, CONFIG_SCOPE); properlyConfigured = false; break; } // Knowing this OAuthCredentials object is complete, load its tokens from persistent storage. oauthCredentials.load(); } setProperlyConfigured(properlyConfigured); } }
From source file:org.energy_home.jemma.ah.internal.greenathome.GreenathomeAppliance.java
public ArrayList getInquiredDevices() { synchronized (lockGatH) { String[] appliancePids = null; appliancePids = this.hacService.getInquiredAppliances(); ArrayList inquredDevices = new ArrayList(); if (fakeMode) { inquredDevices.add(this.getFakeAppliance()); } else {//from w w w . ja va2 s . c o m for (int i = 0; i < appliancePids.length; i++) { try { Dictionary c = this.hacService.getManagedConfiguration(appliancePids[i]); // those information that can cause marshalling problems // in JSON RPC. Hashtable config = new Hashtable(); Enumeration keys = c.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = c.get(key); if (key.equals(IAppliance.APPLIANCE_TYPE_PROPERTY)) { // !!! Energy@home webui compatibility String[] epsTypes = (String[]) config.get(IAppliance.APPLIANCE_EPS_TYPES_PROPERTY); value = encodeGenericApplianceType((String) value, epsTypes[1]); config.put(IAppliance.APPLIANCE_TYPE_PROPERTY, value); } else { config.put(key, value); } } inquredDevices.add(config); } catch (Exception e) { log.fatal("Unable to get Inquired Appliance " + appliancePids[i], e); } } } return inquredDevices; } }