Example usage for java.util Dictionary get

List of usage examples for java.util Dictionary get

Introduction

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

Prototype

public abstract V get(Object key);

Source Link

Document

Returns the value to which the key is mapped in this dictionary.

Usage

From source file:org.openhab.binding.snmp.internal.SnmpBinding.java

/**
 * {@inheritDoc}/*w ww.  ja v a2  s  .  c o m*/
 */
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    boolean mapping = false;
    stopListening();

    if (config != null) {
        mapping = true;

        SnmpBinding.community = (String) config.get("community");
        if (StringUtils.isBlank(SnmpBinding.community)) {
            SnmpBinding.community = "public";
            logger.info("didn't find SNMP community configuration -> listen to SNMP community {}",
                    SnmpBinding.community);
        }

        String portString = (String) config.get("port");
        if (StringUtils.isNotBlank(portString) && portString.matches("\\d*")) {
            SnmpBinding.port = Integer.valueOf(portString).intValue();
        } else {
            SnmpBinding.port = SNMP_DEFAULT_PORT;
            logger.info(
                    "Didn't find SNMP port configuration or configuration is invalid -> listen to SNMP default port {}",
                    SnmpBinding.port);
        }

        String timeoutString = (String) config.get("timeout");
        if (StringUtils.isNotBlank(timeoutString)) {
            SnmpBinding.timeout = Integer.valueOf(timeoutString).intValue();
            if (SnmpBinding.timeout < 0 | SnmpBinding.retries > 5) {
                logger.info(
                        "SNMP timeout value is invalid (" + SnmpBinding.timeout + "). Using default value.");
                SnmpBinding.timeout = 1500;
            }
        } else {
            SnmpBinding.timeout = 1500;
            logger.info("Didn't find SNMP timeout or configuration is invalid -> timeout set to {}",
                    SnmpBinding.timeout);
        }

        String retriesString = (String) config.get("retries");
        if (StringUtils.isNotBlank(retriesString)) {
            SnmpBinding.retries = Integer.valueOf(retriesString).intValue();
            if (SnmpBinding.retries < 0 | SnmpBinding.retries > 5) {
                logger.info(
                        "SNMP retries value is invalid (" + SnmpBinding.retries + "). Using default value.");
                SnmpBinding.retries = 0;
            }
        } else {
            SnmpBinding.retries = 0;
            logger.info("Didn't find SNMP retries or configuration is invalid -> retries set to {}",
                    SnmpBinding.retries);
        }

    }

    for (SnmpBindingProvider provider : providers) {
        if (provider.getInBindingItemNames() != null) {
            mapping = true;
        }
    }

    // Did we find either a trap request, or any bindings
    if (mapping) {
        listen();
    }
    setProperlyConfigured(true);
}

From source file:org.openhab.binding.maxcube.internal.MaxCubeBinding.java

/**
 * {@inheritDoc}/*from w  w w.j av a  2s  .  c  o m*/
 */
@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {
    if (config != null) {
        ip = (String) config.get("ip");
        if (StringUtils.isBlank(ip)) {
            ip = discoveryGatewayIp();
        }

        String portString = (String) config.get("port");
        if (portString != null && !portString.isEmpty()) {
            if (port > 0 && port <= 65535) {
                port = Integer.parseInt(portString);
            }
        }

        String refreshIntervalString = (String) config.get("refreshInterval");
        if (refreshIntervalString != null && !refreshIntervalString.isEmpty()) {
            refreshInterval = Long.parseLong(refreshIntervalString);
        }

        String exclusiveString = (String) config.get("exclusive");
        if (StringUtils.isNotBlank(exclusiveString)) {
            exclusive = Boolean.parseBoolean(exclusiveString);
        }

        String maxRequestsPerConnectionString = (String) config.get("maxRequestsPerConnection");
        if (maxRequestsPerConnectionString != null && !maxRequestsPerConnectionString.isEmpty()) {
            maxRequestsPerConnection = Integer.parseInt(maxRequestsPerConnectionString);
        }
    } else {
        ip = discoveryGatewayIp();
    }

    setProperlyConfigured(ip != null);
}

From source file:org.openhab.binding.smarthomatic.internal.SmarthomaticBinding.java

