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.davis.internal.DavisBinding.java

public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.trace("update() 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);
        }// ww  w.  j ava2  s.c  o m
        String newPort = (String) config.get("port"); //$NON-NLS-1$
        if (StringUtils.isNotBlank(newPort) && !newPort.equals(port)) {
            port = newPort;
            setProperlyConfigured(true);
        }
    }
}

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  ww  .  ja  v a  2s.  c  om*/
        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.fs20.internal.FS20Binding.java

/**
 * @{inheritDoc/* w  w w . j a v a 2s.c  om*/
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug("Received new config");
    if (config != null) {

        Boolean configChanged = false;
        /**
         * Valid values of the baudRateString
         * "75", "110", "300", "1200", "2400", "4800", 
         * "9600", "19200", "38400", "57600", "115200"
         * @see org.openhab.io.transport.cul.internal.CULSerialHandlerImpl
         */
        String baudRateString = (String) config.get(KEY_BAUD_RATE);
        if (StringUtils.isNotBlank(baudRateString)) {
            properties.put(KEY_BAUD_RATE, baudRateString);
            configChanged = true;
        }

        /**
         * Valid values of the parityString
         * "NONE"
         * "ODD"
         * "EVEN"
         * "MARK"
         * "SPACE"
         * @see org.openhab.io.transport.cul.internal.CULSerialHandlerImpl
         */
        String parityString = (String) config.get(KEY_PARITY);
        if (StringUtils.isNotBlank(parityString)) {
            properties.put(KEY_PARITY, parityString);
            configChanged = true;
        }

        // 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 {
            this.deviceName = deviceName;
            configChanged = true;
        }

        if (configChanged) {
            updateDeviceSettings();
        }

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

    }
}

From source file:org.openhab.binding.mqtt.internal.MqttEventBusBinding.java

@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {

    // load event bus pubish/subscribe configuration from configuration file
    if (properties == null || properties.isEmpty()) {
        logger.trace("No mqtt-eventbus properties configured.");
        return;/*  w w w .ja va 2s  .c  o m*/
    }

    logger.debug("Initializing MQTT Event Bus Binding");

    // stop existing publishers/subscribers
    deactivate();

    brokerName = (String) properties.get("broker");
    if (StringUtils.isEmpty(brokerName)) {
        logger.debug("No broker name configured for MQTT EventBusBinding");
        return;
    }

    setupEventBusStatePublisher((String) properties.get("statePublishTopic"));
    setupEventBusStateSubscriber((String) properties.get("stateSubscribeTopic"));
    setupEventBusCommandPublisher((String) properties.get("commandPublishTopic"));
    setupEventBusCommandSubscriber((String) properties.get("commandSubscribeTopic"));

    logger.debug("MQTT Event Bus Binding initialization completed.");
}

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

/**
 * Copies the setup of a {@link Group}.//from w w w.ja  v a 2  s . co 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.maxcul.internal.MaxCulBinding.java

/**
 * @{inheritDoc/*  ww w.ja  v a  2  s.c  om*/
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug("MaxCUL Reading config");
    if (config != null) {

        // handle timezone configuration
        // maxcul:timezone=Europe/London
        String timezoneString = (String) config.get("timezone");
        if (StringUtils.isNotBlank(timezoneString)) {
            this.tzStr = timezoneString;
        } else {
            this.tzStr = "Europe/London";
        }

        // handle device config
        // maxcul:device=/dev/cul
        String deviceString = (String) config.get("device");
        if (StringUtils.isNotBlank(deviceString)) {
            logger.debug("Setting up device " + deviceString);
            setupDevice(deviceString, config);
            if (cul == null)
                throw new ConfigurationException("device",
                        "Configuration failed. Unable to access CUL device " + deviceString);
        } else {
            throw new ConfigurationException("device", "No device set - please set one");
        }
    }
}

