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.codice.pubsub.server.SubscriptionServer.java

private void processSubscriptions() {
    while (!Thread.currentThread().isInterrupted()) {
        //Fetch Subscriptions
        Dictionary subMap = getSubscriptionMap();

        if (subMap != null) {
            Enumeration e = subMap.keys();
            while (e.hasMoreElements()) {
                String subscriptionId = (String) e.nextElement();
                if (!subscriptionId.equals("service.pid")) {
                    String subscriptionMsg = (String) subMap.get(subscriptionId);
                    int status = checkProcessingStatus(subscriptionId);

                    if (status == PROCESS_STATUS_COMPLETE) {
                        Future<QueryControlInfo> future = processMap.get(subscriptionId);
                        if (future != null) {
                            boolean done = future.isDone();
                            if (done) {
                                try {
                                    QueryControlInfo ctrlInfo = future.get();
                                    processMap.remove(subscriptionId);
                                    runQuery(subscriptionMsg, ctrlInfo.getQueryEndDateTime());
                                } catch (InterruptedException ie) {
                                    LOGGER.error(ie.getMessage());

                                } catch (ExecutionException ee) {
                                    LOGGER.error(ee.getMessage());
                                }//from w  w w . ja v a  2  s . c o m
                            }
                        }
                    } else if (status == PROCESS_STATUS_NOT_EXIST) {
                        runQuery(subscriptionMsg, new DateTime().minusSeconds(1));

                    } else if (status == PROCESS_STATUS_NOT_EXIST) {

                        //Do Nothing For Now
                    }
                }
            }
        } else {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:org.fourthline.cling.osgi.test.integration.InitialIntegrationTest.java

private void doSimpleDeviceSetAction(final String name, String testDataId) {
    UPnPDevice dev = findUPnPTestDevice();

    //        for(UPnPService service : dev.getServices()) {
    //            System.out.println("serviceID: " + service.getId());
    //        }//from w  w  w .  j  a v a2  s.  co  m

    UPnPService service = dev.getService(SERVICE_ID);
    assertNotNull(service);

    //        for(UPnPAction action : service.getActions()) {
    //            System.out.println("ACTIONS: " + action.getName());
    //        }

    UPnPAction action = service.getAction("GetAllVariables");
    assertNotNull(action);

    try {
        Dictionary result = action.invoke(null);
        Enumeration en = result.keys();

        TestData d = new TestDataFactory().getInstance().getTestData(INITIAL_TEST_DATA_ID);
        while (en.hasMoreElements()) {
            String key = (String) en.nextElement();
            Object object = d.getOSGiUPnPValue(key, /*type*/key);
            assertTrue(validate(key, key, result.get(key), object));

        }
    } catch (Exception e) {
        fail(e.getMessage());
    }

    UPnPAction setAction = service.getAction("SetAllVariables");

    TestData d = new TestDataFactory().getInstance().getTestData(testDataId);
    Properties props = new Properties();
    for (String argName : setAction.getInputArgumentNames()) {
        //            System.out.printf("@@@ argument: %s\n", argName);
        //            System.out.printf("@@@ type: %s\n", argName);

        Object object = d.getOSGiUPnPValue(argName, /*type*/argName);

        //            System.out.println("OBJECT: " + object);

        props.put(argName, object);

    }

    try {
        setAction.invoke(props);
    } catch (Exception e) {
        fail(e.getMessage());
    }

    try {
        Dictionary result = action.invoke(null);

        //            System.out.println("RESULT: " + result);
        Enumeration en = result.keys();
        while (en.hasMoreElements()) {
            String key = (String) en.nextElement();
            assertTrue(validate(key, key, result.get(key), props.get(key)));
        }

    } catch (Exception e) {
        fail(e.getMessage());
    }
}

From source file:org.opencastproject.silencedetection.impl.SilenceDetectionServiceImpl.java

@Override
public void updated(Dictionary properties) throws ConfigurationException {
    this.properties = new Properties();
    Enumeration keys = properties.keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        this.properties.put(key, properties.get(key));
    }//from   ww  w . j av a 2s .  c o  m
    logger.debug("Properties updated!");
}

From source file:org.openhab.binding.aleoncean.internal.AleonceanBinding.java

@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    if (config != null) {
        Enumeration<String> keys = config.keys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            Object val = config.get(key);
            LOGGER.debug("Parse config: {}; {}", key, val);
        }/* w ww  . j  a  va2 s . c o  m*/

        WorkerReply reply;

        /*
         * Set the ESP3 port.
         */
        final String valuePort = (String) config.get(CONFIG_PORT);
        if (StringUtils.isBlank(valuePort)) {
            LOGGER.warn("You need to setup the port that should be used for the ESP3 interface.");
            return;
        }

        reply = worker.addAndWaitForReply(new WorkerItemESP3Port(valuePort), 1, TimeUnit.MINUTES);
        if (reply.getReplyCode() != WorkerReplyCode.OK) {
            LOGGER.warn("Something went wrong ({}) enqueue set ESP3 port.", reply.getReplyCode());
            return;
        }

        /*
         * Set the base ID if entry is available.
         */
        final String valueBaseId = (String) config.get(CONFIG_BASEID);
        if (StringUtils.isNotBlank(valueBaseId)) {
            try {
                EnOceanId baseId = new EnOceanId(valueBaseId);
                reply = worker.addAndWaitForReply(new WorkerItemSetBaseId(baseId), 1, TimeUnit.MINUTES);
                if (reply.getReplyCode() != WorkerReplyCode.OK) {
                    LOGGER.warn("Something went wrong ({}) set base id.", reply.getReplyCode());
                    return;
                }
            } catch (IllegalArgumentException ex) {
                LOGGER.warn("Something went wrong parsing the base id.", ex);
                return;
            }
        }

        LOGGER.debug("The configuration was successfully updated.");

        // Seems only to be used by AbstractActiveBinding and not by AbstractBinding.
        //setProperlyConfigured(true);
    } else {
        LOGGER.warn(
                "You need to set at least the port for ESP3 hardware if you want to use the aleoncean binding.");
    }
}

