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:ch.entwine.weblounge.cache.impl.CacheServiceImpl.java

/**
 * Configures the caching service. Available options are:
 * <ul>/*from   w w w  . j  a  va2 s .  com*/
 * <li><code>size</code> - the maximum cache size</li>
 * <li><code>filters</code> - the name of the output filters</li>
 * </ul>
 * 
 * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
 */
@SuppressWarnings("rawtypes")
public void updated(Dictionary properties) throws ConfigurationException {
    if (properties == null)
        return;

    // Do we need to clear the cache?
    boolean clear = ConfigurationUtils.isTrue((String) properties.get(OPT_CLEAR), false);
    if (clear) {
        clear();
    }

    // Enabled status
    enabled = ConfigurationUtils.isTrue((String) properties.get(OPT_ENABLE), DEFAULT_ENABLE);
    logger.debug("Cache is {}", diskPersistent ? "enabled" : "disabled");

    debug = ConfigurationUtils.isTrue((String) properties.get(OPT_DEBUG), DEFAULT_DEBUG);
    logger.debug("Cache is {}", diskPersistent ? "enabled" : "disabled");

    // Disk persistence
    diskPersistent = ConfigurationUtils.isTrue((String) properties.get(OPT_DISK_PERSISTENT),
            DEFAULT_DISK_PERSISTENT);
    logger.debug("Cache persistance between reboots is {}", diskPersistent ? "on" : "off");

    // Statistics
    statisticsEnabled = ConfigurationUtils.isTrue((String) properties.get(OPT_ENABLE_STATISTICS),
            DEFAULT_STATISTICS_ENABLED);
    logger.debug("Cache statistics are {}", statisticsEnabled ? "enabled" : "disabled");

    // Max elements in memory
    try {
        maxElementsInMemory = ConfigurationUtils.getValue((String) properties.get(OPT_MAX_ELEMENTS_IN_MEMORY),
                DEFAULT_MAX_ELEMENTS_IN_MEMORY);
        logger.debug("Cache will keep {} elements in memory",
                maxElementsInMemory > 0 ? "up to " + maxElementsInMemory : "all");
    } catch (NumberFormatException e) {
        logger.warn("Value for cache setting '" + OPT_MAX_ELEMENTS_IN_MEMORY + "' is malformed: "
                + (String) properties.get(OPT_MAX_ELEMENTS_IN_MEMORY));
        logger.warn("Cache setting '" + OPT_MAX_ELEMENTS_IN_MEMORY + "' set to default value of "
                + DEFAULT_MAX_ELEMENTS_IN_MEMORY);
        maxElementsInMemory = DEFAULT_MAX_ELEMENTS_IN_MEMORY;
    }

    // Max elements on disk
    try {
        maxElementsOnDisk = ConfigurationUtils.getValue((String) properties.get(OPT_MAX_ELEMENTS_ON_DISK),
                DEFAULT_MAX_ELEMENTS_ON_DISK);
        logger.debug("Cache will keep {} elements on disk",
                maxElementsOnDisk > 0 ? "up to " + maxElementsOnDisk : "all");
    } catch (NumberFormatException e) {
        logger.warn("Value for cache setting '" + OPT_MAX_ELEMENTS_ON_DISK + "' is malformed: "
                + (String) properties.get(OPT_MAX_ELEMENTS_ON_DISK));
        logger.warn("Cache setting '" + OPT_MAX_ELEMENTS_ON_DISK + "' set to default value of "
                + DEFAULT_MAX_ELEMENTS_ON_DISK);
        maxElementsOnDisk = DEFAULT_MAX_ELEMENTS_ON_DISK;
    }

    // Overflow to disk
    overflowToDisk = ConfigurationUtils.isTrue((String) properties.get(OPT_OVERFLOW_TO_DISK),
            DEFAULT_OVERFLOW_TO_DISK);

    // Time to idle
    try {
        timeToIdle = ConfigurationUtils.getValue((String) properties.get(OPT_TIME_TO_IDLE),
                DEFAULT_TIME_TO_IDLE);
        logger.debug("Cache time to idle is set to ", timeToIdle > 0 ? timeToIdle + "s" : "unlimited");
    } catch (NumberFormatException e) {
        logger.warn("Value for cache setting '" + OPT_TIME_TO_IDLE + "' is malformed: "
                + (String) properties.get(OPT_TIME_TO_IDLE));
        logger.warn("Cache setting '" + OPT_TIME_TO_IDLE + "' set to default value of " + DEFAULT_TIME_TO_IDLE);
        timeToIdle = DEFAULT_TIME_TO_IDLE;
    }

    // Time to live
    try {
        timeToLive = ConfigurationUtils.getValue((String) properties.get(OPT_TIME_TO_LIVE),
                DEFAULT_TIME_TO_LIVE);
        logger.debug("Cache time to live is set to ", timeToIdle > 0 ? timeToLive + "s" : "unlimited");
    } catch (NumberFormatException e) {
        logger.warn("Value for cache setting '" + OPT_TIME_TO_LIVE + "' is malformed: "
                + (String) properties.get(OPT_TIME_TO_LIVE));
        logger.warn("Cache setting '" + OPT_TIME_TO_LIVE + "' set to default value of " + DEFAULT_TIME_TO_LIVE);
        timeToLive = DEFAULT_TIME_TO_LIVE;
    }

    for (String cacheId : cacheManager.getCacheNames()) {
        Cache cache = cacheManager.getCache(cacheId);
        if (cache == null)
            continue;
        CacheConfiguration config = cache.getCacheConfiguration();
        config.setOverflowToDisk(overflowToDisk && diskStoreEnabled);
        if (overflowToDisk && diskStoreEnabled) {
            config.setMaxElementsOnDisk(maxElementsOnDisk);
        }
        config.setDiskPersistent(diskPersistent && diskStoreEnabled);
        config.setStatistics(statisticsEnabled);
        config.setMaxElementsInMemory(maxElementsInMemory);
        config.setTimeToIdleSeconds(timeToIdle);
        config.setTimeToLiveSeconds(timeToLive);
    }
}