From source file:org.openhab.binding.k8055.internal.k8055Binding.java

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

    logger.debug("updated() called");
    setProperlyConfigured(false);
    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 boardNum = (String) config.get("boardno");
        if (StringUtils.isNotBlank(boardNum)) {
            try {
                boardNo = Integer.parseInt(boardNum);
                setProperlyConfigured(true);
            } catch (NumberFormatException e) {
                logger.error("Invalid board number: " + boardNum);
                throw new ConfigurationException("boardno", boardNum + " is not a valid board number.");
            }
        }

    } else {
        logger.info("No config supplied - using default values");
    }

    if (isProperlyConfigured()) {
        // Connect to hardware
        connect();
    }
}

From source file:org.ops4j.pax.web.itest.jetty.WhiteboardR6IntegrationTest.java

private ServiceRegistration<Servlet> registerServlet(Dictionary<String, String> extendedProps) {
    Dictionary<String, String> properties = new Hashtable<>();
    properties.put("osgi.http.whiteboard.servlet.pattern", "/myservlet");
    properties.put("servlet.init.myname", "value");

    if (extendedProps != null) {
        Enumeration<String> keys = extendedProps.keys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            properties.put(key, extendedProps.get(key));
        }/*from w ww .  j  a va  2s  . c o m*/
    }

    ServiceRegistration<Servlet> registerService = bundleContext.registerService(Servlet.class, new MyServlet(),
            properties);
    return registerService;
}

From source file:org.paxle.core.filter.impl.FilterManager.java

/**
 * Registering a new {@link IFilter}/*  w w  w  . j  a  v  a2s .c o m*/
 * @param filterContext the context-object for the {@link IFilter}
 */
@SuppressWarnings("unchecked")
public synchronized void addFilter(FilterContext filterContext) {
    if (filterContext == null)
        throw new NullPointerException("The filtercontext is null");

    final String queueID = filterContext.getTargetID();
    final String filterPID = filterContext.getFilterPID();
    final String filterContextPID = filterContext.getFilterContextPID();
    final boolean enabledPerDefault = filterContext.isEnabled();
    try {
        /* disable context for now */
        filterContext.setEnabled(false);

        /* 
         * Getting the registered-filter-list of the target
         * and add the new filter to it
         */
        final Set<FilterContext> knownFilters = this.getRegisteredFilters(queueID);
        knownFilters.add(filterContext);

        /* 
         * getting the enabled-filter-list
         * and add the new filter-to it (if newly installed)
         */
        final Set<String> enabledFilters = this.getEnabledFilters(queueID);

        // check if we have detected a newly installed filter
        if (!this.knownFilterContexts.contains(filterContextPID)) {
            this.knownFilterContexts.add(filterContextPID);

            /* If newly installed filters should be enabled per default and
             * the filter-provider has not disabled the filter per default
             * we enable the filter now
             */
            if (this.enableNewFilters.booleanValue() && enabledPerDefault) {
                // mark filter-context as enabled
                filterContext.setEnabled(true);

                // remember enabled filter in list
                enabledFilters.add(filterContextPID);

                // updating CM if needed
                Dictionary<String, Object> props = this.config.getProperties();
                if (props.get(CM_FILTER_ENABLED_FILTERS + queueID) != null) {
                    // we need to update the list
                    props.put(CM_FILTER_ENABLED_FILTERS + queueID,
                            enabledFilters.toArray(new String[enabledFilters.size()]));
                    this.config.update(props);
                }
            } else {
                filterContext.setEnabled(false);
            }
        } else if (props.get(CM_FILTER_ENABLED_FILTERS + queueID) != null) {
            boolean enabled = enabledFilters.contains(filterContextPID);
            filterContext.setEnabled(enabled);
        }

        // if the queue is already registered pass the filters to it
        if (this.queues.containsKey(queueID)) {
            /*
             * passing the changed filter-list to the filter-queue
             */
            IFilterQueue queue = this.getQueue(queueID);
            this.setFilters(queue, knownFilters, enabledFilters);
        }
    } catch (Throwable e) {
        this.logger.error(String.format("Unexpected '%s' while registering a new filter '%s' for queue '%s'.",
                e.getClass().getName(), filterPID, queueID));
    }
}

