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.diyonxbee.internal.DiyOnXBeeBinding.java

@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
    {/*from  ww  w.  j  a  v  a 2s.  c o m*/
        final String serialPort = (String) properties.get("serialPort");
        if (StringUtils.isNotBlank(serialPort)) {
            this.serialPort = serialPort;
        }
    }

    {
        final String baudRate = (String) properties.get("baudRate");
        if (StringUtils.isNotBlank(baudRate)) {
            this.baudRate = Integer.parseInt(baudRate);
        }
    }

    String canonical = serialPort;
    try {
        // This code below enables to use a device name in
        // /dev/serial/by-id/... on linux
        File device = new File(serialPort);
        if (device.canRead()) {
            canonical = device.getCanonicalPath();
        }
    } catch (IOException e1) {
        logger.info("unable to get canonical path for '{}'", serialPort);
        canonical = serialPort;
    }

    xbeeSetupLock.lock();
    try {
        if (xbee != null) {
            xbee.removePacketListener(this);
            xbee.close();
            xbee = null;
        }
        xbee = new XBee();

        try {
            logger.info("opening XBee communication on '{}'", canonical);
            xbee.open(canonical, baudRate);
        } catch (XBeeException e) {
            logger.error("failed to open connection to XBee module", e);
            xbee = null;
            return;
        }
    } finally {
        xbeeSetupLock.unlock();
    }

    xbee.addPacketListener(this);
}

From source file:org.opencastproject.loadtest.impl.LoadTest.java

/**
 * Gets the distribution of media packages to ingest.
 * //from  w  w  w .j  a  v a2s. co m
 * @param properties
 *          The new properties to extract the property from.
 * @throws InvalidConfigurationException
 *           Thrown if property doesn't exist
 */
@SuppressWarnings("unchecked")
private void updatePackageDistribution(Dictionary properties) throws InvalidConfigurationException {
    String packageDistributionsInputString = StringUtils
            .trimToNull((String) properties.get(PACKAGE_DISTRIBUTION_KEY));
    int packageDistributionValue = 0;
    if (packageDistributionsInputString != null) {
        logger.info("Setting package distribution to " + packageDistributionsInputString);
        String[] groups = packageDistributionsInputString.split(",");
        int[] distributions = new int[groups.length];
        String packageDistributionInputString = "";
        for (int i = 0; i < groups.length; i++) {
            packageDistributionInputString = groups[i];
            packageDistributionValue = 0;
            try {
                packageDistributionValue = Integer.parseInt(packageDistributionInputString);
                if (packageDistributionValue < 0) {
                    packageDistributionValue *= -1;
                }
                logger.debug("Set this package distribution to {}", packageDistributionValue);
            } catch (NumberFormatException e) {
                packageDistributionValue = DEFAULT_PACKAGE_DISTRIBUTION_VALUE;
                logger.warn(
                        "Can not set current package distribution to {}. {} must be an integer. It is set to default "
                                + DEFAULT_PACKAGE_DISTRIBUTION_VALUE,
                        packageDistributionsInputString, this.packageDistribution);
            }
            distributions[i] = packageDistributionValue;
        }
        this.packageDistribution = distributions;
    } else {
        logger.info("No package distribution set for load testing so default of 1 load test will be done. ");
        this.packageDistribution = new int[1];
        this.packageDistribution[0] = 1;
    }
}

From source file:edu.northwestern.bioinformatics.studycalendar.osgi.felixcm.internal.PscFelixPersistenceManager.java