From source file:com.concursive.connect.config.ApplicationPrefs.java

public String getValue(String section, String parameter, String tagName, String language) {
    if (null == dictionaries) {
        return null;
    }//  www .  j  a  v a2 s . co  m

    final Dictionary dictionary = dictionaries.get(language);
    if (null == dictionary) {
        return null;
    }

    Map prefGroup = (Map) dictionary.getLocalizationPrefs().get(section);
    if (null != prefGroup) {
        Node param = (Node) prefGroup.get(parameter);
        if (null != param) {
            return XMLUtils.getNodeText(XMLUtils.getFirstChild((Element) param, tagName));
        }
    }
    return null;
}

From source file:org.codice.ddf.ui.admin.api.ConfigurationAdminTest.java

/**
 * Tests the {@link ConfigurationAdmin#getProperties(String)} and
 * {@link ConfigurationAdmin#getPropertiesForLocation(String, String)} methods
 *
 * @throws Exception//  www  .  ja  v a  2s .c o  m
 */
@Test
public void testGetProperties() throws Exception {
    org.osgi.service.cm.ConfigurationAdmin testConfigAdmin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
    ConfigurationAdmin configAdmin = new ConfigurationAdmin(testConfigAdmin);

    Configuration testConfig = mock(Configuration.class);
    Dictionary<String, Object> testProp = mock(Dictionary.class);
    Enumeration<String> testKeys = mock(Enumeration.class);

    when(testConfig.getProperties()).thenReturn(testProp);
    when(testProp.get(TEST_KEY)).thenReturn(TEST_VALUE);
    when(testProp.keys()).thenReturn(testKeys);
    when(testKeys.hasMoreElements()).thenReturn(true).thenReturn(false);
    when(testKeys.nextElement()).thenReturn(TEST_KEY);

    when(testConfigAdmin.getConfiguration(TEST_PID, null)).thenReturn(testConfig);
    Map<String, Object> result = configAdmin.getProperties(TEST_PID);

    assertThat("Should return the given properties.", (String) result.get(TEST_KEY), is(TEST_VALUE));
}

