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.owserver.internal.OWServerBinding.java

/**
 * {@inheritDoc}/*w  w  w  .  j  a v a2 s.  com*/
 */
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    if (config != null) {
        Enumeration<String> keys = config.keys();

        if (serverList == null) {
            serverList = new HashMap<String, OWServerConfig>();
        }

        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_CONFIG_PATTERN.matcher(key);

            if (!matcher.matches()) {
                continue;
            }

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

            String serverId = matcher.group(1);

            OWServerConfig deviceConfig = serverList.get(serverId);

            if (deviceConfig == null) {
                deviceConfig = new OWServerConfig();
                serverList.put(serverId, deviceConfig);
            }

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

            if ("host".equals(configKey)) {
                deviceConfig.host = value;
            } else if ("user".equals(configKey)) {
                deviceConfig.user = value;
            } else if ("password".equals(configKey)) {
                deviceConfig.password = value;
            } else {
                throw new ConfigurationException(configKey,
                        "The given OWServer configKey '" + configKey + "' is unknown");
            }
        }

        String timeoutString = (String) config.get("timeout");
        if (StringUtils.isNotBlank(timeoutString)) {
            timeout = Integer.parseInt(timeoutString);
        }

        String granularityString = (String) config.get("granularity");
        if (StringUtils.isNotBlank(granularityString)) {
            granularity = Integer.parseInt(granularityString);
        }

        String cacheString = (String) config.get("cache");
        if (StringUtils.isNotBlank(cacheString)) {
            cacheDuration = Integer.parseInt(cacheString);
        }

        setProperlyConfigured(true);
    }
}

From source file:org.openhab.binding.denon.internal.DenonBinding.java

/**
 * {@inheritDoc}//from w ww . j  a va  2  s  .c o m
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug("Denon binding updated");

    if (config == null) {
        return;
    }

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

    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        if (CONFIG_SERVICE_PID.equals(key)) {
            continue;
        }

        String[] parts = key.split("\\.");
        String value = Objects.toString(config.get(key), null);

        if (parts.length == 1) {
            String option = parts[0];
            if (CONFIG_REFRESH.equals(option)) {
                refreshInterval = Integer.valueOf(value);
            }
        } else {
            String instance = parts[0];

            DenonConnectionProperties connection = connections.get(instance);
            if (connection == null) {
                connection = new DenonConnectionProperties();
                connection.setInstance(instance);
                connections.put(instance, connection);
            }

            String option = parts[1].trim();

            if (CONFIG_HOST.equals(option)) {
                connection.setHost(value);
            } else if (CONFIG_UPDATE_TYPE.equals(option)) {
                connection.setTelnet(value.equals(CONFIG_UPDATE_TYPE_TELNET));
                connection.setHttp(value.equals(CONFIG_UPDATE_TYPE_HTTP));

                if (!value.equals(CONFIG_UPDATE_TYPE_TELNET) && !value.equals(CONFIG_UPDATE_TYPE_HTTP)) {
                    logger.warn("Invalid connection type {} for instance {}, using default", value, instance);
                }
            }
        }
    }

    boolean isActiveBinding = false;

    for (Entry<String, DenonConnectionProperties> entry : connections.entrySet()) {
        DenonConnectionProperties connection = entry.getValue();

        if (!StringUtils.isBlank(connection.getHost())) {
            logger.debug("Denon receiver configured at {}", connection.getHost());
            DenonConnector connector = new DenonConnector(connection, new DenonPropertyUpdatedCallback() {
                @Override
                public void updated(String instance, String property, State state) {
                    processPropertyUpdated(instance, property, state);
                }
            });
            connection.setConnector(connector);
            connector.connect();

            if (connection.isHttp()) {
                isActiveBinding = true;
            }
        } else {
            logger.debug("No host configured for receiver {}", connection.getInstance());
        }
    }

    setProperlyConfigured(isActiveBinding);
}

From source file:org.openhab.binding.multionewire.internal.MultiOneWireBinding.java

@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {

    if (config == null)
        return;/*from  w  w  w . j  a v a 2s  .  c  om*/

    @SuppressWarnings("unchecked")
    Enumeration<String> keys = config.keys();

    if (serverList == null) {
        serverList = new HashMap<String, ServerConfig>();
    }

    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_CONFIG_PATTERN.matcher(key);

        if (!matcher.matches()) {
            continue;
        }

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

        String serverId = matcher.group(1);

        ServerConfig serverConfig = serverList.get(serverId);

        if (serverConfig == null) {
            serverConfig = new ServerConfig();
            serverList.put(serverId, serverConfig);
        }

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

        if ("host".equals(configKey)) {
            String[] hostConfig = value.split(":");
            serverConfig.host = hostConfig[0];
            if (hostConfig.length > 1) {
                serverConfig.port = Integer.parseInt(hostConfig[1]);
            } else {
                serverConfig.port = 4304;
            }
            logger.debug("Added new Server {}:{} to serverlist",
                    new Object[] { serverConfig.host, serverConfig.port });
        } else {
            throw new ConfigurationException(configKey,
                    "The given OWServer configKey '" + configKey + "' is unknown");
        }
    }

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

    String retryString = (String) config.get("retry");
    if (StringUtils.isNotBlank(retryString)) {
        retry = Integer.parseInt(retryString);
    }

    String tempScaleString = (String) config.get("tempscale");
    if (StringUtils.isNotBlank(tempScaleString)) {
        try {
            tempScale = OwTemperatureScale.valueOf("OWNET_TS_" + tempScaleString);
        } catch (IllegalArgumentException iae) {
            throw new ConfigurationException("onewire:tempscale", "Unknown temperature scale '"
                    + tempScaleString + "'. Valid values are CELSIUS, FAHRENHEIT, KELVIN or RANKIN.");
        }
    }

    setProperlyConfigured(true);
}

