Example usage for java.util Properties entrySet

List of usage examples for java.util Properties entrySet

Introduction

In this page you can find the example usage for java.util Properties entrySet.

Prototype

@Override
    public Set<Map.Entry<Object, Object>> entrySet() 

Source Link

Usage

From source file:com.impetus.kundera.ejb.EntityManagerFactoryBuilder.java

/**
* Builds up EntityManagerFactory for a given persistenceUnitName and
* overriding properties.//w ww.j  ava 2 s. c om
* 
* @param persistenceUnitName
*            the persistence unit name
* @param override
*            the override
* @return the entity manager factory
*/
public EntityManagerFactory buildEntityManagerFactory(String persistenceUnitName,
        Map<Object, Object> override) {
    PersistenceMetadata metadata = getPersistenceMetadata(persistenceUnitName);

    Properties props = new Properties();
    // Override properties
    Properties metadataProperties = metadata.getProps();
    // Make sure, it's empty or Unmodifiable
    override = override == null ? Collections.EMPTY_MAP : Collections.unmodifiableMap(override);

    // Take all from Metadata and override with supplied map 
    for (Map.Entry<Object, Object> entry : metadataProperties.entrySet()) {
        Object key = entry.getKey();
        Object value = entry.getValue();

        if (override.containsKey(key)) {
            value = override.get(key);
        }
        props.put(key, value);
    }

    // Now take all the remaining ones from override
    for (Map.Entry<Object, Object> entry : override.entrySet()) {
        Object key = entry.getKey();
        Object value = entry.getValue();

        if (!props.containsKey(key)) {
            props.put(key, value);
        }
    }

    log.info("Building EntityManagerFactory for name: " + metadata.getName() + ", and Properties:" + props);
    return new EntityManagerFactoryImpl(metadata, props);
}

From source file:io.microprofile.showcase.web.EndpointService.java

private Endpoints getCachedEndpoints(final String application) throws WebApplicationException {

    Endpoints eps = this.map.get(application);

    if (null == eps) {

        final Properties p = new Properties();

        try (final InputStream is = this.context
                .getResourceAsStream("/WEB-INF/" + application + ".properties")) {
            p.load(is);/*from   ww  w . jav a2 s.co  m*/
        } catch (final Exception e) {
            throw new WebApplicationException("Unexpected error", e);
        }

        final Set<Endpoint> endpointSet = p.entrySet().stream().map(entry -> this
                .getEndpoint(String.class.cast(entry.getKey()), String.class.cast(entry.getValue())))
                .collect(Collectors.toSet());

        eps = new Endpoints();
        eps.setApplication(application);
        eps.setEndpoints(endpointSet);

        eps = this.addHyperMedia(eps);
        this.map.put(application, eps);
    }

    return eps;
}

From source file:com.amalto.core.util.Util.java

public static String convertAutoIncrement(Properties p) {
    StringBuilder buffer = new StringBuilder();
    buffer.append("<AutoIncrement>"); //$NON-NLS-1$
    buffer.append("<id>AutoIncrement</id>"); //$NON-NLS-1$
    if (p != null) {
        for (Entry entry : p.entrySet()) {
            buffer.append("<entry>"); //$NON-NLS-1$
            buffer.append("<key>").append(entry.getKey()).append("</key>"); //$NON-NLS-1$ //$NON-NLS-2$
            buffer.append("<value>").append(entry.getValue()).append("</value>"); //$NON-NLS-1$ //$NON-NLS-2$
            buffer.append("</entry>"); //$NON-NLS-1$
        }/*from   w w  w  .ja  v  a 2 s.  c  o  m*/
    }
    buffer.append("</AutoIncrement>"); //$NON-NLS-1$
    return buffer.toString();
}

From source file:org.apache.falcon.security.FalconAuthenticationFilter.java

