Example usage for java.util Dictionary keys

List of usage examples for java.util Dictionary keys

Introduction

In this page you can find the example usage for java.util Dictionary keys.

Prototype

public abstract Enumeration<K> keys();

Source Link

Document

Returns an enumeration of the keys in this dictionary.

Usage

From source file:org.openhab.binding.plum.PlumActiveBinding.java

@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
    logger.warn(//from   w  ww . j a  v a  2s  .c om
            "The Plum Binding does not support runtime updates. Restart OpenHAB for item changes to take effect");
    HashMap<String, String> newConfig = new HashMap<String, String>();
    if (m_config == null) {
        logger.debug("seems like our configuration has been erased, will reset everything!");

        // turn config into new HashMap
        for (Enumeration<String> e = properties.keys(); e.hasMoreElements();) {
            String key = e.nextElement();
            String value = properties.get(key).toString();
            newConfig.put(key, value);
        }

        m_config = newConfig;

        if (m_config.containsKey("refresh")) {
            try {
                m_refreshInterval = Long.parseLong(m_config.get("refresh"));
                setProperlyConfigured(true);
            } catch (NumberFormatException e) {
                logger.error(
                        "Are you sure you provided a numerical value for the openhab.cfg option plum:refresh?");
            }
        }
    }

}

From source file:org.opendaylight.controller.cluster.datastore.DatastoreContextIntrospector.java

/**
 * Applies the given properties to the cached DatastoreContext and yields a new DatastoreContext
 * instance which can be obtained via {@link getContext}.
 *
 * @param properties the properties to apply
 * @return true if the cached DatastoreContext was updated, false otherwise.
 *///from ww w .  j av  a 2  s  . co m
public synchronized boolean update(Dictionary<String, Object> properties) {
    currentProperties = null;
    if (properties == null || properties.isEmpty()) {
        return false;
    }

    LOG.debug("In update: properties: {}", properties);

    ImmutableMap.Builder<String, Object> mapBuilder = ImmutableMap.<String, Object>builder();

    Builder builder = DatastoreContext.newBuilderFrom(context);

    final String dataStoreTypePrefix = context.getDataStoreName() + '.';

    List<String> keys = getSortedKeysByDatastoreType(Collections.list(properties.keys()), dataStoreTypePrefix);

    boolean updated = false;
    for (String key : keys) {
        Object value = properties.get(key);
        mapBuilder.put(key, value);

        // If the key is prefixed with the data store type, strip it off.
        if (key.startsWith(dataStoreTypePrefix)) {
            key = key.replaceFirst(dataStoreTypePrefix, "");
        }

        if (convertValueAndInvokeSetter(key, value, builder)) {
            updated = true;
        }
    }

    currentProperties = mapBuilder.build();

    if (updated) {
        context = builder.build();
    }

    return updated;
}

From source file:org.apache.felix.webconsole.internal.servlet.OsgiManager.java

private Dictionary toStringConfig(Dictionary config) {
    Dictionary stringConfig = new Hashtable();
    for (Enumeration ke = config.keys(); ke.hasMoreElements();) {
        Object key = ke.nextElement();
        stringConfig.put(key.toString(), String.valueOf(config.get(key)));
    }/* www  .  j  a v  a2s.c om*/
    return stringConfig;
}

From source file:org.apache.felix.webconsole.internal.core.BundlesServlet.java

private void listHeaders(JSONWriter jsonWriter, Bundle bundle) throws JSONException {
    JSONArray val = new JSONArray();

    Dictionary headers = bundle.getHeaders();
    Enumeration headerKey = headers.keys();
    while (headerKey.hasMoreElements()) {
        Object header = headerKey.nextElement();
        String value = String.valueOf(headers.get(header));
        // Package headers may be long, support line breaking by
        // ensuring blanks after comma and semicolon.
        value = value.replaceAll("([;,])", "$1 ");
        val.put(header + ": " + value);
    }/*ww w .  j a v a2s. co m*/

    jsonKeyVal(jsonWriter, "Manifest Headers", val);
}

From source file:org.codice.ddf.registry.source.configuration.SourceConfigurationHandler.java

private DictionaryMap<String, Object> getConfigurationsFromDictionary(Dictionary<String, Object> properties) {
    DictionaryMap<String, Object> configProperties = new DictionaryMap<>();

    Enumeration<String> enumeration = properties.keys();
    while (enumeration.hasMoreElements()) {
        String key = enumeration.nextElement();
        configProperties.put(key, properties.get(key));
    }//w  w  w.j  a  v a  2 s  .co  m

    return configProperties;
}