From source file:org.eclipse.smarthome.model.core.internal.folder.FolderObserver.java

@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {
    if (config != null) {
        // make sure to clear the caches first
        lastFileNames.clear();/*from ww w  . j a  v a  2 s .  c  om*/
        lastCheckedMap.clear();
        folderFileExtMap.clear();
        folderRefreshMap.clear();

        Enumeration keys = config.keys();
        while (keys.hasMoreElements()) {
            String foldername = (String) keys.nextElement();
            if (foldername.equals("service.pid"))
                continue;
            String[] values = ((String) config.get(foldername)).split(",");
            try {
                Integer refreshValue = Integer.valueOf(values[0]);
                String[] fileExts = (String[]) ArrayUtils.remove(values, 0);
                File folder = getFolder(foldername);
                if (folder.exists() && folder.isDirectory()) {
                    folderFileExtMap.put(foldername, fileExts);
                    if (refreshValue > 0) {
                        folderRefreshMap.put(foldername, refreshValue);
                        if (!this.isAlive()) {
                            // seems we have the first folder to observe, so let's start the thread
                            this.start();
                        } else {
                            // make sure that we notify the sleeping thread and directly refresh the folders
                            synchronized (FolderObserver.this) {
                                notify();
                                checkFolder(foldername);
                            }
                        }
                    } else {
                        // deactivate the refresh for this folder
                        folderRefreshMap.remove(foldername);
                        checkFolder(foldername);
                    }
                } else {
                    logger.warn(
                            "Directory '{}' does not exist in '{}'. Please check your configuration settings!",
                            foldername, ConfigDispatcher.getConfigFolder());
                }

                // now update the refresh information for the thread
                Integer[] refreshValues = folderRefreshMap.values().toArray(new Integer[0]);
                if (refreshValues.length > 0) {
                    gcdRefresh = MathUtils.gcd(refreshValues);
                    lcmRefresh = MathUtils.lcm(refreshValues);
                }
                refreshCount = 0;
            } catch (NumberFormatException e) {
                logger.warn("Invalid value '{}' for configuration '{}'. Integer value expected!", values[0],
                        ModelCoreConstants.SERVICE_PID + ":" + foldername);
            }

        }
    }
}

From source file:net.cellar.hazelcast.HazelcastGroupManager.java

/**
 * Copies the setup of a {@link Group}./* w w w  . ja v  a 2  s. c  o  m*/
 *
 * @param sourceGroupName
 * @param targetGroupName
 */
