List of usage examples for java.util Dictionary keys
public abstract Enumeration<K> keys();
From source file:org.codice.ddf.configuration.persistence.felix.FelixCfgPersistenceStrategy.java
@Override public void write(OutputStream out, Dictionary<String, Object> properties) throws IOException { Validate.notNull(out, "invalid null output stream"); Validate.notNull(properties, "invalid null properties"); final Properties props = new Properties(); final Enumeration<String> keys = properties.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); props.put(key, (String) properties.get(key)); }/* w w w.jav a 2s .c o m*/ props.save(out); }
From source file:org.codice.ddf.platform.io.CfgStrategy.java
@Override public void write(OutputStream out, Dictionary<String, Object> inputDictionary) throws IOException { notNull(out, "Output stream cannot be null"); notNull(inputDictionary, "Properties cannot be null"); final Properties props = new Properties(); final Enumeration<String> keys = inputDictionary.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); props.put(key, inputDictionary.get(key).toString()); }// w w w.java2 s. c o m props.save(out); }
From source file:org.codice.ddf.configuration.persistence.felix.FelixPersistenceStrategy.java
private void checkForInvalidProperties(Set<String> expectedPropertyName, Dictionary properties) throws ConfigurationFileException { if (properties.size() != expectedPropertyName.size()) { @SuppressWarnings("unchecked") Set<String> propertyNames = new HashSet<>(Collections.list(properties.keys())); LOGGER.error("Unable to convert all config file properties. One of [{}] is invalid", expectedPropertyName.removeAll(propertyNames)); throw new ConfigurationFileException("Unable to convert all config file properties."); }/*from ww w .j a va2 s. c om*/ }
From source file:org.openhab.binding.dmlsmeter.internal.DmlsMeterBinding.java
private Set<String> getNames(Dictionary<String, ?> config) { Set<String> set = new HashSet<String>(); 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) || "refresh".equals(key)) { continue; }//from w w w .j av a 2 s .c om Matcher meterMatcher = METER_CONFIG_PATTERN.matcher(key); if (!meterMatcher.matches()) { logger.debug("given config key '" + key + "' does not follow the expected pattern '<meterName>.<serialPort|baudRateChangeDelay|echoHandling>'"); continue; } meterMatcher.reset(); meterMatcher.find(); set.add(meterMatcher.group(1)); } return set; }
From source file:org.eclipse.virgo.ide.management.remote.StandardBundleAdmin.java
@ManagedOperation(description = "Returns the current OSGi Bundles") public Map<Long, Bundle> retrieveBundles() { Map<Long, Bundle> bundles = new HashMap<Long, Bundle>(); for (org.osgi.framework.Bundle b : this.bundleContext.getBundles()) { Object version = b.getHeaders().get("Bundle-Version"); Bundle bundle = new Bundle(Long.toString(b.getBundleId()), b.getSymbolicName(), version != null ? version.toString() : "0", getState(b), b.getLocation()); Dictionary<?, ?> headers = b.getHeaders(); Enumeration<?> keys = headers.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = headers.get(key); bundle.addHeader(key.toString(), value.toString()); }/*from ww w.j a va 2 s. c om*/ BundleDescription bundleDescription = this.platformAdmin.getState(false).getBundle(b.getBundleId()); ExportPackageDescription[] exportedPackages = bundleDescription.getExportPackages(); if (exportedPackages != null) { for (ExportPackageDescription exportedPackage : exportedPackages) { PackageExport packageExport = new PackageExport(exportedPackage.getName(), exportedPackage.getVersion() != null ? exportedPackage.getVersion().toString() : "0"); bundle.addPackageExport(packageExport); } } ExportPackageDescription[] visiblePackages = this.platformAdmin.getStateHelper() .getVisiblePackages(bundleDescription); if (visiblePackages != null) { for (ExportPackageDescription visiblePackage : visiblePackages) { PackageImport packageImport = new PackageImport(visiblePackage.getName(), visiblePackage.getVersion() != null ? visiblePackage.getVersion().toString() : "0", Long.toString(visiblePackage.getSupplier().getBundleId())); bundle.addPackageImport(packageImport); } } if (b.getRegisteredServices() != null) { for (ServiceReference ref : b.getRegisteredServices()) { org.eclipse.virgo.ide.management.remote.ServiceReference reference = new org.eclipse.virgo.ide.management.remote.ServiceReference( Type.REGISTERED, ref.getBundle().getBundleId(), OsgiServiceReferenceUtils.getServiceObjectClasses(ref)); Map<?, ?> props = OsgiServiceReferenceUtils.getServicePropertiesAsMap(ref); for (Object key : props.keySet()) { String value = props.get(key).toString(); if (props.get(key).getClass().isArray()) { value = Arrays.deepToString((Object[]) props.get(key)); } reference.addProperty(key.toString(), value); } if (ref.getUsingBundles() != null) { for (org.osgi.framework.Bundle usingBundle : ref.getUsingBundles()) { reference.addUsingBundle(usingBundle.getBundleId()); } } bundle.addRegisteredService(reference); } } if (b.getServicesInUse() != null) { for (ServiceReference ref : b.getServicesInUse()) { org.eclipse.virgo.ide.management.remote.ServiceReference reference = new org.eclipse.virgo.ide.management.remote.ServiceReference( Type.IN_USE, ref.getBundle().getBundleId(), OsgiServiceReferenceUtils.getServiceObjectClasses(ref)); Map<?, ?> props = OsgiServiceReferenceUtils.getServicePropertiesAsMap(ref); for (Object key : props.keySet()) { String value = props.get(key).toString(); if (props.get(key).getClass().isArray()) { value = Arrays.deepToString((Object[]) props.get(key)); } reference.addProperty(key.toString(), value); } if (ref.getUsingBundles() != null) { for (org.osgi.framework.Bundle usingBundle : ref.getUsingBundles()) { reference.addUsingBundle(usingBundle.getBundleId()); } } bundle.addUsingService(reference); } } bundles.put(Long.valueOf(bundle.getId()), bundle); } return bundles; }
From source file:org.openhab.binding.iec6205621meter.internal.Iec6205621MeterBinding.java
/** * Analyze configuration to get meter names * /* w ww . j a v a2s . c o m*/ * @return set of String of meter names */ private Set<String> getNames(Dictionary<String, ?> config) { Set<String> set = new HashSet<String>(); 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) || "refresh".equals(key)) { continue; } Matcher meterMatcher = METER_CONFIG_PATTERN.matcher(key); if (!meterMatcher.matches()) { logger.debug("given config key '" + key + "' does not follow the expected pattern '<meterName>.<serialPort|baudRateChangeDelay|echoHandling>'"); continue; } meterMatcher.reset(); meterMatcher.find(); set.add(meterMatcher.group(1)); } return set; }
From source file:edu.northwestern.bioinformatics.studycalendar.osgi.felixcm.internal.PscFelixPersistenceManager.java
@SuppressWarnings({ "unchecked" }) private void doStore(String pid, Dictionary values) { List<OsgiConfigurationProperty> existingProperties = getProperties(pid); Collection<String> newKeys = EnumerationUtils.toList(values.keys()); Collection<String> existingKeys = new HashSet<String>(); for (OsgiConfigurationProperty existingProperty : existingProperties) { String existingKey = existingProperty.getName(); if (newKeys.contains(existingKey)) { existingProperty.setValue(values.get(existingKey)); existingKeys.add(existingKey); } else {/*from w w w . j a va 2s. c o m*/ getHibernateTemplate().delete(existingProperty); } } for (String newKey : newKeys) { if (!EXCLUDED_PROPERTIES.contains(newKey) && !existingKeys.contains(newKey)) { getHibernateTemplate().save(OsgiConfigurationProperty.create(pid, newKey, values.get(newKey))); } } }
From source file:org.openhab.binding.ekozefir.internal.EkozefirBinding.java
/** * @{inheritDoc}/* w ww. j a va 2 s.c om*/ */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { Objects.requireNonNull(config); for (String configKey : Collections.list(config.keys())) { parseConfig(clearAndCheckConfig(configKey, (String) config.get(configKey))); } setProperlyConfigured(true); }
From source file:org.eclipse.swordfish.core.configuration.ManagedServiceAdapter.java
public void updated(Dictionary properties) throws ConfigurationException { Assert.notNull(delegate, "The ConfigurationConsumer delegate must be supplied"); if (properties == null) { delegate.onReceiveConfiguration(null); return;//from w w w . j a v a 2 s .c o m } Map configuration = new HashMap(); Enumeration e = properties.keys(); while (e.hasMoreElements()) { Object key = e.nextElement(); configuration.put(key, properties.get(key)); } LOG.info(String.format("Received configuration [%s] for the configurationConsumer with id = [%s] ", configuration.toString(), delegate.getId())); delegate.onReceiveConfiguration(configuration); }
From source file:com.github.lburgazzoli.karaf.common.cmd.AbstractManagedService.java
/** * * @param dictionary//from w ww . ja v a 2s. co m * @return */ protected Properties getConfiguration(Dictionary dictionary) { Properties props = null; if (dictionary != null) { LOGGER.debug("getConfiguration, dictionary={}", dictionary); Enumeration keys = dictionary.keys(); if (keys != null) { LOGGER.debug("getConfiguration, keys={}", dictionary); props = new Properties(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object val = dictionary.get(key); props.put(ObjectUtils.toString(key), ObjectUtils.toString(val, StringUtils.EMPTY)); } } } if (props == null) { LOGGER.warn("No configuration for {}", m_pid); } return props; }