From source file:org.codice.ddf.admin.core.impl.ConfigurationAdminImpl.java

private void addConfigurationData(Service service, Configuration[] configs,
        Map<String, ObjectClassDefinition> objectClassDefinitions) {
    for (Configuration config : configs) {
        // ignore configuration object if it is invalid
        final String pid = config.getPid();
        if (!isAllowedPid(pid)) {
            continue;
        }/*from  w ww . j  av  a2s .  co m*/

        ConfigurationDetails configData = new ConfigurationDetailsImpl();
        configData.setId(pid);
        String fpid = config.getFactoryPid();
        if (fpid != null) {
            configData.setFactoryPid(fpid);
        }
        // insert an entry for the PID
        try {
            ObjectClassDefinition ocd = objectClassDefinitions.get(config.getPid());
            if (ocd != null) {
                configData.setName(ocd.getName());
            } else {
                // no object class definition, use plain PID
                configData.setName(pid);
            }
        } catch (IllegalArgumentException t) {
            // Catch exception thrown by getObjectClassDefinition so other configurations
            // are displayed
            // no object class definition, use plain PID
            configData.setName(pid);
        }

        final Bundle bundle = getBoundBundle(config);
        if (null != bundle) {
            configData.setBundle(bundle.getBundleId());
            configData.setBundleName(getName(bundle));
            configData.setBundleLocation(bundle.getLocation());
        }

        ConfigurationProperties propertiesTable = new ConfigurationPropertiesImpl();
        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));
            }
        }

        // If the configuration property is a password that has been set,
        // mask its value to "password" so that the real password value will be hidden.
        List<MetatypeAttribute> metatypeList = service.getAttributeDefinitions();
        metatypeList.stream().filter(metatype -> AttributeDefinition.PASSWORD == metatype.getType())
                .forEach(metatype -> {
                    setPasswordMask(metatype, propertiesTable);
                });

        configData.setConfigurationProperties(propertiesTable);

        Map<String, Object> pluginDataMap = getConfigurationPluginData(configData.getId(),
                Collections.unmodifiableMap(configData));
        if (pluginDataMap != null && !pluginDataMap.isEmpty()) {
            configData.putAll(pluginDataMap);
        }

        List<ConfigurationDetails> configurationDetails;
        if (service.containsKey(Service.CONFIGURATIONS)) {
            configurationDetails = service.getConfigurations();
        } else if (service.containsKey(Service.DISABLED_CONFIGURATIONS)) {
            configurationDetails = service.getDisabledConfigurations();
        } else {
            configurationDetails = new ArrayList<>();
        }

        configurationDetails.add(configData);
        if (configData.getId().contains(ConfigurationDetails.DISABLED_SERVICE_IDENTIFIER)) {
            configData.setEnabled(false);
        } else {
            configData.setEnabled(true);
        }
        service.setConfigurations(configurationDetails);
    }
}

From source file:org.codice.ddf.itests.common.ServiceManagerImpl.java

private void printInactiveBundles(Consumer<String> headerConsumer, BiConsumer<String, Object[]> logConsumer) {
    headerConsumer.accept("Listing inactive bundles");

    for (Bundle bundle : getBundleContext().getBundles()) {
        if (bundle.getState() != Bundle.ACTIVE) {
            Dictionary<String, String> headers = bundle.getHeaders();
            if (headers.get("Fragment-Host") != null) {
                continue;
            }//from ww  w .j  a  v  a 2  s . co  m

            StringBuilder headerString = new StringBuilder("[ ");
            Enumeration<String> keys = headers.keys();

            while (keys.hasMoreElements()) {
                String key = keys.nextElement();
                headerString.append(key).append("=").append(headers.get(key)).append(", ");
            }

            headerString.append(" ]");
            logConsumer.accept("\n\tBundle: {}_v{} | {}\n\tHeaders: {}",
                    new Object[] { bundle.getSymbolicName(), bundle.getVersion(),
                            BUNDLE_STATES.getOrDefault(bundle.getState(), "UNKNOWN"), headerString });
        }
    }
}

From source file:org.openhab.binding.xbmc.internal.XbmcActiveBinding.java