@SuppressWarnings({ "unchecked" })
private void doStore(String pid, Dictionary values) {
    List<OsgiConfigurationProperty> existingProperties = getProperties(pid);
    Collection<String> newKeys = EnumerationUtils.toList(values.keys());
    Collection<String> existingKeys = new HashSet<String>();
    for (OsgiConfigurationProperty existingProperty : existingProperties) {
        String existingKey = existingProperty.getName();
        if (newKeys.contains(existingKey)) {
            existingProperty.setValue(values.get(existingKey));
            existingKeys.add(existingKey);
        } else {//www. ja v a  2  s.com
            getHibernateTemplate().delete(existingProperty);
        }
    }
    for (String newKey : newKeys) {
        if (!EXCLUDED_PROPERTIES.contains(newKey) && !existingKeys.contains(newKey)) {
            getHibernateTemplate().save(OsgiConfigurationProperty.create(pid, newKey, values.get(newKey)));
        }
    }
}

From source file:com.github.lburgazzoli.karaf.common.cmd.AbstractManagedService.java

/**
 *
 * @param dictionary/*from   ww w  .  j  a  va  2  s.c om*/
 * @return
 */
protected Properties getConfiguration(Dictionary dictionary) {
    Properties props = null;

    if (dictionary != null) {
        LOGGER.debug("getConfiguration, dictionary={}", dictionary);
        Enumeration keys = dictionary.keys();
        if (keys != null) {
            LOGGER.debug("getConfiguration, keys={}", dictionary);
            props = new Properties();
            while (keys.hasMoreElements()) {
                Object key = keys.nextElement();
                Object val = dictionary.get(key);

                props.put(ObjectUtils.toString(key), ObjectUtils.toString(val, StringUtils.EMPTY));
            }
        }
    }

    if (props == null) {
        LOGGER.warn("No configuration for {}", m_pid);
    }

    return props;
}

From source file:org.opencastproject.loadtest.impl.LoadTest.java

/**
 * Gets the time between ingesting each group of ingests.
 * /* ww w . j  ava 2 s .c o m*/
 * @param properties
 *          The new properties to extract the property from.
 * @throws InvalidConfigurationException
 *           Thrown if property doesn't exist
 */
@SuppressWarnings("unchecked")
private void updatePackageDistributionTimings(Dictionary properties) throws InvalidConfigurationException {
    String packageDistributionTimingsInputString = StringUtils
            .trimToNull((String) properties.get(PACKAGE_DISTRIBUTION_TIMINGS_KEY));
    int packageDistributionTimingValue = 0;
    if (packageDistributionTimingsInputString != null) {
        logger.info("Setting package distribution timing to " + packageDistributionTimingsInputString);
        String[] groups = packageDistributionTimingsInputString.split(",");
        int[] distributions = new int[groups.length];
        String packageDistributionTimingInputString = "";
        for (int i = 0; i < groups.length; i++) {
            packageDistributionTimingInputString = groups[i];
            packageDistributionTimingValue = 0;
            try {
                packageDistributionTimingValue = Integer.parseInt(packageDistributionTimingInputString);
                if (packageDistributionTimingValue < 0) {
                    packageDistributionTimingValue *= -1;
                }
                logger.debug("Set package distribution timing value to {}", packageDistributionTimingValue);
            } catch (NumberFormatException e) {
                packageDistributionTimingValue = DEFAULT_PACKAGE_DISTRIBUTION_TIMING_VALUE;
                logger.warn(
                        "Can not set current package distribution to {}. {} must be an integer. It is set to default "
                                + DEFAULT_PACKAGE_DISTRIBUTION_VALUE,
                        packageDistributionTimingsInputString, packageDistribution);
            }
            distributions[i] = packageDistributionTimingValue;
        }
        packageDistributionTiming = distributions;
    } else {
        logger.info("No package distribution timings set for load testing so default of 0 delay will be done.");
        this.packageDistributionTiming = new int[1];
        this.packageDistributionTiming[0] = 0;
    }
}

From source file:org.opencastproject.videosegmenter.ffmpeg.VideoSegmenterServiceImpl.java

/**
 * {@inheritDoc}/*from w w w  .  j a va 2s.c o  m*/
 *
 * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
 */