From source file:org.openhab.binding.weather.internal.common.WeatherConfig.java

/**
 * Parses and validates the properties in openhab.cfg.
 *//*from  w w w .jav  a 2  s .  com*/
public void parse(Dictionary<String, ?> properties) throws ConfigurationException {
    valid = false;
    if (properties != null) {
        Enumeration<String> keys = properties.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();

            String value = StringUtils.trimToNull((String) properties.get(key));
            if (StringUtils.startsWithIgnoreCase(key, "apikey")) {
                parseApiKey(key, value);
            } else if (StringUtils.startsWithIgnoreCase(key, "location")) {
                parseLocation(key, value);
            }
        }

        // check all LocationConfigs
        for (LocationConfig lc : locationConfigs.values()) {
            if (!lc.isValid()) {
                throw new ConfigurationException("weather", "Incomplete location config for locationId '"
                        + lc.getLocationId() + "', please check your openhab.cfg!");
            }
            if (lc.getProviderName() != ProviderName.YAHOO
                    && !providerConfigs.containsKey(lc.getProviderName())) {
                throw new ConfigurationException("weather", "No apikey found for provider '"
                        + lc.getProviderName() + "', please check your openhab.cfg!");
            }
        }

        // check all ProviderConfigs
        for (ProviderConfig pc : providerConfigs.values()) {
            if (!pc.isValid()) {
                throw new ConfigurationException("weather", "Invalid apikey config for provider '"
                        + pc.getProviderName() + "', please check your openhab.cfg!");
            }
        }

        valid = locationConfigs.size() > 0;
    }
}

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

private boolean propertiesMatch(Dictionary<String, Object> dictionary1,
        Dictionary<String, Object> dictionary2) {
    if (dictionary1.size() != dictionary2.size()) {
        return false;
    }//from   w ww.  ja va  2 s.c om
    Enumeration<String> keys = dictionary1.keys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        Object o = dictionary1.get(key);
        Object o1 = dictionary2.get(key);
        if (o.getClass().isArray() && o1.getClass().isArray()) {
            if (!ArrayUtils.isEquals(o, o1)) {
                return false;
            }
        } else if (!o.equals(o1)) {
            return false;
        }
    }
    return true;
}

From source file:org.openhab.binding.samsungac.internal.SamsungAcBinding.java

/**
 * @{inheritDoc/*from  w  w w .  ja  va2  s . c  o  m*/
 */
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    Enumeration<String> keys = config.keys();

    String refreshIntervalString = (String) config.get("refresh");
    if (StringUtils.isNotBlank(refreshIntervalString)) {
        refreshInterval = Long.parseLong(refreshIntervalString);
        logger.info("Refresh interval set to " + refreshIntervalString + " ms");
    } else {
        logger.info("No refresh interval configured, using default: " + refreshInterval + " ms");
    }

    Map<String, AirConditioner> hosts = new HashMap<String, AirConditioner>();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        logger.debug("Configuration key is: " + key);
        if ("service.pid".equals(key)) {
            continue;
        }

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

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

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

        if ("host".equals(parts[1])) {
            host.setIpAddress(value);
        }
        if ("mac".equals(parts[1])) {
            host.setMacAddress(value);
        }
        if ("token".equals(parts[1])) {
            host.setToken(value);
        }
        hosts.put(hostname, host);
    }
    nameHostMapper = hosts;

    if (nameHostMapper == null || nameHostMapper.size() == 0) {
        setProperlyConfigured(false);
        Map<String, Map<String, String>> discovered = SsdpDiscovery.discover();
        if (discovered != null && discovered.size() > 0) {
            for (Map<String, String> ac : discovered.values()) {
                if (ac.get("IP") != null && ac.get("MAC_ADDR") != null)
                    logger.warn(
                            "We found air conditioner. Please put the following in your configuration file: "
                                    + "\r\n samsungac:<ACNAME>.host=" + ac.get("IP")
                                    + "\r\n samsungac:<ACNAME>.mac=" + ac.get("MAC_ADDR"));
            }
        } else {
            logger.warn("No Samsung Air Conditioner has been configured, and we could not find one either");
        }
    } else {
        setProperlyConfigured(true);
    }
}

