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.dmlsmeter.internal.DmlsMeterBinding.java

/**
 * @{inheritDoc/*  www . ja v a 2  s .com*/
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {

    if (config == null || config.isEmpty()) {
        logger.warn("Empty or null configuration. Ignoring.");
        return;
    }

    Set<String> names = getNames(config);

    for (String name : names) {

        String value = (String) config.get(name + ".serialPort");
        String serialPort = value != null ? value : DmlsMeterDeviceConfig.DEFAULT_SERIAL_PORT;

        value = (String) config.get(name + ".baudRateChangeDelay");
        int baudRateChangeDelay = value != null ? Integer.valueOf(value)
                : DmlsMeterDeviceConfig.DEFAULT_BAUD_RATE_CHANGE_DELAY;

        value = (String) config.get(name + ".echoHandling");
        boolean echoHandling = value != null ? Boolean.valueOf(value)
                : DmlsMeterDeviceConfig.DEFAULT_ECHO_HANDLING;

        DmlsMeterReader reader = createDmlsMeterReader(name,
                new DmlsMeterDeviceConfig(serialPort, baudRateChangeDelay, echoHandling));

        if (meterDevices.put(reader.getName(), reader) != null) {
            logger.info("Recreated reader {} with  {}!", reader.getName(), reader.getConfig());
        } else {
            logger.info("Created reader {} with  {}!", reader.getName(), reader.getConfig());
        }
    }

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

From source file:org.opencastproject.workflow.impl.WorkflowCleanupScanner.java

@Override
public void updated(@SuppressWarnings("rawtypes") Dictionary properties) throws ConfigurationException {
    boolean enabled = false;
    String cronExpression;//from   w w  w .ja v  a2 s .  c o m
    unschedule();

    if (properties != null) {
        logger.debug("Updating configuration...");

        enabled = BooleanUtils.toBoolean((String) properties.get(AbstractScanner.PARAM_KEY_ENABLED));
        setEnabled(enabled);
        logger.debug("enabled = {}", enabled);

        cronExpression = (String) properties.get(AbstractScanner.PARAM_KEY_CRON_EXPR);
        if (StringUtils.isBlank(cronExpression)) {
            throw new ConfigurationException(AbstractScanner.PARAM_KEY_CRON_EXPR,
                    "Cron expression must be valid");
        }
        setCronExpression(cronExpression);
        logger.debug("cronExpression = {}", cronExpression);

        try {
            bufferForSuccessfulJobs = Integer.valueOf((String) properties.get(PARAM_KEY_BUFFER_SUCCEEDED));
        } catch (NumberFormatException e) {
            throw new ConfigurationException(PARAM_KEY_BUFFER_SUCCEEDED, "Buffer must be a valid integer", e);
        }
        logger.debug("bufferForSuccessfulJobs = {}", bufferForSuccessfulJobs);

        try {
            bufferForFailedJobs = Integer.valueOf((String) properties.get(PARAM_KEY_BUFFER_FAILED));
        } catch (NumberFormatException e) {
            throw new ConfigurationException(PARAM_KEY_BUFFER_FAILED, "Buffer must be a valid integer", e);
        }
        logger.debug("bufferForFailedJobs = {}", bufferForFailedJobs);

        try {
            bufferForStoppedJobs = Integer.valueOf((String) properties.get(PARAM_KEY_BUFFER_STOPPED));
        } catch (NumberFormatException e) {
            throw new ConfigurationException(PARAM_KEY_BUFFER_STOPPED, "Buffer must be a valid integer", e);
        }
        logger.debug("bufferForStoppedJobs = {}", bufferForStoppedJobs);

        try {
            bufferForParentlessJobs = Integer.valueOf((String) properties.get(PARAM_KEY_BUFFER_PARENTLESS));
        } catch (NumberFormatException e) {
            throw new ConfigurationException(PARAM_KEY_BUFFER_PARENTLESS, "Buffer must be a valid integer", e);
        }
        logger.debug("bufferForParentlessJobs = {}", bufferForParentlessJobs);
    }

    schedule();
}

From source file:org.onosproject.provider.nil.link.impl.NullLinkProvider.java

@Modified
public void modified(ComponentContext context) {
    if (context == null) {
        log.info("No configs, using defaults: eventRate={}", DEFAULT_RATE);
        return;/*from w  w w  . j a  v  a 2s .c om*/
    }
    Dictionary<?, ?> properties = context.getProperties();
    int newRate;
    String newPath;
    try {
        String s = (String) properties.get("eventRate");
        newRate = isNullOrEmpty(s) ? eventRate : Integer.parseInt(s.trim());
        s = (String) properties.get("cfgFile");
        newPath = s.trim();
    } catch (NumberFormatException | ClassCastException e) {
        log.warn(e.getMessage());
        newRate = eventRate;
        newPath = cfgFile;
    }

    // topology file configuration
    if (!newPath.equals(cfgFile)) {
        cfgFile = newPath;
    }
    readGraph(cfgFile, nodeService.getLocalNode().id());

    // test mode configuration
    if (eventRate != newRate && newRate > 0) {
        driverMap.replaceAll((k, v) -> false);
        eventRate = newRate;
        flicker = true;
    } else if (newRate == 0) {
        driverMap.replaceAll((k, v) -> false);
        flicker = false;
    }

    log.info("Using settings: eventRate={}, topofile={}", eventRate, cfgFile);
    for (Device dev : deviceService.getDevices()) {
        DeviceId did = dev.id();
        synchronized (this) {
            if (driverMap.get(did) == null || !driverMap.get(did)) {
                driverMap.put(dev.id(), true);
                linkDriver.submit(new LinkDriver(dev));
            }
        }
    }
}

From source file:org.openhab.binding.zibase.internal.ZibaseBinding.java

/**
 * @{inheritDoc}/* w w w  .java 2s  .  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>
        logger.debug("Loading zibase configuration");

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

        String ip = (String) config.get("ip");
        if (StringUtils.isNotBlank(ip)) {
            ZibaseBinding.ip = ip;
        }

        String tmpListenerIp = (String) config.get("listenerHost");
        if (StringUtils.isNotBlank(tmpListenerIp)) {
            ZibaseBinding.listenerHost = tmpListenerIp;
        }

        String tmpListenerPort = (String) config.get("listenerPort");
        if (StringUtils.isNotBlank(tmpListenerPort)) {
            ZibaseBinding.listenerPort = Integer.parseInt(tmpListenerPort);
        }

        // read further config parameters here ...
        setProperlyConfigured(true);
        this.launch();
    }
}

From source file:com.buglabs.bug.ws.program.ProgramServlet.java

private Bundle findBundleByName(String name) {
    Bundle[] bundles = context.getBundles();

    for (int i = 0; i < bundles.length; ++i) {
        Dictionary headers = bundles[i].getHeaders();
        if (headers != null) {
            String symbolicName = (String) headers.get("Bundle-Name");
            if (symbolicName != null) {
                if (symbolicName.equals(name)) {
                    return bundles[i];
                }/*from w w w. ja v  a2  s.  c om*/
            }
        }
    }

    return null;
}

