List of usage examples for org.apache.commons.configuration CompositeConfiguration getList
public List getList(String key)
From source file:com.dattack.naming.standalone.StandaloneContextFactory.java
private static Context createInitialContext(final File dir, final Map<?, ?> environment, final CompositeConfiguration configuration) throws NamingException { LOGGER.debug("Scanning directory '{}' for JNDI resources.", dir); try {/*from w ww .j a v a 2s.c o m*/ final StandaloneContext ctx = new StandaloneContext(environment); final NamingLoader loader = new NamingLoader(); final Collection<File> extraClasspath = FilesystemUtils .locateFiles(configuration.getList(CLASSPATH_DIRECTORY_PROPERTY)); loader.loadDirectory(dir, ctx, extraClasspath); LOGGER.debug("JNDI context is ready"); return ctx; } catch (final IOException e) { throw (NamingException) new NamingException(e.getMessage()).initCause(e); } }
From source file:ffx.utilities.Keyword.java
/** * This method sets up configuration properties in the following precedence * * order://w w w . j av a 2 s .com * * 1.) Structure specific properties (for example pdbname.properties) * * 2.) Java system properties a.) -Dkey=value from the Java command line b.) * System.setProperty("key","value") within Java code. * * 3.) User specific properties (~/.ffx/ffx.properties) * * 4.) System wide properties (file defined by environment variable * FFX_PROPERTIES) * * 5.) Internal force field definition. * * @since 1.0 * @param file a {@link java.io.File} object. * @return a {@link org.apache.commons.configuration.CompositeConfiguration} * object. */ public static CompositeConfiguration loadProperties(File file) { /** * Command line options take precedence. */ CompositeConfiguration properties = new CompositeConfiguration(); /** * Structure specific options are first. */ if (file != null) { String filename = file.getAbsolutePath(); filename = org.apache.commons.io.FilenameUtils.removeExtension(filename); String propertyFilename = filename + ".properties"; File structurePropFile = new File(propertyFilename); if (structurePropFile.exists() && structurePropFile.canRead()) { try { properties.addConfiguration(new PropertiesConfiguration(structurePropFile)); properties.addProperty("propertyFile", structurePropFile.getCanonicalPath()); } catch (ConfigurationException | IOException e) { logger.log(Level.INFO, " Error loading {0}.", filename); } } else { propertyFilename = filename + ".key"; structurePropFile = new File(propertyFilename); if (structurePropFile.exists() && structurePropFile.canRead()) { try { properties.addConfiguration(new PropertiesConfiguration(structurePropFile)); properties.addProperty("propertyFile", structurePropFile.getCanonicalPath()); } catch (ConfigurationException | IOException e) { logger.log(Level.INFO, " Error loading {0}.", filename); } } } } /** * Java system properties * * a.) -Dkey=value from the Java command line * * b.) System.setProperty("key","value") within Java code. */ properties.addConfiguration(new SystemConfiguration()); /** * User specific options are 3rd. */ String filename = System.getProperty("user.home") + File.separator + ".ffx/ffx.properties"; File userPropFile = new File(filename); if (userPropFile.exists() && userPropFile.canRead()) { try { properties.addConfiguration(new PropertiesConfiguration(userPropFile)); } catch (ConfigurationException e) { logger.log(Level.INFO, " Error loading {0}.", filename); } } /** * System wide options are 2nd to last. */ filename = System.getenv("FFX_PROPERTIES"); if (filename != null) { File systemPropFile = new File(filename); if (systemPropFile.exists() && systemPropFile.canRead()) { try { properties.addConfiguration(new PropertiesConfiguration(systemPropFile)); } catch (ConfigurationException e) { logger.log(Level.INFO, " Error loading {0}.", filename); } } } /** * Echo the interpolated configuration. */ if (logger.isLoggable(Level.FINE)) { //Configuration config = properties.interpolatedConfiguration(); Iterator<String> i = properties.getKeys(); StringBuilder sb = new StringBuilder(); sb.append(String.format("\n %-30s %s\n", "Property", "Value")); while (i.hasNext()) { String s = i.next(); //sb.append(String.format(" %-30s %s\n", s, Arrays.toString(config.getList(s).toArray()))); sb.append(String.format(" %-30s %s\n", s, Arrays.toString(properties.getList(s).toArray()))); } logger.fine(sb.toString()); } return properties; }