From source file:org.openhab.binding.daikin.internal.DaikinBinding.java

/**
 * {@inheritDoc}//from   w  ww.j a v  a2  s.co  m
 */
@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {
    if (config != null) {
        Enumeration keys = config.keys();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            String value = (String) config.get(key);

            // the config-key enumeration contains additional keys that we
            // don't want to process here ...
            if ("service.pid".equals(key)) {
                continue;
            }

            if (key.equals(CONFIG_KEY_REFRESH)) {
                refreshInterval = Long.parseLong(value);
                continue;
            }

            String[] keyParts = key.split("\\.");
            String hostId = keyParts[0];
            String configKey = keyParts[1];

            if (!hosts.containsKey(hostId)) {
                hosts.put(hostId, new DaikinHost(hostId));
            }

            DaikinHost host = hosts.get(hostId);

            if (configKey.equals(CONFIG_KEY_HOST)) {
                host.setHost(value);
            } else if (configKey.equals(CONFIG_KEY_USERNAME)) {
                host.setUsername(value);
            } else if (configKey.equals(CONFIG_KEY_PASSWORD)) {
                host.setPassword(value);
            } else {
                throw new ConfigurationException(key, "Unrecognised configuration parameter: " + configKey);
            }
        }

        // start the refresh thread
        setProperlyConfigured(true);
    }
}

From source file:org.jahia.services.usermanager.mongo.JahiaMongoConfig.java

/**
 * defines or update the context of the provider
 * @param context the Spring application context object
 * @param dictionary configuration parameters
 *///  ww w  .  j  av  a 2s  .  c  om
public void setContext(final ApplicationContext context, final Dictionary<String, ?> dictionary) {
    final Properties userMongoProperties = new Properties();
    final UserConfig userConfig = new UserConfig();
    final Enumeration<String> keys = dictionary.keys();

    String fileName = null;
    while (keys.hasMoreElements()) {
        final String key = keys.nextElement();
        if (Constants.SERVICE_PID.equals(key) || ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)) {
            continue;
        } else if ("felix.fileinstall.filename".equals(key)) {
            fileName = (String) dictionary.get(key);
            continue;
        }
        final Object value = dictionary.get(key);
        if (key.startsWith("user.")) {
            buildConfig(userMongoProperties, userConfig, key, value, true);
        } else {
            userMongoProperties.put(transformPropKeyToBeanAttr(key), value);
        }
    }
    try {
        // populate config beans
        BeanUtils.populate(userConfig, userMongoProperties);

        // handle defaults values
        userConfig.handleDefaults();

        final String host = userConfig.getHost();
        final String database = userConfig.getDatabase();
        final MongoClient mongoClient = new MongoClient(host);
        final MongoDatabase mongoDatabase = mongoClient.getDatabase(database);

        if (mongoUserGroupProvider == null) {
            mongoUserGroupProvider = (MongoUserGroupProvider) context.getBean("mongoUserGroupProvider");
        } else {
            // Deactivate the provider before reconfiguring it.
            mongoUserGroupProvider.unregister();
        }

        mongoUserGroupProvider.setKey(providerKey);
        mongoUserGroupProvider.setUserConfig(userConfig);
        mongoUserGroupProvider.setMongoTemplateWrapper(new MongoTemplateWrapper(mongoDatabase));

        // Activate (again).
        mongoUserGroupProvider.register();
    } catch (IllegalAccessException | InvocationTargetException e) {
        LOGGER.error("Invalid Mongo configuration:" + fileName + ", "
                + "please refer to the Mongo configuration documentation", e);
    }
}

From source file:org.openhab.binding.hdanywhere.internal.HDanywhereBinding.java

@SuppressWarnings("rawtypes")
@Override//from  w  ww.j  a  va  2s  . c  o m
public void updated(Dictionary config) throws ConfigurationException {

    if (config != null) {

        Enumeration keys = config.keys();
        while (keys.hasMoreElements()) {

            String key = (String) keys.nextElement();

            Matcher matcher = EXTRACT_HDANYWHERE_CONFIG_PATTERN.matcher(key);
            if (!matcher.matches()) {
                logger.debug("given hdanywhere-config-key '" + key
                        + "' does not follow the expected pattern '<host_IP_Address>.ports'");
                continue;
            }

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

            String hostIP = matcher.group(1) + "." + matcher.group(2) + "." + matcher.group(3) + "."
                    + matcher.group(4);
            String configKey = matcher.group(5);
            String value = (String) config.get(key);

            if ("ports".equals(configKey)) {
                matrixCache.put(hostIP, Integer.valueOf(value));
            } else {
                throw new ConfigurationException(configKey,
                        "the given configKey '" + configKey + "' is unknown");
            }
        }
    }

    setProperlyConfigured(true);

}