From source file:org.openhab.binding.iec6205621meter.internal.Iec6205621MeterBinding.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 || config.isEmpty()) {
        logger.warn("Empty or null configuration. Ignoring.");
        return;
    }

    Set<String> names = getNames(config);

    for (String name : names) {

        String value = (String) config.get(name + ".serialPort");
        String serialPort = value != null ? value : MeterConfig.DEFAULT_SERIAL_PORT;

        value = (String) config.get(name + ".baudRateChangeDelay");
        int baudRateChangeDelay = value != null ? Integer.valueOf(value)
                : MeterConfig.DEFAULT_BAUD_RATE_CHANGE_DELAY;

        value = (String) config.get(name + ".echoHandling");
        boolean echoHandling = value != null ? Boolean.valueOf(value) : MeterConfig.DEFAULT_ECHO_HANDLING;

        Meter meterConfig = createIec6205621MeterConfig(name,
                new MeterConfig(serialPort, baudRateChangeDelay, echoHandling));

        if (meterDeviceConfigurtions.put(meterConfig.getName(), meterConfig) != null) {
            logger.info("Recreated reader {} with  {}!", meterConfig.getName(), meterConfig.getConfig());
        } else {
            logger.info("Created reader {} with  {}!", meterConfig.getName(), meterConfig.getConfig());
        }
    }

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

From source file:org.openhab.binding.benqprojector.internal.BenqProjectorBinding.java

/**
 * @{inheritDoc/*from  ww w .ja  v  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);
        }

        /* decide which transport to use - default is network */
        String modeString = (String) config.get("mode");
        if (StringUtils.isNotBlank(modeString)) {
            if (modeString.equalsIgnoreCase("serial")) {
                transport = new BenqProjectorSerialTransport();
            } else {
                /* default to network */
                transport = new BenqProjectorNetworkTransport();
            }
        } else {
            transport = new BenqProjectorNetworkTransport();
        }

        String deviceIdString = (String) config.get("deviceId");
        if (StringUtils.isNotBlank(deviceIdString)) {
            setProperlyConfigured(transport.setupConnection(deviceIdString));
        }
    }
}

From source file:org.opencastproject.kernel.mail.SmtpService.java

/**
 * Callback from the OSGi <code>ConfigurationAdmin</code> on configuration changes.
 * //from   ww w.  j  a  v  a 2s.  co m
 * @param properties
 *          the configuration properties
 * @throws ConfigurationException
 *           if configuration fails
 */