@SuppressWarnings("unchecked")
@Override
public void updated(Dictionary properties) throws ConfigurationException {
    if (properties == null) {
        return;
    }
    logger.debug("Configuring the videosegmenter");

    // Stability threshold
    if (properties.get(OPT_STABILITY_THRESHOLD) != null) {
        String threshold = (String) properties.get(OPT_STABILITY_THRESHOLD);
        try {
            stabilityThreshold = Integer.parseInt(threshold);
            logger.info("Stability threshold set to {} consecutive frames", stabilityThreshold);
        } catch (Exception e) {
            logger.warn("Found illegal value '{}' for videosegmenter's stability threshold", threshold);
        }
    }

    // Changes threshold
    if (properties.get(OPT_CHANGES_THRESHOLD) != null) {
        String threshold = (String) properties.get(OPT_CHANGES_THRESHOLD);
        try {
            changesThreshold = Float.parseFloat(threshold);
            logger.info("Changes threshold set to {}", changesThreshold);
        } catch (Exception e) {
            logger.warn("Found illegal value '{}' for videosegmenter's changes threshold", threshold);
        }
    }

}

From source file:org.openhab.binding.mqttdisplay.internal.MqttDisplayBinding.java

/**
 * {@inheritDoc}/*from ww  w .j a  v  a 2 s .co  m*/
 */
@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {

    // Limits to 10 screens maximum. 
    if (parserRules.size() == 0) {
        for (int i = 0; i < 10; i++) {
            parserRules.add(new ArrayList<String>());
        }
    }

    if (config != null) {
        String hostnameString = (String) config.get("brokername");
        if (StringUtils.isNotBlank(hostnameString)) {
            brokername = hostnameString;
        }

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

        /*String content = (String) config.get("content");
        if (StringUtils.isNotBlank(content)) {
           String fields[] = content.split("|");
           int screen = Integer.valueOf(fields[0]);
           int line = Integer.valueOf(fields[1]);
           String displayText = fields[2];
           if ( screen > 0 && line > 0) {
              parserRules.get(screen).set(line, displayText);
           }
           if ( screen > maxScreen ) {
              maxScreen = screen;
           }
           if ( line > maxLine ) {
              maxLine = line;
           }*/

        setProperlyConfigured(true);
    }

}

From source file:org.galicaster.dashboard.DashboardService.java

