List of usage examples for java.util Properties keySet
@Override
public Set<Object> keySet()
From source file:com.commsen.apropos.core.PropertyPackage.java
/** * Reads external {@link Properties} and adds them all to this package. * //from ww w .j ava 2 s. c o m * @param externalProperties the external properties to be added * @param overwrite boolean flag indicating whether to overwrite existing properties * @throws IllegalArgumentException if <code>externalProperties</code> is null */ public void importProperties(Properties externalProperties, boolean overwrite) { if (externalProperties == null) throw new IllegalArgumentException("properties can not be null"); for (Object key : externalProperties.keySet()) { String propertyName = (String) key; if (!overwrite && this.properties.containsKey(propertyName)) continue; try { this.properties.put(propertyName, new Property(propertyName, externalProperties.getProperty(propertyName), null, null)); } catch (PropertiesException e) { /* * this should never happen since the key in Properties can not be null and that is * the only case where new Property() throws PropertiesException */ throw new InternalError(e.getMessage()); } } }
From source file:conf.DBCPConnectionProvider.java
public void configure(Properties props) throws HibernateException { try {//from w w w . j a v a 2s.c om log.debug("Configure DBCPConnectionProvider"); // DBCP properties used to create the BasicDataSource Properties dbcpProperties = new Properties(); // DriverClass & url String jdbcDriverClass = props.getProperty(Environment.DRIVER); String jdbcUrl = props.getProperty(Environment.URL); dbcpProperties.put("driverClassName", jdbcDriverClass); dbcpProperties.put("url", jdbcUrl); // Username / password String username = props.getProperty(Environment.USER); String password = props.getProperty(Environment.PASS); dbcpProperties.put("username", username); dbcpProperties.put("password", password); // Isolation level String isolationLevel = props.getProperty(Environment.ISOLATION); if ((isolationLevel != null) && (isolationLevel.trim().length() > 0)) { dbcpProperties.put("defaultTransactionIsolation", isolationLevel); } // Turn off autocommit (unless autocommit property is set) String autocommit = props.getProperty(AUTOCOMMIT); if ((autocommit != null) && (autocommit.trim().length() > 0)) { dbcpProperties.put("defaultAutoCommit", autocommit); } else { dbcpProperties.put("defaultAutoCommit", String.valueOf(Boolean.FALSE)); } // Pool size String poolSize = props.getProperty(Environment.POOL_SIZE); if ((poolSize != null) && (poolSize.trim().length() > 0) && (Integer.parseInt(poolSize) > 0)) { dbcpProperties.put("maxActive", poolSize); } // Copy all "driver" properties into "connectionProperties" Properties driverProps = ConnectionProviderFactory.getConnectionProperties(props); if (driverProps.size() > 0) { StringBuffer connectionProperties = new StringBuffer(); for (Iterator iter = driverProps.keySet().iterator(); iter.hasNext();) { String key = (String) iter.next(); String value = driverProps.getProperty(key); connectionProperties.append(key).append('=').append(value); if (iter.hasNext()) { connectionProperties.append(';'); } } dbcpProperties.put("connectionProperties", connectionProperties.toString()); } // Copy all DBCP properties removing the prefix for (Iterator iter = props.keySet().iterator(); iter.hasNext();) { String key = String.valueOf(iter.next()); if (key.startsWith(PREFIX)) { String property = key.substring(PREFIX.length()); String value = props.getProperty(key); dbcpProperties.put(property, value); } } // Backward-compatibility if (props.getProperty(DBCP_PS_MAXACTIVE) != null) { dbcpProperties.put("poolPreparedStatements", String.valueOf(Boolean.TRUE)); dbcpProperties.put("maxOpenPreparedStatements", props.getProperty(DBCP_PS_MAXACTIVE)); } // Some debug info if (log.isDebugEnabled()) { log.debug("Creating a DBCP BasicDataSource with the following DBCP factory properties:"); StringWriter sw = new StringWriter(); dbcpProperties.list(new PrintWriter(sw, true)); log.debug(sw.toString()); } // Let the factory create the pool ds = (BasicDataSource) BasicDataSourceFactory.createDataSource(dbcpProperties); // The BasicDataSource has lazy initialization // borrowing a connection will start the DataSource // and make sure it is configured correctly. Connection conn = ds.getConnection(); conn.close(); // Log pool statistics before continuing. logStatistics(); } catch (Exception e) { String message = "Could not create a DBCP pool"; log.fatal(message, e); if (ds != null) { try { ds.close(); } catch (Exception e2) { // ignore } ds = null; } throw new HibernateException(message, e); } log.debug("Configure DBCPConnectionProvider complete"); }
From source file:com.agnie.useradmin.tools.dbinit.DBInit.java
private Properties readInitProperties() { Properties initProperties = new Properties(); AgnieDeploymentConfig config = new AgnieDeploymentConfig("global"); try {/*from w w w .j av a 2s. c o m*/ initProperties.load(new FileInputStream(new File(config.getConfig() + "/init-db.properties"))); } catch (IOException e) { logger.error("Error while reading init-db.properties : ", e); } boolean notSet = false; for (Object key : initProperties.keySet()) { String value = initProperties.getProperty((String) key); if (value == null || value.isEmpty() || value.startsWith("<")) { logger.error("Property '" + key + "' is not set with value"); System.out.println("Property '" + key + "' is not set with value"); notSet = true; } } if (notSet) { System.out.println("Error init-db.properties is not set with required values"); System.exit(1); } return initProperties; }
From source file:org.apache.hadoop.minikdc.MiniKdc.java
/** * Creates a MiniKdc./* ww w . jav a 2s. co m*/ * * @param conf MiniKdc configuration. * @param workDir working directory, it should be the build directory. Under * this directory an ApacheDS working directory will be created, this * directory will be deleted when the MiniKdc stops. * @throws Exception thrown if the MiniKdc could not be created. */ public MiniKdc(Properties conf, File workDir) throws Exception { if (!conf.keySet().containsAll(PROPERTIES)) { Set<String> missingProperties = new HashSet<String>(PROPERTIES); missingProperties.removeAll(conf.keySet()); throw new IllegalArgumentException("Missing configuration properties: " + missingProperties); } this.workDir = new File(workDir, Long.toString(System.currentTimeMillis())); if (!workDir.exists() && !workDir.mkdirs()) { throw new RuntimeException("Cannot create directory " + workDir); } LOG.info("Configuration:"); LOG.info("---------------------------------------------------------------"); for (Map.Entry<?, ?> entry : conf.entrySet()) { LOG.info(" {}: {}", entry.getKey(), entry.getValue()); } LOG.info("---------------------------------------------------------------"); this.conf = conf; port = Integer.parseInt(conf.getProperty(KDC_PORT)); String orgName = conf.getProperty(ORG_NAME); String orgDomain = conf.getProperty(ORG_DOMAIN); realm = orgName.toUpperCase(Locale.ENGLISH) + "." + orgDomain.toUpperCase(Locale.ENGLISH); }
From source file:org.alloy.metal.xml.merge.MergeContext.java
/** * Removes all keys that share the same number. (e.g. if xpath.28 is the key * then handler.28, xpath.28, and priority.28 will all be removed). * * @param firstKey/* w ww . j av a 2s .c om*/ * @param props * @return */ private void removeItemsMatchingKey(String firstKey, Properties props) { int dotPos = firstKey.indexOf("."); if (dotPos > 0) { String keyNumberToMatch = firstKey.substring(dotPos); Iterator<Object> iter = props.keySet().iterator(); while (iter.hasNext()) { Object keyObj = iter.next(); if (keyObj instanceof String) { String keyStr = (String) keyObj; dotPos = keyStr.indexOf("."); String keyNumber = keyStr.substring(dotPos); if (keyNumber.equals(keyNumberToMatch)) { iter.remove(); } } } } }
From source file:edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageImpl.java
/** * Load the namespaces file from the disk. It's easy to load into a * {@link Properties}, but we need to convert it to a {@link Map}. *//* w ww . j a va2 s. c o m*/ private Map<Character, String> readNamespaces() throws IOException { Reader reader = null; try { reader = new FileReader(this.namespaceFile); Properties props = new Properties(); props.load(reader); Map<Character, String> map = new HashMap<Character, String>(); for (Object key : props.keySet()) { char keyChar = key.toString().charAt(0); map.put(keyChar, (String) props.get(key)); } return map; } catch (Exception e) { throw new IOException("Problem loading the namespace file."); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } }
From source file:com.hs.mail.mailet.RemoteDelivery.java
/** * Initialize the mailet//w ww .j ava2 s.com */ public void init(MailetContext context) { super.init(context); Properties props = new Properties(); Properties sysprops = System.getProperties(); for (Object key : sysprops.keySet()) { if (((String) key).startsWith("mail.")) { props.put(key, sysprops.get(key)); } } if (this.debug) props.setProperty("mail.debug", "true"); props.setProperty("mail.smtp.timeout", smtpTimeout + ""); props.setProperty("mail.smtp.connectiontimeout", connectionTimeout + ""); props.setProperty("mail.smtp.sendpartial", String.valueOf(sendPartial)); props.setProperty("mail.smtp.localhost", Config.getHelloName()); this.maxRetries = (int) Config.getNumberProperty("max_retry_count", 3); this.session = Session.getInstance(props, null); this.session.setDebug(this.debug); this.gateway = Config.getProperty("smtp_gateway", null); this.authUser = Config.getProperty("smtp_gateway_username", null); this.authPass = Config.getProperty("smtp_gateway_password", null); }
From source file:com.antonjohansson.geolocation.config.Configuration.java
private <T> T getInstance(Properties properties, Class<T> target) { String type = target.getSimpleName().toLowerCase(); String className = properties.getProperty(type); Class<?> clazz = getClass(className); if (!target.isAssignableFrom(clazz)) { throw new RuntimeException("'" + clazz.getName() + "' is not a valid " + type); }//from w w w .j a v a2 s.co m T instance = newInstance(clazz.asSubclass(target)); List<String> keys = properties.keySet().stream().filter(key -> key instanceof String) .map(key -> (String) key).filter(key -> key.startsWith(type)) .filter(key -> key.length() > type.length()).map(key -> key.substring(type.length() + 1)) .filter(key -> isWriteable(instance, key)).collect(toList()); for (String key : keys) { Object value = properties.get(type + "." + key); try { setProperty(instance, key, value); } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } } return instance; }