/**
 * {@inheritDoc}/*w w  w  .j  a  v a  2  s. co  m*/
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug(getName() + " updated()");

    Map<String, XbmcHost> hosts = new HashMap<String, XbmcHost>();

    if (config != null) {

        String refreshIntervalString = (String) config.get("refreshInterval");
        if (StringUtils.isNotBlank(refreshIntervalString)) {
            refreshInterval = Long.parseLong(refreshIntervalString);
        }

        Enumeration<String> keys = config.keys();

        while (keys.hasMoreElements()) {
            // Ignore "refreshInterval" key
            String key = keys.nextElement();
            if ("refreshInterval".equals(key)) {
                continue;
            }

            if ("service.pid".equals(key)) {
                continue;
            }

            String[] parts = key.split("\\.");
            String hostname = parts[0];

            XbmcHost host = hosts.get(hostname);
            if (host == null) {
                host = new XbmcHost();
            }

            String value = ((String) config.get(key)).trim();

            if ("host".equals(parts[1])) {
                host.setHostname(value);
            }
            if ("rsPort".equals(parts[1])) {
                host.setRsPort(Integer.valueOf(value));
            }
            if ("wsPort".equals(parts[1])) {
                host.setWsPort(Integer.valueOf(value));
            }
            if ("username".equals(parts[1])) {
                host.setUsername(value);
            }
            if ("password".equals(parts[1])) {
                host.setPassword(value);
            }
            hosts.put(hostname, host);
        }

        setProperlyConfigured(true);
        nameHostMapper = hosts;
        registerAllWatches();
    }
}

From source file:org.openhab.binding.mpd.internal.MpdBinding.java

@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {
    if (config != null) {
        disconnectPlayersAndMonitors();// www .  j  a  va2s.com
        cancelScheduler();

        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_PLAYER_CONFIG_PATTERN.matcher(key);
            if (!matcher.matches()) {
                logger.debug("given mpd player-config-key '" + key
                        + "' does not follow the expected pattern '<playername>.<host|port>'");
                continue;
            }

            matcher.reset();
            matcher.find();

            String playerId = matcher.group(1);

            MpdPlayerConfig playerConfig = playerConfigCache.get(playerId);
            if (playerConfig == null) {
                playerConfig = new MpdPlayerConfig();
                playerConfigCache.put(playerId, playerConfig);
            }

            String configKey = matcher.group(2);
            String value = (String) config.get(key);

            if ("host".equals(configKey)) {
                playerConfig.host = value;
            } else if ("port".equals(configKey)) {
                playerConfig.port = Integer.valueOf(value);
            } else if ("password".equals(configKey)) {
                playerConfig.password = value;
            } else {
                throw new ConfigurationException(configKey,
                        "the given configKey '" + configKey + "' is unknown");
            }

        }

        connectAllPlayersAndMonitors();
        scheduleReconnect();
    }
}

From source file:org.codice.ddf.registry.federationadmin.impl.FederationAdmin.java

@Override
public List<Service> allRegistryInfo() {

    List<Service> metatypes = helper.getMetatypes();

    for (Service metatype : metatypes) {
        try {/*from  ww  w .  j av  a  2s  .co  m*/
            List<Configuration> configs = helper.getConfigurations(metatype);

            List<ConfigurationDetails> configurations = new ArrayList<>();
            if (configs != null) {
                for (Configuration config : configs) {
                    ConfigurationDetails registry = new ConfigurationDetailsImpl();

                    boolean disabled = config.getPid().endsWith(DISABLED);
                    registry.setId(config.getPid());
                    registry.setEnabled(!disabled);
                    registry.setFactoryPid(config.getFactoryPid());

                    if (!disabled) {
                        registry.setName(helper.getName(config));
                        registry.setBundleName(helper.getBundleName(config));
                        registry.setBundleLocation(config.getBundleLocation());
                        registry.setBundle(helper.getBundleId(config));
                    } else {
                        registry.setName(config.getPid());
                    }

                    Dictionary<String, Object> properties = config.getProperties();
                    ConfigurationProperties plist = new ConfigurationPropertiesImpl();
                    for (String key : Collections.list(properties.keys())) {
                        plist.put(key, properties.get(key));
                    }
                    registry.setConfigurationProperties(plist);

                    configurations.add(registry);
                }
                metatype.setConfigurations(configurations);
            }
        } catch (InvalidSyntaxException | IOException e) {
            LOGGER.info("Error getting registry info:", e);
        }
    }

    Collections.sort(metatypes, (o1, o2) -> ((String) o1.get("id")).compareToIgnoreCase((String) o2.get("id")));
    return metatypes;
}