/**
 * Returns the configuration from Oozie configuration to be used by the authentication filter.
 * <p/>/*from  w  w  w .j  a v  a2 s.com*/
 * All properties from Oozie configuration which name starts with {@link #FALCON_PREFIX} will
 * be returned. The keys of the returned properties are trimmed from the {@link #FALCON_PREFIX}
 * prefix, for example the Oozie configuration property name 'oozie.authentication.type' will
 * be just 'type'.
 *
 * @param configPrefix configuration prefix, this parameter is ignored by this implementation.
 * @param filterConfig filter configuration, this parameter is ignored by this implementation.
 * @return all Oozie configuration properties prefixed with {@link #FALCON_PREFIX}, without the
 * prefix.
 */
@Override
protected Properties getConfiguration(String configPrefix, FilterConfig filterConfig) {
    Properties authProperties = new Properties();
    Properties configProperties = StartupProperties.get();

    // setting the cookie path to root '/' so it is used for all resources.
    authProperties.setProperty(
            org.apache.hadoop.security.authentication.server.AuthenticationFilter.COOKIE_PATH, "/");

    for (Map.Entry entry : configProperties.entrySet()) {
        String name = (String) entry.getKey();
        if (name.startsWith(FALCON_PREFIX)) {
            String value = (String) entry.getValue();
            name = name.substring(FALCON_PREFIX.length());
            authProperties.setProperty(name, value);
        }
    }

    if (UserGroupInformation.isSecurityEnabled()) { // replace _HOST in principal
        String principal = getKerberosPrincipalWithSubstitutedHost(configProperties);
        // principal cannot be null in secure mode, is validated in submission
        authProperties.setProperty(KerberosAuthenticationHandler.PRINCIPAL, principal);
    }

    return authProperties;
}

From source file:org.sakaiproject.hierarchy.tool.vm.spring.VelocityConfigurer.java

/**
 * Prepare the VelocityEngine instance and return it.
 * /*from w  ww. ja  va2s.  com*/
 * @return the VelocityEngine instance
 * @throws IOException
 *         if the config file wasn't found
 * @throws VelocityException
 *         on Velocity initialization failure
 */
public VelocityEngine createVelocityEngine() throws IOException, VelocityException {
    VelocityEngine velocityEngine = newVelocityEngine();
    if (servletContextHolder == null || servletContextHolder.getServletContext() == null) {
        logger.warn("Servlet ContextHolder  not set, you will not be able to use WebApp based templates, "
                + "please \n"
                + "1. Add a ServletContextHolder bean into applicationContext.xml with the name \n"
                + "2. add the VelocityContextListener to web.xml ");
    } else {
        logger.info("ServletContextHolder Set on path "
                + servletContextHolder.getServletContext().getRealPath("/"));
        velocityEngine.setApplicationAttribute(ServletContext.class.getName(),
                servletContextHolder.getServletContext());

    }

    Properties props = new Properties();

    // Merge local properties if set.
    if (!this.velocityProperties.isEmpty()) {
        props.putAll(this.velocityProperties);
    }

    // Apply properties to VelocityEngine.
    for (Iterator it = props.entrySet().iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        if (!(entry.getKey() instanceof String)) {
            throw new IllegalArgumentException(
                    "Illegal property key [" + entry.getKey() + "]: only Strings allowed");
        }

        velocityEngine.setProperty((String) entry.getKey(), entry.getValue());
    }

    try {
        // Perform actual initialization.
        velocityEngine.init();
    } catch (IOException ex) {
        throw ex;
    } catch (VelocityException ex) {
        throw ex;
    } catch (RuntimeException ex) {
        throw ex;
    } catch (Exception ex) {
        logger.error("Why does VelocityEngine throw a generic checked exception, after all?", ex);
        throw new VelocityException(ex.getMessage());
    }

    return velocityEngine;
}

From source file:com.liferay.portal.dao.jdbc.DataSourceFactoryImpl.java

protected DataSource initDataSourceTomcat(Properties properties) throws Exception {

    PoolProperties poolProperties = new PoolProperties();

    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        String key = (String) entry.getKey();
        String value = (String) entry.getValue();

        // Ignore Liferay properties

        if (isPropertyLiferay(key)) {
            continue;
        }/*  w w w .j  a  v a  2  s  .  c  o  m*/

        // Ignore C3P0 properties

        if (isPropertyC3PO(key)) {
            continue;
        }

        // Ignore Primrose properties

        if (isPropertyPrimrose(key)) {
            continue;
        }

        try {
            BeanUtil.setProperty(poolProperties, key, value);
        } catch (Exception e) {
            if (_log.isWarnEnabled()) {
                _log.warn("Property " + key + " is not a valid Tomcat JDBC " + "Connection Pool property");
            }
        }
    }

    String poolName = PwdGenerator.getPassword(PwdGenerator.KEY2, 8);

    poolProperties.setName(poolName);

    org.apache.tomcat.jdbc.pool.DataSource dataSource = new org.apache.tomcat.jdbc.pool.DataSource(
            poolProperties);

    if (poolProperties.isJmxEnabled()) {
        org.apache.tomcat.jdbc.pool.ConnectionPool jdbcConnectionPool = dataSource.createPool();

        ConnectionPool jmxConnectionPool = jdbcConnectionPool.getJmxPool();

        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

        ObjectName objectName = new ObjectName(_TOMCAT_JDBC_POOL_OBJECT_NAME_PREFIX + poolName);

        mBeanServer.registerMBean(jmxConnectionPool, objectName);
    }

    return dataSource;
}

From source file:com.github.mrstampy.poisonivy.PoisonIvy.java

private void addDOptions(CommandLine cli, List<String> command) {
    Properties props = cli.getOptionProperties("D");
    if (props == null || props.isEmpty())
        return;// w  w w .j av a2  s.  c om

    for (Entry<Object, Object> entry : props.entrySet()) {
        command.add("-D" + entry.getKey() + "=" + entry.getValue());
    }
}

From source file:com.feedzai.commons.sql.abstraction.engine.configuration.PdbProperties.java

/**
 * Merges properties with the existing ones.
 *
 * @param properties The properties to merge.
 *//*www.  j  a  va 2s.c om*/
public final void merge(final Properties properties) {
    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        setProperty(entry.getKey().toString(), entry.getValue().toString());
    }
}

From source file:hudson.plugins.sonar.SonarRunnerBuilder.java

private void loadProperties(ExtendedArgumentListBuilder args, Properties p) {
    for (Entry<Object, Object> entry : p.entrySet()) {
        args.append(entry.getKey().toString(), entry.getValue().toString());
    }/*w  w w  . j a v a2 s.  c o m*/
}

From source file:org.apache.jsieve.ConfigurationManager.java

private ConcurrentMap<String, String> loadConfiguration(final String name) throws IOException {
    final Properties properties = loadProperties(name);
    final ConcurrentMap<String, String> result = new ConcurrentHashMap<String, String>(properties.size(), 1.0f,
            initialConcurrencyLevel);//from  w  w  w . j  a va  2 s.  c om
    for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
        result.put(entry.getKey().toString(), entry.getValue().toString());
    }
    return result;
}