List of usage examples for org.apache.commons.configuration CompositeConfiguration CompositeConfiguration
public CompositeConfiguration()
From source file:com.shmsoft.dmass.main.ParameterProcessing.java
/** * Default configuration / processing parameters * * @return//from w ww. ja va 2 s.c om */ public static Configuration setDefaultParameters() { CompositeConfiguration cc = new CompositeConfiguration(); try { Configuration defaults = new SHMcloudConfiguration(DEFAULT_PARAMETER_FILE); cc.addConfiguration(defaults); } catch (Exception e) { e.printStackTrace(System.out); // follow the "fail-fast" design pattern System.exit(0); } return cc; }
From source file:com.evolveum.midpoint.init.StartupConfiguration.java
/** * Loading logic/*from www. j a v a 2s .c o m*/ */ private void loadConfiguration(File midpointHome) { if (config != null) { config.clear(); } else { config = new CompositeConfiguration(); } DocumentBuilder documentBuilder = DOMUtil.createDocumentBuilder(); // we need namespace-aware document builder (see GeneralChangeProcessor.java) if (midpointHome != null) { /* configuration logic */ File f = new File(midpointHome, this.getConfigFilename()); System.out.println("Loading midPoint configuration from file " + f); LOGGER.info("Loading midPoint configuration from file {}", f); try { if (!f.exists()) { LOGGER.warn("Configuration file {} does not exists. Need to do extraction ...", f); ApplicationHomeSetup ah = new ApplicationHomeSetup(); ah.init(MIDPOINT_HOME); ClassPathUtil.extractFileFromClassPath(this.getConfigFilename(), f.getPath()); } //Load and parse properties config.addProperty(MIDPOINT_HOME, System.getProperty(MIDPOINT_HOME)); createXmlConfiguration(documentBuilder, f.getPath()); } catch (ConfigurationException e) { String message = "Unable to read configuration file [" + f + "]: " + e.getMessage(); LOGGER.error(message); System.out.println(message); throw new SystemException(message, e); // there's no point in continuing with midpoint initialization } } else { // Load from current directory try { createXmlConfiguration(documentBuilder, this.getConfigFilename()); } catch (ConfigurationException e) { String message = "Unable to read configuration file [" + this.getConfigFilename() + "]: " + e.getMessage(); LOGGER.error(message); System.out.println(message); throw new SystemException(message, e); } } }
From source file:br.eti.kinoshita.testlinkjavaapi.TestLinkAPI.java
/** * Creates application composite configuration. * //w w w . j a v a2s .c o m * @return Application composite configuration. */ private CompositeConfiguration createApplicationConfiguration() { CompositeConfiguration appConfig = new CompositeConfiguration(); appConfig.addConfiguration(new SystemConfiguration()); try { appConfig.addConfiguration(new PropertiesConfiguration("testlinkjavaapi.properties")); } catch (ConfigurationException ce) { this.debug(ce); } return appConfig; }
From source file:com.germinus.easyconf.AggregatedProperties.java
private void addIncludedPropertiesSources(Configuration newConf, CompositeConfiguration loadedConf) { CompositeConfiguration tempConf = new CompositeConfiguration(); tempConf.addConfiguration(prefixedSystemConfiguration); tempConf.addConfiguration(newConf);//ww w .j av a 2s . c o m tempConf.addConfiguration(systemConfiguration); tempConf.addProperty(Conventions.COMPANY_ID_PROPERTY, companyId); tempConf.addProperty(Conventions.COMPONENT_NAME_PROPERTY, componentName); String[] fileNames = tempConf.getStringArray(Conventions.INCLUDE_PROPERTY); for (int i = fileNames.length - 1; i >= 0; i--) { String iteratedFileName = fileNames[i]; addPropertiesSource(iteratedFileName, loadedConf); } }
From source file:com.cloudera.whirr.cm.integration.BaseITServer.java
private static Configuration clusterConfig() { CompositeConfiguration configuration = new CompositeConfiguration(); try {//from www . ja v a 2 s. c om if (System.getProperty("config") != null) { configuration.addConfiguration(new PropertiesConfiguration(System.getProperty("config"))); } configuration.addConfiguration(new PropertiesConfiguration(TEST_CM_TEST_PREFIX_PROPERTIES + (System.getProperty(TEST_PLATFORM) == null || System.getProperty(TEST_PLATFORM).equals("") ? BaseTest.TEST_PLATFORM_DEFAULT : System.getProperty(TEST_PLATFORM)) + ".properties")); configuration.addConfiguration(new PropertiesConfiguration(TEST_CM_TEST_PROPERTIES)); configuration.addConfiguration(new PropertiesConfiguration(TEST_CM_TEST_GLOBAL_PROPERTIES)); configuration.addConfiguration(new PropertiesConfiguration(TEST_CM_EXAMPLE_PROPERTIES)); configuration.addConfiguration(new PropertiesConfiguration( CmServerClusterInstance.class.getClassLoader().getResource(CONFIG_WHIRR_DEFAULT_FILE))); } catch (ConfigurationException e) { throw new RuntimeException("Could not load integration test properties", e); } return configuration; }
From source file:cross.ObjectFactory.java
@Override public <T> T instantiate(final String classname, final Class<T> cls, final String configurationFile) { CompositeConfiguration cc = new CompositeConfiguration(); try {/*from w ww . java2s .c o m*/ File configFileLocation = new File(configurationFile); cc.addConfiguration(new PropertiesConfiguration(configFileLocation.getAbsolutePath())); } catch (ConfigurationException e) { log.warn(e.getLocalizedMessage()); } cc.addConfiguration(this.cfg); return instantiate(classname, cls, cc); }
From source file:ffx.potential.utils.PotentialsFileOpener.java
/** * At present, parses the PDB, XYZ, INT, or ARC file from the constructor * and creates MolecularAssembly and properties objects. *//* w ww . ja v a2 s.c o m*/ @Override public void run() { int numFiles = allFiles.length; for (int i = 0; i < numFiles; i++) { File fileI = allFiles[i]; Path pathI = allPaths[i]; MolecularAssembly assembly = new MolecularAssembly(pathI.toString()); assembly.setFile(fileI); CompositeConfiguration properties = Keyword.loadProperties(fileI); ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties); ForceField forceField = forceFieldFilter.parse(); String patches[] = properties.getStringArray("patch"); for (String patch : patches) { logger.info(" Attempting to read force field patch from " + patch + "."); CompositeConfiguration patchConfiguration = new CompositeConfiguration(); try { patchConfiguration.addProperty("propertyFile", fileI.getCanonicalPath()); } catch (IOException e) { logger.log(Level.INFO, " Error loading {0}.", patch); } patchConfiguration.addProperty("parameters", patch); forceFieldFilter = new ForceFieldFilter(patchConfiguration); ForceField patchForceField = forceFieldFilter.parse(); forceField.append(patchForceField); if (RotamerLibrary.addRotPatch(patch)) { logger.info(String.format(" Loaded rotamer definitions from patch %s.", patch)); } } assembly.setForceField(forceField); if (new PDBFileFilter().acceptDeep(fileI)) { filter = new PDBFilter(fileI, assembly, forceField, properties); } else if (new XYZFileFilter().acceptDeep(fileI)) { filter = new XYZFilter(fileI, assembly, forceField, properties); } else if (new INTFileFilter().acceptDeep(fileI) || new ARCFileFilter().accept(fileI)) { filter = new INTFilter(fileI, assembly, forceField, properties); } else { throw new IllegalArgumentException( String.format(" File %s could not be recognized as a valid PDB, XYZ, INT, or ARC file.", pathI.toString())); } if (filter.readFile()) { if (!(filter instanceof PDBFilter)) { Utilities.biochemistry(assembly, filter.getAtomList()); } filter.applyAtomProperties(); assembly.finalize(true, forceField); //ForceFieldEnergy energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints()); ForceFieldEnergy energy; if (nThreads > 0) { energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints(), nThreads); } else { energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints()); } assembly.setPotential(energy); assemblies.add(assembly); propertyList.add(properties); if (filter instanceof PDBFilter) { PDBFilter pdbFilter = (PDBFilter) filter; List<Character> altLocs = pdbFilter.getAltLocs(); if (altLocs.size() > 1 || altLocs.get(0) != ' ') { StringBuilder altLocString = new StringBuilder("\n Alternate locations found [ "); for (Character c : altLocs) { // Do not report the root conformer. if (c == ' ') { continue; } altLocString.append(format("(%s) ", c)); } altLocString.append("]\n"); logger.info(altLocString.toString()); } /** * Alternate conformers may have different chemistry, so * they each need to be their own MolecularAssembly. */ for (Character c : altLocs) { if (c.equals(' ') || c.equals('A')) { continue; } MolecularAssembly newAssembly = new MolecularAssembly(pathI.toString()); newAssembly.setForceField(assembly.getForceField()); pdbFilter.setAltID(newAssembly, c); pdbFilter.clearSegIDs(); if (pdbFilter.readFile()) { String fileName = assembly.getFile().getAbsolutePath(); newAssembly.setName(FilenameUtils.getBaseName(fileName) + " " + c); filter.applyAtomProperties(); newAssembly.finalize(true, assembly.getForceField()); //energy = new ForceFieldEnergy(newAssembly, filter.getCoordRestraints()); if (nThreads > 0) { energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints(), nThreads); } else { energy = new ForceFieldEnergy(assembly, filter.getCoordRestraints()); } newAssembly.setPotential(energy); assemblies.add(newAssembly); } } } } else { logger.warning(String.format(" Failed to read file %s", fileI.toString())); } } activeAssembly = assemblies.get(0); activeProperties = propertyList.get(0); }
From source file:com.ariht.maven.plugins.config.generator.ConfigGeneratorImpl.java
/** * Filter io contain the properties we wish to substitute in templates. * * Uses Apache Commons Configuration to load filters. *//* w w w .j ava 2s . c om*/ private Properties readFilterIntoProperties(final FileInfo filter) throws ConfigurationException, IOException { final CompositeConfiguration composite = new CompositeConfiguration(); final List<File> files = filter.getFiles(); for (final File file : files) { final PropertiesConfiguration config = new PropertiesConfiguration(file); config.setEncoding(configGeneratorParameters.getEncoding()); composite.addConfiguration(config); } if (StringUtils.isNotBlank(configGeneratorParameters.getFilterSourcePropertyName())) { composite.setProperty(configGeneratorParameters.getFilterSourcePropertyName(), filter.getAllSources()); } return ConfigurationConverter.getProperties(composite); }
From source file:cross.Factory.java
/** * Configures the factory./*from w w w . ja v a2 s . com*/ * * @param config1 the configuration to use */ protected void configureMe(final Configuration config1) { EvalTools.notNull(config1, this); this.configuration = new CompositeConfiguration(); this.configuration.addConfiguration(config1); // this.objconfig.addConfigurationListener(this); if (config1.getBoolean("maltcms.ui.charts.PlotRunner.headless", true) == true) { System.setProperty("java.awt.headless", "true"); } configureThreadPool(this.configuration); //initialize CacheFactory Fragments.setDefaultFragmentCacheType(CacheType .valueOf(this.configuration.getString(Fragments.class.getName() + ".cacheType", "EHCACHE"))); // configure ObjectFactory getObjectFactory().configure(config1); getDataSourceFactory().configure(config1); getInputDataFactory().configure(config1); }
From source file:com.intel.mtwilson.MyConfiguration.java
private Configuration gatherConfiguration(Properties customProperties) { CompositeConfiguration composite = new CompositeConfiguration(); // first priority: custom properties take priority over any other source if (customProperties != null) { MapConfiguration customconfig = new MapConfiguration(customProperties); logConfiguration("custom", customconfig); composite.addConfiguration(customconfig); }// w w w .j a v a 2s . c om // second priority are properties defined on the current JVM (-D switch // or through web container) SystemConfiguration system = new SystemConfiguration(); logConfiguration("system", system); composite.addConfiguration(system); // third priority: environment variables (regular and also converted from dot-notation to all-caps) EnvironmentConfiguration env = new EnvironmentConfiguration(); logConfiguration("environment", env); composite.addConfiguration(env); // AllCapsEnvironmentConfiguration envAllCaps = new AllCapsEnvironmentConfiguration(); // logConfiguration("environment_allcaps", envAllCaps); // composite.addConfiguration(envAllCaps); List<File> files = listConfigurationFiles(); // add all the files we found so far, in the priority order for (File f : files) { // System.out.println("Looking for "+f.getAbsolutePath()); try { if (f.exists() && f.canRead()) { // first check if the file is encrypted... if it is, we need to decrypt it before loading! try (FileInputStream in = new FileInputStream(f)) { String content = IOUtils.toString(in); if (Pem.isPem(content)) { // starts with something like -----BEGIN ENCRYPTED DATA----- and ends with -----END ENCRYPTED DATA----- // a pem-format file indicates it's encrypted... we could check for "ENCRYPTED DATA" in the header and footer too. String password = getApplicationConfigurationPassword(); if (password == null) { log.warn( "Found encrypted configuration file, but no password was found in system properties or environment"); } if (password != null) { ExistingFileResource resource = new ExistingFileResource(f); PasswordEncryptedFile encryptedFile = new PasswordEncryptedFile(resource, password); String decryptedContent = encryptedFile.loadString(); Properties p = new Properties(); p.load(new StringReader(decryptedContent)); MapConfiguration encrypted = new MapConfiguration(p); logConfiguration("encrypted-file:" + f.getAbsolutePath(), encrypted); composite.addConfiguration(encrypted); } } else { log.debug("FILE {} IS IN REGULAR PROPERTIES FORMAT", f.getAbsolutePath()); PropertiesConfiguration standard = new PropertiesConfiguration(f); logConfiguration("file:" + f.getAbsolutePath(), standard); composite.addConfiguration(standard); } } } } catch (FileNotFoundException ex) { // shouldn't happen since we check for f.exists() first, but must handle it because FileInputStream can throw it log.error("File not found: " + f.getAbsolutePath(), ex); } catch (IOException ex) { log.error("Cannot load configuration: " + f.getAbsolutePath(), ex); } catch (ConfigurationException ex) { log.error("Cannot load configuration from " + f.getAbsolutePath(), ex); } } // seventh priority are properties defined on the classpath (for example defaults provided with the application, or placed in the web server container) String propertiesFilename = "mtwilson.properties"; InputStream in = getClass().getResourceAsStream("/" + propertiesFilename); try { // user's home directory (assuming it's on the classpath!) if (in != null) { Properties properties = new Properties(); properties.load(in); MapConfiguration classpath = new MapConfiguration(properties); logConfiguration("classpath:" + propertiesFilename, classpath); composite.addConfiguration(classpath); } } catch (IOException ex) { log.debug("Did not find [" + propertiesFilename + "] properties on classpath", ex); } finally { if (in != null) { try { in.close(); } catch (IOException e) { log.error("Failed to close input stream for " + propertiesFilename); } } } return composite; }