public void copyGroupConfiguration(String sourceGroupName, String targetGroupName) {
    try {
        Configuration conf = configurationAdmin.getConfiguration(Configurations.GROUP);
        Dictionary dictionary = conf.getProperties();
        Dictionary updatedProperties = new Properties();
        Enumeration keyEnumeration = dictionary.keys();
        while (keyEnumeration.hasMoreElements()) {
            String key = (String) keyEnumeration.nextElement();
            String value = (String) dictionary.get(key);

            if (key.startsWith(sourceGroupName)) {
                String newKey = key.replace(sourceGroupName, targetGroupName);
                updatedProperties.put(newKey, value);
            }
            updatedProperties.put(key, value);
        }

        conf.update(updatedProperties);

    } catch (IOException e) {
        logger.error("Error reading group configuration ", e);
    }

}

From source file:org.openhab.binding.openenergymonitor.internal.OpenEnergyMonitorBinding.java

/**
 * @{inheritDoc//from  ww w  .  j ava  2  s .  c om
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {

    if (config != null) {

        HashMap<String, OpenEnergyMonitorParserRule> parsingRules = new HashMap<String, OpenEnergyMonitorParserRule>();

        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)) {
                continue;
            }

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

            if ("udpPort".equals(key)) {
                if (StringUtils.isNotBlank(value)) {
                    udpPort = Integer.parseInt(value);
                }
            } else if ("serialPort".equals(key)) {
                serialPort = value;
            } else if ("simulate".equals(key)) {
                if (StringUtils.isNotBlank(value)) {
                    simulate = Boolean.parseBoolean(value);
                }
            } else {

                // process all data parsing rules
                try {
                    OpenEnergyMonitorParserRule rule = new OpenEnergyMonitorParserRule(value);
                    parsingRules.put(key, rule);
                } catch (OpenEnergyMonitorException e) {
                    throw new ConfigurationException(key, "invalid parser rule", e);
                }
            }

        }

        if (parsingRules != null) {

            dataParser = new OpenEnergyMonitorDataParser(parsingRules);
        }

        if (messageListener != null) {

            logger.debug("Close previous message listener");

            messageListener.setInterrupted(true);
            try {
                messageListener.join();
            } catch (InterruptedException e) {
                logger.info("Previous message listener closing interrupted", e);
            }
        }

        messageListener = new MessageListener();
        messageListener.start();
    }
}

From source file:org.paxle.tools.ieporter.cm.impl.ConfigurationIEPorter.java

@SuppressWarnings("unchecked")
Map<String, Document> exportConfiguration(Configuration config) throws ParserConfigurationException {
    if (config == null)
        return Collections.emptyMap();
    else if (config.getPid() == null)
        return Collections.emptyMap();
    else if (config.getProperties() == null)
        return Collections.emptyMap();

    // create a new XML document
    Document doc = this.createNewXMLDocument(ELEM_CONFIG, "http://www.paxle.net/config");
    Element root = doc.getDocumentElement();

    // adding the pid
    Element pidElem = doc.createElement(Constants.SERVICE_PID);
    pidElem.appendChild(doc.createTextNode(config.getPid()));
    root.appendChild(pidElem);//from  ww w.ja  v a  2 s.  c  o  m

    // <properties>
    Element propsElem = doc.createElement(ELEM_PROPERTIES);
    root.appendChild(propsElem);

    // loop through all parameters
    Dictionary<String, Object> props = config.getProperties();
    Enumeration<String> keys = props.keys();
    while (keys.hasMoreElements()) {
        final String key = keys.nextElement();
        final Object value = props.get(key);
        if (key.equalsIgnoreCase(Constants.SERVICE_PID))
            continue;
        if (value == null)
            continue; // TODO we should set nil instead

        // <property key="xxx" type="xxx">
        Element propertyElement = doc.createElement(ELEM_PROPERTY);
        propertyElement.setAttribute(ATTRIBUTE_PROPERTY_KEY, key);
        propertyElement.setAttribute(ATTRIB_PROPERTY_TYPE, value.getClass().getSimpleName());
        propsElem.appendChild(propertyElement);

        if (value.getClass().isArray() || value instanceof Vector) {
            Element valuesElem = doc.createElement(ELEM_VALUES);
            propertyElement.appendChild(valuesElem);

            // <values>
            int length = (value.getClass().isArray()) ? Array.getLength(value) : ((Vector) value).size();
            for (int i = 0; i < length; i++) {
                // <value>
                Object valueItem = (value.getClass().isArray()) ? Array.get(value, i) : ((Vector) value).get(i);
                Element valueElem = doc.createElement(ELEM_VALUE);
                valueElem.appendChild(doc.createTextNode(valueItem.toString()));
                valuesElem.appendChild(valueElem);
                // </value>
            }
            // </values>
        } else {
            // <value>
            Element valueElem = doc.createElement(ELEM_VALUE);
            valueElem.appendChild(doc.createTextNode(value.toString()));
            propertyElement.appendChild(valueElem);
            // </value>
        }
        // </property>
    }
    // </properties>

    HashMap<String, Document> result = new HashMap<String, Document>();
    result.put(config.getPid(), doc);
    return result;
}

From source file:org.openhab.binding.echonetlite.internal.ECHONETLiteBinding.java

@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    if (config == null || config.isEmpty())
        throw new IllegalArgumentException("config is empty");
    else {//from   w  w w .j av  a2s  .c  o m
        for (final Enumeration<String> e = config.keys(); e.hasMoreElements();) {
            final String key = e.nextElement();
            final String value = StringUtils.trim((String) config.get(key));

            // skip empty values
            if (StringUtils.isBlank(value)) {
                continue;
            }
            final Matcher matcher = CONFIG_PATTERN.matcher(key);
            if (matcher.matches()) {
                final String device = matcher.group(1);
                final String property = matcher.group(2);
                if (!deviceMap.containsKey(device)) {
                    deviceMap.put(device, new DeviceInfo());
                }
                DeviceInfo deviceInfo = deviceMap.get(device);

                // dispatch individual properties
                if (("host").equalsIgnoreCase(property)) {
                    deviceInfo.setHost(value);
                } else if (("port").equalsIgnoreCase(property)) {
                    deviceInfo.setPort(Integer.parseInt(value));
                } else if (("ehd").equalsIgnoreCase(property)) {
                    deviceInfo.setEhd(CommonUtils.hexStringToByteArray(value));
                } else if (("edata_head").equalsIgnoreCase(property)) {
                    deviceInfo.setEdataHead(CommonUtils.hexStringToByteArray(value));
                }
            }
        }
    }
}

From source file:org.openhab.binding.plex.internal.PlexBinding.java

/**
 * @{inheritDoc}//from  w  ww  .  j  av  a2s. c om
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug("Plex binding updated");

    if (config != null) {
        PlexConnectionProperties connectionProperties = new PlexConnectionProperties();
        Enumeration<String> keys = config.keys();

        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            if ("service.pid".equals(key))
                continue;

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

            if ("host".equals(key))
                connectionProperties.setHost(value);
            else if ("port".equals(key))
                connectionProperties.setPort(Integer.valueOf(value));
            else if ("token".equals(key))
                connectionProperties.setToken(value);
            else if ("username".equals(key))
                connectionProperties.setUsername(value);
            else if ("password".equals(key))
                connectionProperties.setPassword(value);
            else if ("refresh".equals(key))
                if (StringUtils.isNumeric(value))
                    refreshInterval = Integer.valueOf(value);
                else
                    logger.warn("Non-numeric refresh interval {}, using default {}", value, refreshInterval);
        }

        logger.debug("Plex config, server at {}:{}", connectionProperties.getHost(),
                connectionProperties.getPort());

        if (!StringUtils.isEmpty(connectionProperties.getHost())) {
            connect(connectionProperties);
            setProperlyConfigured(true);
        } else {
            logger.warn("No host IP configured for Plex binding");
        }
    }
}

From source file:org.openhab.binding.enigma2.internal.Enigma2Binding.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) {
        String refreshIntervalString = (String) config.get("refresh");
        if (StringUtils.isNotBlank(refreshIntervalString)) {
            refreshInterval = Long.parseLong(refreshIntervalString);
        }

        Enumeration<String> keys = config.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();

            String[] keyElements = key.split(":");
            String deviceId = keyElements[0];

            if (keyElements.length >= 2) {

                Enigma2Node node = enigmaNodes.get(deviceId);
                if (node == null) {
                    node = new Enigma2Node();
                    enigmaNodes.put(deviceId, node);
                }

                String option = keyElements[1];
                if (option.equals("hostname")) {
                    node.setHostName((String) config.get(key));
                } else if (option.equals("username")) {
                    node.setUserName((String) config.get(key));
                } else if (option.equals("password")) {
                    node.setPassword((String) config.get(key));
                }

            }
        }

        setProperlyConfigured(checkProperlyConfigured());
    }
}