From source file:org.openhab.binding.plclogo.internal.PLCLogoBinding.java

@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    Boolean configured = false;/* w  w w.  j a v a2s.  com*/
    if (config != null) {
        String refreshIntervalString = Objects.toString(config.get("refresh"), null);
        if (StringUtils.isNotBlank(refreshIntervalString)) {
            refreshInterval = Long.parseLong(refreshIntervalString);
        }

        if (controllers == null) {
            controllers = new HashMap<String, PLCLogoConfig>();
        }

        Enumeration<String> keys = config.keys();
        while (keys.hasMoreElements()) {
            String key = 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 controllerName = matcher.group(1);
            PLCLogoConfig deviceConfig = controllers.get(controllerName);

            if (deviceConfig == null) {
                deviceConfig = new PLCLogoConfig();
                controllers.put(controllerName, deviceConfig);
                logger.info("Create new config for {}", controllerName);
            }
            if (matcher.group(2).equals("host")) {
                String ip = config.get(key).toString();
                deviceConfig.setIP(ip);
                logger.info("Set host of {}: {}", controllerName, ip);
                configured = true;
            }
            if (matcher.group(2).equals("remoteTSAP")) {
                String tsap = config.get(key).toString();
                deviceConfig.setRemoteTSAP(Integer.decode(tsap));
                logger.info("Set remote TSAP for {}: {}", controllerName, tsap);
            }
            if (matcher.group(2).equals("localTSAP")) {
                String tsap = config.get(key).toString();
                deviceConfig.setLocalTSAP(Integer.decode(tsap));
                logger.info("Set local TSAP for {}: {}", controllerName, tsap);
            }
            if (matcher.group(2).equals("model")) {
                PLCLogoModel model = null;
                String modelName = config.get(key).toString();
                if (modelName.equalsIgnoreCase("0BA7")) {
                    model = PLCLogoModel.LOGO_MODEL_0BA7;
                } else if (modelName.equalsIgnoreCase("0BA8")) {
                    model = PLCLogoModel.LOGO_MODEL_0BA8;
                } else {
                    logger.info("Found unknown model for {}: {}", controllerName, modelName);
                }

                if (model != null) {
                    deviceConfig.setModel(model);
                    logger.info("Set model for {}: {}", controllerName, modelName);
                }
            }
        } // while

        Iterator<Entry<String, PLCLogoConfig>> entries = controllers.entrySet().iterator();
        while (entries.hasNext()) {
            Entry<String, PLCLogoConfig> thisEntry = entries.next();
            String controllerName = thisEntry.getKey();
            PLCLogoConfig deviceConfig = thisEntry.getValue();
            S7Client LogoS7Client = deviceConfig.getS7Client();
            if (LogoS7Client == null) {
                LogoS7Client = new Moka7.S7Client();
            } else {
                LogoS7Client.Disconnect();
            }
            LogoS7Client.SetConnectionParams(deviceConfig.getlogoIP(), deviceConfig.getlocalTSAP(),
                    deviceConfig.getremoteTSAP());
            logger.info("About to connect to {}", controllerName);

            if ((LogoS7Client.Connect() == 0) && LogoS7Client.Connected) {
                logger.info("Connected to PLC LOGO! device {}", controllerName);
            } else {
                logger.error("Could not connect to PLC LOGO! device {} : {}", controllerName,
                        S7Client.ErrorText(LogoS7Client.LastError));
                throw new ConfigurationException("Could not connect to PLC LOGO! device ",
                        controllerName + " " + deviceConfig.getlogoIP());
            }
            deviceConfig.setS7Client(LogoS7Client);
        }

        setProperlyConfigured(configured);
    } else {
        logger.info("No configuration for PLCLogoBinding");
    }
}