@SuppressWarnings("rawtypes")
@Override
public void updated(Dictionary properties) throws ConfigurationException {

    // Read the mail server properties
    mailProperties.clear();

    // Mail transport protocol
    mailTransport = StringUtils.trimToNull((String) properties.get(OPT_MAIL_TRANSPORT));
    if (!("smtp".equals(mailTransport) || "smtps".equals(mailTransport))) {
        if (mailTransport != null)
            logger.warn("'{}' procotol not supported. Reverting to default: '{}'", mailTransport,
                    DEFAULT_MAIL_TRANSPORT);
        mailTransport = DEFAULT_MAIL_TRANSPORT;
        logger.debug("Mail transport protocol defaults to '{}'", mailTransport);
    } else {
        logger.debug("Mail transport protocol is '{}'", mailTransport);
    }
    logger.info("Mail transport protocol is '{}'", mailTransport);
    mailProperties.put(OPT_MAIL_TRANSPORT, mailTransport);

    // The mail host is mandatory
    String propName = OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_HOST_SUFFIX;
    mailHost = StringUtils.trimToNull((String) properties.get(propName));
    if (mailHost == null)
        throw new ConfigurationException(propName, "is not set");
    logger.debug("Mail host is {}", mailHost);
    mailProperties.put(propName, mailHost);

    // Mail port
    propName = OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_PORT_SUFFIX;
    String mailPort = StringUtils.trimToNull((String) properties.get(propName));
    if (mailPort == null) {
        mailPort = DEFAULT_MAIL_PORT;
        logger.debug("Mail server port defaults to '{}'", mailPort);
    } else {
        logger.debug("Mail server port is '{}'", mailPort);
    }
    mailProperties.put(propName, mailPort);

    // TSL over SMTP support
    propName = OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_TLS_ENABLE_SUFFIX;
    String smtpStartTLSStr = StringUtils.trimToNull((String) properties.get(propName));
    boolean smtpStartTLS = Boolean.parseBoolean(smtpStartTLSStr);
    if (smtpStartTLS) {
        mailProperties.put(propName, "true");
        logger.debug("TLS over SMTP is enabled");
    } else {
        logger.debug("TLS over SMTP is disabled");
    }

    // Mail user
    mailUser = StringUtils.trimToNull((String) properties.get(OPT_MAIL_USER));
    if (mailUser != null) {
        mailProperties.put(OPT_MAIL_USER, mailUser);
        logger.debug("Mail user is '{}'", mailUser);
    } else {
        logger.debug("Sending mails to {} without authentication", mailHost);
    }

    // Mail password
    mailPassword = StringUtils.trimToNull((String) properties.get(OPT_MAIL_PASSWORD));
    if (mailPassword != null) {
        mailProperties.put(OPT_MAIL_PASSWORD, mailPassword);
        logger.debug("Mail password set");
    }

    // Mail sender
    String mailFrom = StringUtils.trimToNull((String) properties.get(OPT_MAIL_FROM));
    if (mailFrom == null) {
        logger.debug("Mail sender defaults to {}", mailFrom);
    } else {
        logger.debug("Mail sender is '{}'", mailFrom);
    }
    mailProperties.put(OPT_MAIL_FROM, mailFrom);

    // Authentication
    propName = OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_AUTH_SUFFIX;
    mailProperties.put(propName, Boolean.toString(mailUser != null));

    // Mail debugging
    String mailDebug = StringUtils.trimToNull((String) properties.get(OPT_MAIL_DEBUG));
    if (mailDebug != null) {
        boolean mailDebugEnabled = Boolean.parseBoolean(mailDebug);
        mailProperties.put(OPT_MAIL_DEBUG, Boolean.toString(mailDebugEnabled));
        logger.info("Mail debugging is {}", mailDebugEnabled ? "enabled" : "disabled");
    }

    defaultMailSession = null;
    logger.info("Mail service configured with {}", mailHost);

    Properties props = getSession().getProperties();
    for (String key : props.stringPropertyNames())
        logger.info("{}: {}", key, props.getProperty(key));

    // Test
    String mailTest = StringUtils.trimToNull((String) properties.get(OPT_MAIL_TEST));
    if (mailTest != null && Boolean.parseBoolean(mailTest)) {
        logger.info("Sending test message to {}", mailFrom);
        try {
            sendTestMessage(mailFrom);
        } catch (MessagingException e) {
            logger.error("Error sending test message to " + mailFrom + ": " + e.getMessage());
            while (e.getNextException() != null) {
                Exception ne = e.getNextException();
                logger.error("Error sending test message to " + mailFrom + ": " + ne.getMessage());
                if (ne instanceof MessagingException)
                    e = (MessagingException) ne;
                else
                    break;
            }
            throw new ConfigurationException(OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_HOST_SUFFIX,
                    "Failed to send test message to " + mailFrom);
        }
    }
}

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 www .  ja va  2 s. c  o  m
    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.jeelink.internal.JeeLinkBinding.java

/**
 * @{inheritDoc//from  w ww.  j a  va  2s  .co m
 */

public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug("Received new config");
    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 deviceName = (String) config.get(KEY_DEVICE_NAME);
        if (StringUtils.isEmpty(deviceName)) {
            logger.error("No device name configured");
            setProperlyConfigured(false);
            throw new ConfigurationException(KEY_DEVICE_NAME, "The device name can't be empty");
        } else {
            setNewDeviceName(deviceName);
        }

        setProperlyConfigured(true);
        // read further config parameters here ...

    }
}