From source file:org.eclipse.vtp.framework.engine.http.HttpConnector.java

/**
 * The MIME type for the specified resource.
 * // ww  w . j av a 2  s  .  c o  m
 * @param resourcePath The resource to determine the MIME type of.
 * @return The MIME type for the specified resource.
 */
public String getMimeType(String resourcePath) {
    @SuppressWarnings("rawtypes")
    Dictionary properties = this.properties;
    if (properties == null)
        return null;
    if (resourcePath == null || properties.isEmpty())
        return null;
    int lastSlash = resourcePath.lastIndexOf('/');
    if (lastSlash >= 0)
        resourcePath = resourcePath.substring(lastSlash + 1);
    if (resourcePath.length() == 0)
        return null;
    Object mimeType = properties.get(MIME_TYPE_PREFIX + resourcePath);
    while (!(mimeType instanceof String)) {
        int firstDot = resourcePath.indexOf('.');
        if (firstDot < 0)
            return null;
        resourcePath = resourcePath.substring(firstDot + 1);
        mimeType = properties.get(MIME_TYPE_PREFIX + resourcePath);
    }
    return (String) mimeType;
}

From source file:ddf.catalog.source.opensearch.CddaOpenSearchSite.java

private Map<String, String> updateDefaultClassification() {
    HashMap<String, String> securityProps = new HashMap<String, String>();
    logger.debug("Assigning default classification values");
    if (siteSecurityConfig != null) {
        logger.debug("setting properties from config admin");
        try {//  w  w w  .j a va2  s.c  o m
            // siteSecurityConfig.update();
            @SuppressWarnings("unchecked")
            Dictionary<String, Object> propertyDictionary = (Dictionary<String, Object>) siteSecurityConfig
                    .getProperties();
            Enumeration<String> propertyKeys = propertyDictionary.keys();
            while (propertyKeys.hasMoreElements()) {
                String currKey = propertyKeys.nextElement();
                String currValue = propertyDictionary.get(currKey).toString();
                securityProps.put(currKey, currValue);
            }

            logger.debug("security properties: " + securityProps);

        } catch (Exception e) {
            logger.warn("Exception thrown while trying to obtain default properties.  "
                    + "Setting all default classifications and owner/producers to U and USA respectively as a last resort.",
                    e);
            securityProps.clear(); // this is being cleared, so the
                                   // "last-resort" defaults specified in
                                   // the xsl will be used.

        }
    } else {
        logger.info("site security config is null");
        securityProps.clear(); // this is being cleared, so the
                               // "last-resort" defaults specified in the
                               // xsl will be used.

    }
    return securityProps;
}