@SuppressWarnings("unchecked")
protected void activate(ComponentContext cc) throws URISyntaxException {

    // Initialize the object to hold the agent's properties
    agentPasswords = new Properties();

    if ((cc == null) || (cc.getProperties() == null)) {

        mode = MODE_DEFAULT;/*from  ww w . j a  v  a  2 s .  c o  m*/
        logger.debug("Setting default functioning mode: {}", mode.toString());

        pingTimeout = PING_TIMEOUT_DEFAULT;
        logger.debug("Setting default ping timeout: {}", pingTimeout);

        snapshotTimeout = SNAPSHOT_TIMEOUT_DEFAULT;
        logger.debug("Setting default snapshot timeout: {}", snapshotTimeout);

        snapshotPeriod = SNAPSHOT_PERIOD_DEFAULT;
        logger.debug("Setting default snapshot period: {}", snapshotPeriod);

        maxConcurrentSnapshots = MAX_CONCURRENT_DEFAULT;
        logger.debug("Setting default maximum concurrent snapshots: {}", maxConcurrentSnapshots);

        defaultPassword = DEFAULT_PASSWORD_DEFAULT;
        logger.debug("Setting default VNC password default: {}", DEFAULT_PASSWORD_DEFAULT);

    } else {

        // Get the component properties
        Dictionary<String, Object> properties = cc.getProperties();

        // Get the functioning mode.
        String strMode = (String) properties.get(MODE_PROPERTY);
        if (strMode != null) {
            try {
                mode = Mode.valueOf(strMode.toUpperCase());
            } catch (IllegalArgumentException iae) {
                logger.warn("Invalid functioning mode found in configuration file: {}", strMode);
                mode = MODE_DEFAULT;
                logger.debug("Setting default functioning mode: {}", mode.toString());
            }
        }

        // Read the properties that control the "snapshot taking" process
        try {
            pingTimeout = Integer.parseInt((String) properties.get(PING_TIMEOUT_PROPERTY));
        } catch (Exception e) {
            pingTimeout = PING_TIMEOUT_DEFAULT;
        }

        try {
            snapshotTimeout = Integer.parseInt((String) properties.get(SNAPSHOT_TIMEOUT_PROPERTY));
        } catch (Exception e) {
            pingTimeout = SNAPSHOT_TIMEOUT_DEFAULT;
        }

        try {
            snapshotPeriod = Long.parseLong((String) properties.get(SNAPSHOT_PERIOD_PROPERTY));
        } catch (Exception e) {
            snapshotPeriod = SNAPSHOT_PERIOD_DEFAULT;
        }

        try {
            maxConcurrentSnapshots = Integer.parseInt((String) properties.get(MAX_CONCURRENT_PROPERTY));
        } catch (Exception e) {
            maxConcurrentSnapshots = MAX_CONCURRENT_DEFAULT;
        }

        // Get the default VNC password, if it is defined in the config file
        defaultPassword = (String) properties.get(DEFAULT_PASSWORD_PROPERTY);
        if (defaultPassword == null)
            defaultPassword = DEFAULT_PASSWORD_DEFAULT;

        // Get the passwords per agent, if specified in the config file
        Pattern propertyPattern = Pattern.compile(PASSWORD_REGEXP);

        for (Enumeration<String> keys = properties.keys(); keys.hasMoreElements();) {
            String key = keys.nextElement();
            Matcher match = propertyPattern.matcher(key);

            if (match.matches()) {
                agentPasswords.setProperty(match.group(1), (String) properties.get(match.group()));
            }
        }
    }

    // If the mode is PULL, set the security information and start the snapshot threads accordingly
    if (mode == Mode.PULL) {

        // Set security information
        this.systemAccount = cc.getBundleContext().getProperty("org.opencastproject.security.digest.user");

        DefaultOrganization defaultOrg = new DefaultOrganization();
        securityService.setOrganization(defaultOrg);
        securityService
                .setUser(new JaxbUser(systemAccount, defaultOrg, new JaxbRole(GLOBAL_ADMIN_ROLE, defaultOrg)));

        // Start the threads that take the snapshots
        periodicSnapshots = Executors.newScheduledThreadPool(maxConcurrentSnapshots);

        Map<String, Agent> knownAgents = captureAgentStateService.getKnownAgents();
        Random randGen = new Random();
        for (Map.Entry<String, Agent> entry : knownAgents.entrySet()) {
            SnapshotWithDeadline task = new SnapshotWithDeadline(entry.getValue(), tempDir,
                    agentPasswords.getProperty(entry.getKey(), defaultPassword), snapshotTimeout,
                    TimeUnit.SECONDS);

            periodicSnapshots.scheduleAtFixedRate(task, randGen.nextLong() % snapshotPeriod, snapshotPeriod,
                    TimeUnit.SECONDS);
        }
    }

    logger.info("Galicaster Service activated");
}

From source file:org.nuxeo.ecm.platform.web.common.requestcontroller.service.NuxeoCorsFilterDescriptor.java

public FilterConfig buildFilterConfig() {
    final Dictionary<String, String> parameters = buildDictionary();

    return new FilterConfig() {
        @Override//from  w w w.  j a  v  a2s  . co  m
        public String getFilterName() {
            return "NuxeoCorsFilterDescriptor";
        }

        @Override
        public ServletContext getServletContext() {
            // Not used with @see CORSFilter
            return null;
        }

        @Override
        public String getInitParameter(String name) {
            return parameters.get(name);
        }

        @Override
        public Enumeration getInitParameterNames() {
            return parameters.keys();
        }
    };
}