List of usage examples for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration
public PropertiesConfiguration(URL url) throws ConfigurationException
From source file:fi.kela.kanta.cda.MaarittelyKonfiguraatio.java
@SuppressWarnings("unchecked") private MaarittelyKonfiguraatio() throws ConfigurationException { maarittelyt = new HashMap<String, MaarittelyLuokka>(); try {// w ww .j a v a2s . co m Configuration config = new PropertiesConfiguration("cda_template.properties"); Iterator<String> templateIds = (Iterator<String>) config.getKeys(); while (templateIds.hasNext()) { kasitteleTyyppi(config, templateIds.next()); } } catch (ConfigurationException e) { throw e; } }
From source file:com.siemens.scr.avt.ad.query.common.NaturalJoinTreeTest.java
@Test public void testLoadingFromHibernateMapping() throws JDOMException, IOException, ConfigurationException { joinTree.loadFromHibernateMapping(this.getClass().getResourceAsStream(testMapping)); PropertiesConfiguration config = new PropertiesConfiguration(expectedFK); HashMap<String, String[]> fks = new HashMap<String, String[]>(); Iterator it = config.getKeys(); while (it.hasNext()) { String key = (String) it.next(); fks.put(key, config.getStringArray(key)); }/*from w ww . j a va 2 s . c o m*/ Set edges = getGraph().getEdges(); assertEquals(fks.keySet().size(), edges.size()); for (Object obj : edges) { NaturalFKEdge edge = (NaturalFKEdge) obj; assertEquals(fks.get(edge.getFK())[0], edge.getEndpoints().getFirst().toString()); assertEquals(fks.get(edge.getFK())[1], edge.getEndpoints().getSecond().toString()); } }
From source file:io.nuun.plugin.configuration.common.NuunCommonConfigurationPlugin.java
/** * reach properties file from classpath. * //from w w w . ja v a 2s .c o m * @param filePathInClasspath * @return return an Apache Configuration interface */ private Configuration configuration(String filePathInClasspath) { try { return new PropertiesConfiguration(filePathInClasspath); } catch (ConfigurationException e) { e.printStackTrace(); throw new IllegalStateException("Error in module initialization : Properties can not be initialized"); } }
From source file:cc.kune.wave.server.CustomSettingsBinder.java
/** * Bind configuration parameters into Guice Module. * * @param propertyFile the property file * @param settingsArg the settings arg/*from www. ja va 2s . co m*/ * @return a Guice module configured with setting support. * @throws ConfigurationException on configuration error */ public static Module bindSettings(String propertyFile, Class<?>... settingsArg) throws ConfigurationException { final CompositeConfiguration config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); config.addConfiguration(new PropertiesConfiguration(propertyFile)); List<Field> fields = new ArrayList<Field>(); for (Class<?> settings : settingsArg) { fields.addAll(Arrays.asList(settings.getDeclaredFields())); } // Reflect on settings class and absorb settings final Map<Setting, Field> settings = new LinkedHashMap<Setting, Field>(); for (Field field : fields) { if (!field.isAnnotationPresent(Setting.class)) { continue; } // Validate target type SettingTypeValidator typeHelper = supportedSettingTypes.get(field.getType()); if (typeHelper == null || !typeHelper.check(field.getGenericType())) { throw new IllegalArgumentException(field.getType() + " is not one of the supported setting types"); } Setting setting = field.getAnnotation(Setting.class); settings.put(setting, field); } // Now validate them List<String> missingProperties = new ArrayList<String>(); for (Setting setting : settings.keySet()) { if (setting.defaultValue().isEmpty()) { if (!config.containsKey(setting.name())) { missingProperties.add(setting.name()); } } } if (missingProperties.size() > 0) { StringBuilder error = new StringBuilder(); error.append("The following required properties are missing from the server configuration: "); error.append(Joiner.on(", ").join(missingProperties)); throw new ConfigurationException(error.toString()); } // bundle everything up in an injectable guice module return new AbstractModule() { @Override protected void configure() { // We must iterate the settings a third time when binding. // Note: do not collapse these loops as that will damage // early error detection. The runtime is still O(n) in setting count. for (Map.Entry<Setting, Field> entry : settings.entrySet()) { Class<?> type = entry.getValue().getType(); Setting setting = entry.getKey(); if (int.class.equals(type)) { Integer defaultValue = null; if (!setting.defaultValue().isEmpty()) { defaultValue = Integer.parseInt(setting.defaultValue()); } bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getInteger(setting.name(), defaultValue)); } else if (boolean.class.equals(type)) { Boolean defaultValue = null; if (!setting.defaultValue().isEmpty()) { defaultValue = Boolean.parseBoolean(setting.defaultValue()); } bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getBoolean(setting.name(), defaultValue)); } else if (String.class.equals(type)) { bindConstant().annotatedWith(Names.named(setting.name())) .to(config.getString(setting.name(), setting.defaultValue())); } else { String[] value = config.getStringArray(setting.name()); if (value.length == 0 && !setting.defaultValue().isEmpty()) { value = setting.defaultValue().split(","); } bind(new TypeLiteral<List<String>>() { }).annotatedWith(Names.named(setting.name())).toInstance(ImmutableList.copyOf(value)); } } } }; }
From source file:com.ibm.replication.iidr.metadata.ExportMetadata.java
public ExportMetadata(String[] commandLineArguments) throws ConfigurationException, ExportMetadataParmsException, EmbeddedScriptException, ExportMetadataException, MalformedURLException { System.setProperty("log4j.configuration", new File(".", File.separatorChar + "conf" + File.separatorChar + "log4j.properties").toURI().toURL() .toString());/*from ww w.j a v a2 s.c o m*/ // logger = // Logger.getLogger("com.ibm.replication.iidr.metadata.ExportMetadata"); logger = Logger.getLogger(ExportMetadata.class.getName()); PropertiesConfiguration versionInfo = new PropertiesConfiguration( "conf" + File.separator + "version.properties"); logger.info(MessageFormat.format("Version: {0}.{1}.{2}, date: {3}", new Object[] { versionInfo.getString("buildVersion"), versionInfo.getString("buildRelease"), versionInfo.getString("buildMod"), versionInfo.getString("buildDate") })); settings = new Settings("conf" + File.separator + this.getClass().getSimpleName() + ".properties"); parms = new ExportMetadataParms(commandLineArguments); assets = new Assets(); // If the debug option was set, make sure that all debug messages are // logged if (parms.debug) { Logger.getRootLogger().setLevel(Level.DEBUG); } // Collect the metadata collectMetadata(); Utils.writeContentToFile(settings.defaultDataPath + File.separator + parms.datastore + "_assets.xml", assets.toXML()); flows = new Flows(assets); Utils.writeContentToFile(settings.defaultDataPath + File.separator + parms.datastore + "_flow.xml", flows.toXML()); if (!parms.previewOnly) { try { IGCRest igcRest = new IGCRest(settings.isHostName, settings.isPort, settings.isUserName, settings.isPassword, settings.trustSelfSignedCertificates); igcRest.uploadBundleIfMissing(settings.bundleFilePath, parms.updateBundle); igcRest.postAssets(assets.toXML()); igcRest.postFlows(flows.toXML()); } catch (IGCRestException e) { logger.error(MessageFormat.format("REST API call for failed with code {0} and message: {1}", new Object[] { e.httpCode, e.message })); throw new ExportMetadataException(e); } catch (Exception e) { throw new ExportMetadataException(e); } } else { String previewFileName = settings.defaultDataPath + File.separator + parms.datastore + "_ExportMetadata_Preview.txt"; logger.debug(MessageFormat.format("Writing output to {0}", new Object[] { previewFileName })); Utils.writeContentToFile(previewFileName, flows.preview()); } logger.info("Finished exporting the CDC metadata"); }
From source file:com.xlson.standalonewar.Starter.java
private static PropertiesConfiguration loadConfig() { final String PROP_NAME_WEBSERVER_CONFIG_FILE = defaultProperties .getString("PROP_NAME_WEBSERVER_CONFIG_FILE", "webserver.configFilename"); String configFilename = System.getProperty(PROP_NAME_WEBSERVER_CONFIG_FILE, defaultProperties.getString("webserver.configFilename", "webserver.conf")); try {/* w ww. j av a 2s . c o m*/ return new PropertiesConfiguration(configFilename); } catch (ConfigurationException e) { logger.warn("Could not load config file: {}", configFilename); return new PropertiesConfiguration(); } }
From source file:net.sf.mpaxs.spi.server.MpaxsImpl.java
@Override public void startMasterServer(Configuration config, Container c) { if (master != null) { throw new IllegalStateException("Master server was already started!"); }/* w ww . j a v a 2 s .c o m*/ if (config == null) { System.out.println("Configuration is null, starting master with default parameters!"); startMasterServer(); return; } try { File f = File.createTempFile(UUID.randomUUID().toString(), ".properties"); PropertiesConfiguration pc; try { pc = new PropertiesConfiguration(f); ConfigurationUtils.copy(config, pc); pc.save(f); System.out.println(ConfigurationUtils.toString(pc)); master = StartUp.start(f.getAbsolutePath(), c); } catch (ConfigurationException ex) { Logger.getLogger(MpaxsImpl.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(MpaxsImpl.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.vvote.verifier.component.votePacking.VotePackingConfig.java
/** * Constructor for a VotePackingConfig object from a String * /*from ww w . j a va2s.c om*/ * @param configLocation * The filename or filepath of the config in string format * @throws ConfigException */ public VotePackingConfig(String configLocation) throws ConfigException { logger.debug("Reading in Vote Packing specific configuration data"); if (configLocation == null) { logger.error("Cannot successfully create a VotePackingConfig"); throw new ConfigException("Cannot successfully create a VotePackingConfig"); } if (configLocation.length() == 0) { logger.error("Cannot successfully create a VotePackingConfig"); throw new ConfigException("Cannot successfully create a VotePackingConfig"); } try { Configuration config = new PropertiesConfiguration(configLocation); if (config.containsKey(ConfigFileConstants.VotePackingConfig.CURVE)) { this.curve = config.getString(ConfigFileConstants.VotePackingConfig.CURVE); } else { logger.error( "Cannot successfully create a VotePackingConfig - must contain the name of the curve used"); throw new ConfigException( "Cannot successfully create a VotePackingConfig - must contain the name of the curve used"); } if (config.containsKey(ConfigFileConstants.VotePackingConfig.PADDING_FILE)) { this.paddingFile = config.getString(ConfigFileConstants.VotePackingConfig.PADDING_FILE); } else { logger.error( "Cannot successfully create a VotePackingConfig - must contain the name of the padding file"); throw new ConfigException( "Cannot successfully create a VotePackingConfig - must contain the name of the padding file"); } if (config.containsKey(ConfigFileConstants.VotePackingConfig.TABLE_LA_LINE_LENGTH)) { this.laLineLength = config.getInt(ConfigFileConstants.VotePackingConfig.TABLE_LA_LINE_LENGTH); } else { this.laLineLength = -1; } if (config.containsKey(ConfigFileConstants.VotePackingConfig.TABLE_LA_PACKING)) { this.laPacking = config.getInt(ConfigFileConstants.VotePackingConfig.TABLE_LA_PACKING); } else { this.laPacking = -1; } if (config.containsKey(ConfigFileConstants.VotePackingConfig.TABLE_BTL_LINE_LENGTH)) { this.lcBTLLineLength = config.getInt(ConfigFileConstants.VotePackingConfig.TABLE_BTL_LINE_LENGTH); } else { this.lcBTLLineLength = -1; } if (config.containsKey(ConfigFileConstants.VotePackingConfig.TABLE_BTL_PACKING)) { this.lcBTLPacking = config.getInt(ConfigFileConstants.VotePackingConfig.TABLE_BTL_PACKING); } else { this.lcBTLPacking = -1; } if (config.containsKey(ConfigFileConstants.VotePackingConfig.CANDIDATE_TABLES)) { this.candidateTablesFolder = config .getString(ConfigFileConstants.VotePackingConfig.CANDIDATE_TABLES); } else { logger.error( "Cannot successfully create a VotePackingConfig - must contain the name of the candidates table"); throw new ConfigException( "Cannot successfully create a VotePackingConfig - must contain the candidates table"); } this.useDirect = new HashMap<RaceType, Boolean>(); this.useDirect.put(RaceType.LA, false); this.useDirect.put(RaceType.LC_ATL, false); this.useDirect.put(RaceType.LC_BTL, false); if (config.containsKey(ConfigFileConstants.VotePackingConfig.USE_DIRECT)) { String[] directlyUsed = config.getStringArray(ConfigFileConstants.VotePackingConfig.USE_DIRECT); for (String race : directlyUsed) { RaceType raceType = RaceType.fromString(race); if (raceType != null) { this.useDirect.remove(raceType); this.useDirect.put(raceType, true); } else { logger.error( "Cannot successfully create a VotePackingConfig - misformed use direct race type"); throw new ConfigException( "Cannot successfully create a VotePackingConfig - misformed use direct race type"); } } } } catch (ConfigurationException e) { logger.error("Cannot successfully create a VotePackingConfig", e); throw new ConfigException("Cannot successfully create a VotePackingConfig", e); } }
From source file:com.impetus.kundera.ycsb.YCSBBaseTest.java
/** * @throws ConfigurationException//w w w . ja v a2s . c o m * @throws IOException * @throws NumberFormatException */ protected void onUpdate() throws ConfigurationException, NumberFormatException, IOException { String[] workLoadList = config.getStringArray("workload.file"); for (String workLoad : workLoadList) { PropertiesConfiguration workLoadConfig = new PropertiesConfiguration(workLoadPackage + "/" + workLoad); workLoadConfig.setProperty("readproportion", "0"); workLoadConfig.setProperty("updateproportion", "1"); workLoadConfig.setProperty("scanproportion", "0"); workLoadConfig.setProperty("insertproportion", "0"); workLoadConfig.save(); process(); } }
From source file:com.appeligo.config.ConfigurationService.java
private static AbstractConfiguration createConfig(File envFile, File baseFile) { if (log.isInfoEnabled()) { log.info("Initiating configuration " + baseFile + " : " + envFile); }//from w w w .j ava2 s . c o m AbstractConfiguration envConfig = null; AbstractConfiguration baseConfig = null; if (envFile.isFile()) { try { if (envFile.getName().endsWith(".xml")) { if (log.isDebugEnabled()) { log.debug("Creating xml config: " + envFile); } envConfig = new XMLConfiguration(); ((XMLConfiguration) envConfig).setValidating(false); ((XMLConfiguration) envConfig).load(envFile); } else if (envFile.getName().endsWith(".properties")) { if (log.isDebugEnabled()) { log.debug("Creating properties config: " + envFile); } envConfig = new PropertiesConfiguration(envFile); } } catch (ConfigurationException e) { if (log.isErrorEnabled()) { log.error("Cannot create AbstractConfiguration for: " + envFile, e); } } } if (baseFile.isFile()) { try { if (baseFile.getName().endsWith(".xml")) { if (log.isDebugEnabled()) { log.debug("Creating xml config: " + baseFile); } baseConfig = new XMLConfiguration(); ((XMLConfiguration) baseConfig).setValidating(false); ((XMLConfiguration) baseConfig).load(baseFile); } else if (baseFile.getName().endsWith(".properties")) { if (log.isDebugEnabled()) { log.debug("Creating properties config: " + baseFile); } baseConfig = new PropertiesConfiguration(baseFile); } } catch (ConfigurationException e) { if (log.isErrorEnabled()) { log.error("Cannot create AbstractConfiguration for: " + baseFile, e); } } } if (envConfig != null && baseConfig != null) { //create a combined AbstractConfiguration if (log.isDebugEnabled()) { log.debug("Creating combined config: " + envFile + " -> " + baseFile); } CombinedConfiguration combined = new CombinedConfiguration(); combined.addConfiguration(envConfig); combined.addConfiguration(baseConfig); return combined; } else if (envConfig != null) { return envConfig; } else { return baseConfig; } }