From source file:org.openhab.binding.paradox.internal.ParadoxBinding.java

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

    logger.debug("Configuration updated, config {}", config != null ? true : false);

    if (config != null) {
        /*         if (deviceConfigCache == null) {
                    deviceConfigCache = new HashMap<String, DeviceConfig>();
                 }
        */
        HashMap<String, ParadoxDataParserRule> parsingRules = new HashMap<String, ParadoxDataParserRule>();

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

        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;
            }

            // better - more Paradox devices...
            /*            Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key);
                    
                        if (!matcher.matches()) {
                           logger.warn("given config key '"
             + key
             + "' does not follow the expected pattern '<deviceId>.<type|serialPort|refresh>'");
                           continue;
                        }
                    
                        matcher.reset();
                        matcher.find();
                    
                        String deviceId = matcher.group(1);
                    
                        DeviceConfig deviceConfig = deviceConfigCache.get(deviceId);
                    
                        if (deviceConfig == null) {
                           logger.debug("Added new device {}", deviceId);
                           deviceConfig = new DeviceConfig(deviceId);
                           deviceConfigCache.put(deviceId, deviceConfig);
                        }
                    
                        String configKey = matcher.group(2);
                        String value = (String) config.get(key);
                    
                        /**
                         * parsing of valid config:
                         * 
            ############################## Paradox Alarm Binding ##################################
            #
            # Serial port of the first Paradox alarm system to control: 
            # paradox:<devId1>.serialPort=
            #
            # Type of the Paradox printer port, to which we are connecting via serial cable
            # valid options are: PTR1, PTR3, simulate (required)
            # paradox:<devId1>.type=
            #
            # Refresh rate in miliseconds of the in-directional items (optional, defaults to 6000)
            # valid for PTR3 only
            # paradox:<devId1>.refresh=
                    
            # example of valid settings:
            paradox:homealarm.serialPort=COM10
            paradox:homealarm.type=simulate
            paradox:homealarm.refresh=6000
                     
                         *
                        if ("serialPort".equals(configKey)) {
                           deviceConfig.serialPort = value;
                                   
                        } else if ("type".equals(configKey)) {
                           if ("PTR1".equals(value))     deviceConfig.type = PTRtype.PTR1;
                           else if("PTR3".equals(value)) deviceConfig.type = PTRtype.PTR3;
                           else deviceConfig.type = PTRtype.SIMULATE;
                                   
                        } else if ("simulate".equals(configKey)) {
                           if (StringUtils.isNotBlank(value)) {
                              deviceConfig.type = PTRtype.SIMULATE;
                           }
                        } else if ("refresh".equals(configKey)) {
                           deviceConfig.granularity = Integer.parseInt(value);
                        }
                          else
                           throw new ConfigurationException(configKey,
                              "the given configKey '" + configKey + "' is unknown");
                        }
                             
                                
                     setProperlyConfigured(true);
                    
            */
            /**
                        ############################## Paradox Alarm Binding ##################################
                        #
                        # Serial port of the Paradox alarm system to control (required): 
                        # paradox.serialPort=
                        #
                        # Type of the Paradox printer port, to which we are connecting via serial cable
                        # valid options are: PTR1, PTR3 (required)  // use 'simulate' for tests only
                        # paradox.type=
                        #
                        # Refresh rate in milliseconds of the in-directional items (optional, defaults to 6000)
                        # valid for PTR3 only
                        # paradox.refresh=
                    
                        # example of valid settings:
                        paradox.serialPort=COM10
                        paradox.type=PTR1
                        paradox.refresh=6000
            */
            String value = (String) config.get(key);

            if ("serialPort".equals(key)) {
                serialPort = value;

            } else if ("type".equals(key)) {
                if ("PTR1".equals(value))
                    deviceType = PTRtype.PTR1;
                else if ("PTR3".equals(value))
                    deviceType = PTRtype.PTR3;
                else
                    deviceType = PTRtype.SIMULATE;

            } else if ("simulate".equals(key)) {
                if (StringUtils.isNotBlank(value)) {
                    deviceType = PTRtype.SIMULATE;
                }
            } else if ("refresh".equals(key)) {
                granularity = Integer.parseInt(value);
            } else
                throw new ConfigurationException(key, "the given configKey '" + key + "' is unknown");
        }

        if (parsingRules != null) {

            dataParser = new ParadoxDataParser(parsingRules);
        }

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

From source file:org.opendaylight.controller.topologymanager.internal.TopologyManagerImpl.java

/**
 * Function called by the dependency manager when all the required
 * dependencies are satisfied/*from  www  . j av a 2 s  .c  o  m*/
 *
 */
void init(Component c) {
    allocateCaches();
    retrieveCaches();
    String containerName = null;
    Dictionary<?, ?> props = c.getServiceProperties();
    if (props != null) {
        containerName = (String) props.get("containerName");
    } else {
        // In the Global instance case the containerName is empty
        containerName = "UNKNOWN";
    }

    registerWithOSGIConsole();
    loadConfiguration();

    // Restore the shuttingDown status on init of the component
    shuttingDown = false;
    notifyThread = new Thread(new TopologyNotify(notifyQ));
    pendingTimer = new Timer("Topology Pending Update Timer");
    updateThread = new Thread(new UpdateTopology(), "Topology Update");
}

From source file:org.codice.ddf.admin.core.impl.AdminConsoleServiceTest.java

/**
 * Tests the {@link AdminConsoleService#getProperties(String)} and {@link
 * AdminConsoleService#getPropertiesForLocation(String, String)} methods
 *
 * @throws Exception//from w w  w . jav a2s  . co  m
 */
