List of usage examples for org.apache.commons.configuration2.ex ConfigurationException ConfigurationException
public ConfigurationException(final Throwable cause)
From source file:eu.mangos.configuration.dao.impl.AuthConfigurationDAOImpl.java
@Override public AuthConfiguration readConfiguration() throws ConfigurationException { AuthConfiguration authConfig = new AuthConfiguration(); Parameters params = new Parameters(); this.builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class) .configure(params.properties().setFile(new File(this.configuration.getSourcePath()))); Configuration config = this.builder.getConfiguration(); authConfig.setVersion(config.getString("ConfVersion")); if (authConfig.getVersion() == null) { logger.error("The selected file does not contain any ConfVersion property."); throw new ConfigurationException("The selected file does not contain any ConfVersion property."); }// ww w . ja v a 2 s. c om if (Long.parseLong(authConfig.getVersion()) != AuthConfiguration.CONF_VERSION) { logger.error("The selected file has a version number not compatible with this manager."); throw new ConfigurationException("The selected file is not compatible with this manager."); } String[] loginDBInfo = (config.getString("LoginDatabaseInfo", "").replace("\"", "")).split(";"); if (loginDBInfo.length != 5) { logger.warn("The selected file has a LoginDatabaseInfo property with not enough parameters."); } authConfig.setIp(loginDBInfo.length >= 1 ? loginDBInfo[0] : ""); authConfig.setPort(loginDBInfo.length >= 2 ? Integer.parseInt(loginDBInfo[1]) : 0); authConfig.setUser(loginDBInfo.length >= 3 ? loginDBInfo[2] : ""); authConfig.setPassword(loginDBInfo.length >= 4 ? loginDBInfo[3] : ""); authConfig.setSchema(loginDBInfo.length >= 5 ? loginDBInfo[4] : ""); authConfig.setLogsDirectory(config.getString("LogsDir", "").replace("\"", "")); authConfig.setPidFile(config.getString("PidFile", "").replace("\"", "")); authConfig.setMaxPing(config.getInt("MaxPingTime", 30)); authConfig.setRealmServerPort(config.getInt("RealmServerPort", 3724)); authConfig.setBindIP(config.getString("BindIP", "0.0.0.0").replace("\"", "")); authConfig.setLogConsoleLevel(LogLevel.convert(config.getInt("LogLevel"))); authConfig.setIncludeLogTime((config.getInt("LogTime", 0) != 0)); authConfig.setLogFile(config.getString("LogFile", "realm-list.log").replace("\"", "")); authConfig.setIncludeTimestamp((config.getInt("LogTimestamp", 0) != 0)); authConfig.setLogFileLevel(LogLevel.convert(config.getInt("LogFileLevel"))); String[] logColors = (config.getString("LogColors", "")).replace("\"", "").split(" "); if (logColors.length != 4) { logger.warn("The selected file has a LogColors property with not enough parameters."); } authConfig.setLogNormalColor( logColors.length >= 1 ? LogColor.convert(Integer.parseInt(logColors[0])) : LogColor.NONE); authConfig.setLogDetailsColor( logColors.length >= 2 ? LogColor.convert(Integer.parseInt(logColors[1])) : LogColor.NONE); authConfig.setLogDebugColor( logColors.length >= 3 ? LogColor.convert(Integer.parseInt(logColors[2])) : LogColor.NONE); authConfig.setLogErrorColor( logColors.length >= 4 ? LogColor.convert(Integer.parseInt(logColors[3])) : LogColor.NONE); authConfig.setUseProcessors(config.getInt("UseProcessors", 0)); authConfig.setProcessPriority(ProcessPriority.convert(config.getInt("ProcessPriority", 1))); authConfig.setWaitAtStartupError(config.getInt("WaitAtStartupError", 0) != 0); authConfig.setRealmStateUpdateDelay(config.getInt("RealmsStateUpdateDelay", 20)); authConfig.setNbWrongPass(config.getInt("WrongPass.MaxCount", 3)); authConfig.setBanTime(config.getInt("WrongPass.BanTime", 300)); authConfig.setBanType(BanType.convert(config.getInt("WrongPass.BanType", 0))); logger.info("Configuration file " + this.configuration.getName() + " has been loaded succesfully !"); return authConfig; }
From source file:nl.minvenj.pef.stream.LiveCapture.java
private static void testPseudonymizationSettings(final XMLConfiguration config) throws ConfigurationException, IllegalArgumentException, ClassNotFoundException { List<HierarchicalConfiguration<ImmutableNode>> fields = config.configurationsAt("fields.field"); for (HierarchicalConfiguration field : fields) { // Test the name of the field. final String constraint = field.getString("constraint"); final String fieldName = field.getString("name"); final String algorithmName = field.getString("algorithm.name"); if ((fieldName == null) || (constraint == null) || (algorithmName == null)) throw new NoSuchElementException( "Name of the field, constraint and algoritm needs to be set for each field."); // Test the constraint. if (!Constraints.CONSTRAINT_MAP.containsKey(field.getString("constraint"))) { throw new ConfigurationException( field.getString("constraint") + "should be defined in constraints list (Constraints.java)"); }//from w w w.j a v a2s.co m // TODO PEF-78: Test if the fieldName matches with the context. // TODO PEF-79: No expression support. // Test if the algorithm is part of the configured algorithms. List<HierarchicalConfiguration> parameters = field.childConfigurationsAt("algorithm.params"); List<AlgorithmParameter> parameterList = new ArrayList<>(); //TODO PEF-81: Create here a specific parameter type. for (HierarchicalConfiguration parameter : parameters) { parameterList.add(new AlgorithmParameter(parameter.getString("name"), parameter.getString("value"), Class.forName(parameter.getString("type")))); } final StringBuilder buffer = new StringBuilder(); if (!testParseValueTransformerConfiguration(TransformerId.valueOf(algorithmName), parameterList, buffer)) { throw new ConfigurationException( "Error in configuration for algorithm " + algorithmName + " " + buffer.toString()); } } }