/**
 * @{inheritDoc/*from w  ww  .j av  a  2  s .co  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
        // <bindingName>:refresh=<intervalInMs>
        String refreshIntervalString = (String) config.get("refresh");
        if (StringUtils.isNotBlank(refreshIntervalString)) {
            refreshInterval = Long.parseLong(refreshIntervalString);
        }

        boolean changed = false;

        if (serialPortname != (String) config.get("serialPort")) {
            serialPortname = (String) config.get("serialPort");
            changed = true;
        }
        String dummy = (String) config.get("baud");
        try {
            if (serialBaudrate != Integer.parseInt(dummy)) {
                serialBaudrate = Integer.parseInt(dummy);
                changed = true;
            }
        } catch (NumberFormatException e) {
            logger.info("reading exception");
        }

        if (changed | (baseStation == null)) {
            if (baseStation != null) {
                baseStation.closeSerialPort();
            }

            baseStation = new BaseStation(serialPortname, serialBaudrate, this);
            logger.debug("Smarthomatic Binding:update creates new basestation");
        }

        Enumeration<String> keys = config.keys();
        for (int i = 0; i < config.size(); i++) {
            String key = keys.nextElement();
            StringTokenizer tokens = new StringTokenizer(key, ":");

            if (tokens.nextToken().equals("device")) {
                if (tokens.hasMoreElements()) {
                    dummy = tokens.nextToken();
                    int deviceID = Integer.parseInt(dummy);
                    String name = (String) config.get(key);
                    SmarthomaticGenericBindingProvider.addDevice(name, deviceID);
                    logger.debug("Smarthomatic device {} can be indexed by name {}",
                            new String[] { dummy, name });
                }
            }
            logger.debug("KEY: {}", key);
        }

        setProperlyConfigured(true);
    }
}

From source file:org.openhab.binding.heatmiser.internal.HeatmiserBinding.java

/**
 * @{inheritDoc}// w  w w  .  j  ava  2 s .  c  o  m
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug("HEATMISER updated() method is called!");

    if (config != null) {
        // to override the default refresh interval one has to add a 
        // parameter to openhab.cfg like <bindingName>:refresh=<intervalInMs>
        String refreshIntervalString = (String) config.get("refresh");
        if (StringUtils.isNotBlank(refreshIntervalString)) {
            refreshInterval = Long.parseLong(refreshIntervalString);
        }

        String localAddress = (String) config.get("address");
        if (StringUtils.isNotBlank(localAddress)) {
            ipAddress = localAddress;
        }

        String portConfig = (String) config.get("port");
        if (StringUtils.isNotBlank(portConfig)) {
            ipPort = Integer.parseInt(portConfig);
        } else {
            ipPort = DefaultPort;
        }

        // start the listener
        listen();

        // Tell the system we're good!
        setProperlyConfigured(true);
    }
}

From source file:org.openhab.binding.mystromecopower.internal.MyStromEcoPowerBinding.java

/**
 * {@inheritDoc}// w  w w.j  a  va 2  s  .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
        // <bindingName>:refresh=<intervalInMs>
        String refreshIntervalString = (String) config.get("refresh");
        if (StringUtils.isNotBlank(refreshIntervalString)) {
            refreshInterval = Long.parseLong(refreshIntervalString);
        }

        // read further config parameters here ...
        // read user name
        String userName = (String) config.get("userName");
        if (StringUtils.isNotBlank(userName)) {
            this.userName = userName;
        } else {
            throw new ConfigurationException("userName",
                    "The userName to connect to myStrom must be specified in config file");
        }

        String password = (String) config.get("password");
        if (StringUtils.isNotBlank(password)) {
            this.password = password;
        } else {
            throw new ConfigurationException("password",
                    "The password to connect to myStrom must be specified in config file");
        }

        if (this.devMode) {
            this.mystromClient = new MockMystromClient();
        } else {
            this.mystromClient = new MystromClient(this.userName, this.password, logger);
        }

        if (ChangeStateJob.MystromClient == null) {
            ChangeStateJob.MystromClient = this.mystromClient;
        }

        setProperlyConfigured(true);

        // do a discovery of all mystrom eco power to get id of devices
        try {
            this.mystromDiscovery();
        } catch (IOException e) {
            logger.error("Error doing discovery of your devices", e);
        }
    }
}

From source file:org.openhab.binding.sunnywebbox.internal.SunnyWebBoxBinding.java

/**
 * @{inheritDoc/*from  w w w. j a  va 2  s  .  co 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
        // <bindingName>:refresh=<intervalInMs>
        String refreshIntervalString = (String) config.get("refresh");

        if (StringUtils.isNotBlank(refreshIntervalString)) {
            logger.debug("refresh is set to " + refreshIntervalString);
            refreshInterval = Long.parseLong(refreshIntervalString);
        }
        // String URLConfig = (String) config.get("URL");
        Enumeration<String> configElementsKeys = config.keys();
        while (configElementsKeys.hasMoreElements()) {
            String configElementKey = configElementsKeys.nextElement();
            logger.debug("config element: " + configElementKey);
            if (configElementKey.startsWith("URL")) {
                URLs.put(configElementKey, (String) config.get(configElementKey));
            }
        }
        // System.exit(0);
        // config.
        // if (StringUtils.isNotBlank(URLConfig)) {
        // URL = URLConfig;
        // }

        // read further config parameters here ...

        setProperlyConfigured(true);
    }
}

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   www.ja  v  a2  s. c o 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.openhab.binding.fht.internal.FHTBinding.java

private String parseMandatoryValue(String key, Dictionary<String, ?> config) throws ConfigurationException {
    String value = (String) config.get(key);
    if (StringUtils.isEmpty(value)) {
        setProperlyConfigured(false);//  ww w.  j a v a2 s  .  co  m
        throw new ConfigurationException(key, "Configuration option " + key + " is mandatory");
    }
    return value;
}

From source file:org.eclipse.virgo.ide.runtime.internal.core.ServerBehaviour.java

public URL getModuleRootURL(IModule module) {
    try {// w ww.  j a  v  a  2  s  . c o m
        // check pre condition; only dynamic web projects and java projects are allowed
        IProject project = module.getProject();
        if (!SpringCoreUtils.hasProjectFacet(project, FacetCorePlugin.WEB_FACET_ID)
                || !JdtUtils.isJavaProject(project)) {
            return null;
        }

        String contextPath = null;

        BundleManifest bundleManifest = BundleManifestCorePlugin.getBundleManifestManager()
                .getBundleManifest(JdtUtils.getJavaProject(project));
        if (bundleManifest != null) {
            Dictionary<String, String> manifest = bundleManifest.toDictionary();
            if (manifest != null && manifest.get(WEB_CONTEXT_PATH_MANIFEST_HEADER) != null) {
                contextPath = manifest.get(WEB_CONTEXT_PATH_MANIFEST_HEADER);
            }

        }
        if (contextPath == null) {
            contextPath = module.getName();
        }

        // TODO: CD make port configurable
        int port = 8080;
        StringBuilder urlBuilder = new StringBuilder();
        urlBuilder.append("http://localhost:");
        urlBuilder.append(port);
        urlBuilder.append("/");
        urlBuilder.append(contextPath);

        String url = urlBuilder.toString();
        if (!url.endsWith("/")) {
            urlBuilder.append("/");
        }

        return new URL(urlBuilder.toString());
    } catch (Exception e) {
        return null;
    }
}

From source file:org.eclipse.smarthome.config.dispatch.internal.ConfigDispatcher.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private void processConfigFile(File configFile) throws IOException, FileNotFoundException {
    if (configFile.isDirectory() || !configFile.getName().endsWith(".cfg")) {
        logger.debug("Ignoring file '{}'", configFile.getName());
        return;//from   w w  w . j a va2 s  .  c om
    }
    logger.debug("Processing config file '{}'", configFile.getName());

    // we need to remember which configuration needs to be updated
    // because values have changed.
    Map<Configuration, Dictionary> configsToUpdate = new HashMap<Configuration, Dictionary>();

    // also cache the already retrieved configurations for each pid
    Map<Configuration, Dictionary> configMap = new HashMap<Configuration, Dictionary>();

    String pid;
    String filenameWithoutExt = StringUtils.substringBeforeLast(configFile.getName(), ".");
    if (filenameWithoutExt.contains(".")) {
        // it is a fully qualified namespace
        pid = filenameWithoutExt;
    } else {
        pid = getServicePidNamespace() + "." + filenameWithoutExt;
    }

    // configuration file contains a PID Marker
    List<String> lines = IOUtils.readLines(new FileInputStream(configFile));
    if (lines.size() > 0 && lines.get(0).startsWith(PID_MARKER)) {
        pid = lines.get(0).substring(PID_MARKER.length()).trim();
    }

    for (String line : lines) {
        String[] contents = parseLine(configFile.getPath(), line);
        // no valid configuration line, so continue
        if (contents == null) {
            continue;
        }

        if (contents[0] != null) {
            pid = contents[0];
            // PID is not fully qualified, so prefix with namespace
            if (!pid.contains(".")) {
                pid = getServicePidNamespace() + "." + pid;
            }
        }

        String property = contents[1];
        String value = contents[2];
        Configuration configuration = configAdmin.getConfiguration(pid, null);
        if (configuration != null) {
            Dictionary configProperties = configMap.get(configuration);
            if (configProperties == null) {
                configProperties = configuration.getProperties() != null ? configuration.getProperties()
                        : new Properties();
                configMap.put(configuration, configProperties);
            }
            if (!value.equals(configProperties.get(property))) {
                configProperties.put(property, value);
                configsToUpdate.put(configuration, configProperties);
            }
        }
    }

    for (Entry<Configuration, Dictionary> entry : configsToUpdate.entrySet()) {
        entry.getKey().update(entry.getValue());
    }
}