@Test
public void testGetProperties() throws Exception {
    org.osgi.service.cm.ConfigurationAdmin testConfigAdmin = mock(org.osgi.service.cm.ConfigurationAdmin.class);
    AdminConsoleService configAdmin = new AdminConsoleService(testConfigAdmin, configurationAdminImpl) {
        @Override
        public boolean isPermittedToViewService(String servicePid) {
            return true;
        }
    };

    Configuration testConfig = mock(Configuration.class);
    Dictionary<String, Object> testProp = mock(Dictionary.class);
    Enumeration<String> testKeys = mock(Enumeration.class);

    when(testConfig.getProperties()).thenReturn(testProp);
    when(testProp.get(TEST_KEY)).thenReturn(TEST_VALUE);
    when(testProp.keys()).thenReturn(testKeys);
    when(testKeys.hasMoreElements()).thenReturn(true).thenReturn(false);
    when(testKeys.nextElement()).thenReturn(TEST_KEY);

    when(testConfigAdmin.getConfiguration(TEST_PID, null)).thenReturn(testConfig);
    Map<String, Object> result = configAdmin.getProperties(TEST_PID);

    assertThat("Should return the given properties.", result.get(TEST_KEY), is(TEST_VALUE));
}

From source file:org.openhab.binding.squeezebox.internal.SqueezeboxBinding.java

@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    if (config != null) {
        disconnectSqueezeServer();/* w  w w . j a  va2 s. co m*/
        int cliport = DEFAULT_CLI_PORT;
        int webport = DEFAULT_WEB_PORT;
        String host = DEFAULT_HOST;

        Map<String, String> tmpPlayerMap = new HashMap<String, String>();

        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;
            }

            Matcher serverMatcher = EXTRACT_SERVER_CONFIG_PATTERN.matcher(key);
            Matcher playerMatcher = EXTRACT_PLAYER_CONFIG_PATTERN.matcher(key);

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

            if (serverMatcher.matches()) {
                serverMatcher.reset();
                serverMatcher.find();

                if ("host".equals(serverMatcher.group(2))) {
                    host = value;
                } else if ("cliport".equals(serverMatcher.group(2))) {
                    cliport = Integer.valueOf(value);
                } else if ("webport".equals(serverMatcher.group(2))) {
                    webport = Integer.valueOf(value);
                }
            } else if (playerMatcher.matches()) {
                tmpPlayerMap.put(value.toString(), playerMatcher.group(1));
            }
        }

        connectSqueezeServer(host, cliport, webport, tmpPlayerMap);
    }
}

From source file:org.liveSense.service.email.EmailServiceImpl.java

/**
 * Activates this component./*from  w  w w  .  j a v  a2  s  . co  m*/
 * 
 * @param componentContext
 *            The OSGi <code>ComponentContext</code> of this component.
 */
@Activate
protected void activate(ComponentContext componentContext) throws RepositoryException {
    Dictionary<?, ?> props = componentContext.getProperties();
    nodeType = PropertiesUtil.toString(props.get(PARAM_NODE_TYPE), DEFAULT_NODE_TYPE);
    propertyName = PropertiesUtil.toString(props.get(DEFAULT_PROPERTY_NAME), DEFAULT_PROPERTY_NAME);
    spoolFolder = PropertiesUtil.toString(props.get(PARAM_SPOOL_FOLDER), DEFAULT_SPOOL_FOLDER);

    if (spoolFolder.startsWith("/"))
        spoolFolder = spoolFolder.substring(1);
    if (spoolFolder.endsWith("/"))
        spoolFolder = spoolFolder.substring(0, spoolFolder.length() - 1);

    Session admin = repository.loginAdministrative(null);
    String spoolFolders[] = spoolFolder.split("/");
    Node n = admin.getRootNode();
    for (int i = 0; i < spoolFolders.length; i++) {
        if (!n.hasNode(spoolFolders[i])) {
            n = n.addNode(spoolFolders[i]);
        } else {
            n = n.getNode(spoolFolders[i]);
        }
    }
    admin.save();
    admin.logout();

    templateConfig = new Configuration();
}