List of usage examples for org.apache.commons.configuration ConfigurationException ConfigurationException
public ConfigurationException(Throwable cause)
ConfigurationException
with specified nested Throwable
. From source file:jdbc.pool.CPropertyManager.java
public CPoolAttribute getPoolAttribute(String strPoolName) throws ConfigurationException { CPoolAttribute attribute = new CPoolAttribute(); if (logger_.isDebugEnabled()) { logger_.debug("Loading properties for pool name #" + strPoolName); }// w w w . j a v a 2 s. co m attribute.setPoolName(strPoolName); attribute.setDriver(properties_.getProperty(strPoolName + ".driver")); attribute.setVendor(properties_.getProperty(strPoolName + ".vendor")); attribute.setURL(properties_.getProperty(strPoolName + ".url")); attribute.setUser(properties_.getProperty(strPoolName + ".user")); attribute.setPassword(properties_.getProperty(strPoolName + ".password")); attribute.setInitialPoolSize( Integer.parseInt(properties_.getProperty(strPoolName + ".initial-connections"))); attribute.setCapacityIncreament( Integer.parseInt(properties_.getProperty(strPoolName + ".capacity-increament"))); attribute.setMaximumCapacity(Integer.parseInt(properties_.getProperty(strPoolName + ".maximum-capacity"))); attribute.setConnectionIdleTimeout( Integer.parseInt(properties_.getProperty(strPoolName + ".inactive-time-out"))); attribute.setShrinkPoolInterval( Integer.parseInt(properties_.getProperty(strPoolName + ".shrink-pool-interval"))); attribute.setCriticalOperationTimeLimit( Integer.parseInt(properties_.getProperty(strPoolName + ".critical-operation-time-limit"))); int iMaxUsage = Integer .parseInt(properties_.getProperty(strPoolName + ".max-usage-per-jdbc-connection", "-1")); if (iMaxUsage < 2) { iMaxUsage = -1; } attribute.setMaxUsagePerJDBCConnection(iMaxUsage); try { attribute .setInUseWaitTime(Integer.parseInt(properties_.getProperty(strPoolName + ".in-use-wait-time"))); } catch (NoSuchElementException e) { attribute.setInUseWaitTime(-1); } try { if (properties_.getProperty(strPoolName + ".load-on-startup", "false").equals("true")) { attribute.setLoadOnStartup(true); } else { attribute.setLoadOnStartup(false); } } catch (NoSuchElementException nsee) { } try { attribute.setPoolAlgorithm(properties_.getProperty(strPoolName + ".pool-algorithm")); } catch (NoSuchElementException e) { attribute.setPoolAlgorithm(IPool.FIFO_ALGORITHM); attribute.setToBeSaved(true); } try { int i = Integer .parseInt(properties_.getProperty(strPoolName + ".inmemory-statistics-history-size", "-1")); if (i == -1) { attribute.setToBeSaved(true); } attribute.setStatisticalHistoryRecordCount(i); } catch (NoSuchElementException e) { attribute.setStatisticalHistoryRecordCount(1); attribute.setToBeSaved(true); } String sqlQuery = properties_.getProperty(strPoolName + ".sql-query", null); if (sqlQuery == null) { throw new ConfigurationException("sql-query attribute must be defined."); } attribute.setSqlQuery(sqlQuery); if (logger_.isDebugEnabled()) { logger_.debug("Pool Attributes Read " + attribute); } return attribute; }
From source file:de.tudarmstadt.ukp.dariah.pipeline.RunPipeline.java
/** * Parses a parameter string that can be found in the .properties files. * The parameterString is of the format parameterName1,parameterType1,parameterValue2,parameterName2,parameterType2,parameterValue2 * @param config /*from ww w . j a va 2s .co m*/ * * @param parametersString * @return Mapped paramaterString to an Object[] array that can be inputted to UIMA components */ private static Object[] parseParameters(Configuration config, String parameterName) throws ConfigurationException { LinkedList<Object> parameters = new LinkedList<>(); List<Object> parameterList = config.getList(parameterName); if (parameterList.size() % 3 != 0) { throw new ConfigurationException( "Parameter String must be a multiple of 3 in the format: name, type, value. " + parameterName); } for (int i = 0; i < parameterList.size(); i += 3) { String name = (String) parameterList.get(i + 0); String type = ((String) parameterList.get(i + 1)).toLowerCase(); String value = (String) parameterList.get(i + 2); Object obj; switch (type) { case "bool": case "boolean": obj = Boolean.valueOf(value); break; case "int": case "integer": obj = Integer.valueOf(value); break; default: obj = value; } parameters.add(name); parameters.add(obj); } return parameters.toArray(new Object[0]); }
From source file:de.sub.goobi.metadaten.copier.MetadataPathSelector.java
/** * The function matchCurrentPathSegment() returns the path segment this * metadata path selector is responsible to represent. Since the method is * called from the constructor it must not be overridden in subclasses. * * @param path/* w w w. ja v a2s . c om*/ * path expression to parse * @return the path segment for this selector * @throws ConfigurationException * if the path cannot be parsed */ private final String matchCurrentPathSegment(String path) throws ConfigurationException { Matcher metadataPathSplitter = METADATA_SPLIT_PATH_SCHEME.matcher(path); if (!metadataPathSplitter.find()) { throw new ConfigurationException( "Cannot create metadata path selector: Path must contain path segment, but is: " + path); } return metadataPathSplitter.group(1); }
From source file:jdbc.pool.CPropertyManager.java
public synchronized boolean create(CPoolAttribute attribute) throws ConfigurationException { StringTokenizer tokenizer = new StringTokenizer(properties_.getProperty("pools"), ";"); boolean bPoolConfigurationFound = false; while (tokenizer.hasMoreTokens()) { if (tokenizer.nextToken().equals(attribute.getPoolName())) { bPoolConfigurationFound = true; break; }//from ww w . j a v a2 s . com } if (bPoolConfigurationFound) { throw new ConfigurationException("Pool Configuration already exists. Could not create."); } String strPools = properties_.getProperty("pools"); if (!strPools.endsWith(";")) { strPools = strPools + ";" + attribute.getPoolName(); } else { strPools = strPools + attribute.getPoolName() + ";"; } String strPoolName = attribute.getPoolName(); properties_.setProperty("pools", strPools); properties_.setProperty(strPoolName + ".driver", attribute.getDriver()); properties_.setProperty(strPoolName + ".vendor", attribute.getVendor()); properties_.setProperty(strPoolName + ".url", attribute.getURL()); properties_.setProperty(strPoolName + ".user", attribute.getUser()); properties_.setProperty(strPoolName + ".password", attribute.getPassword()); properties_.setProperty(strPoolName + ".initial-connections", attribute.getInitialPoolSize() + ""); properties_.setProperty(strPoolName + ".capacity-increament", attribute.getCapacityIncreament() + ""); properties_.setProperty(strPoolName + ".maximum-capacity", attribute.getMaximumCapacity() + ""); properties_.setProperty(strPoolName + ".inactive-time-out", attribute.getConnectionIdleTimeout() + ""); properties_.setProperty(strPoolName + ".shrink-pool-interval", attribute.getShrinkPoolInterval() + ""); properties_.setProperty(strPoolName + ".critical-operation-time-limit", attribute.getCriticalOperationTimeLimit() + ""); properties_.setProperty(strPoolName + ".max-usage-per-jdbc-connection", attribute.getMaxUsagePerJDBCConnection() + ""); properties_.setProperty(strPoolName + ".in-use-wait-time", attribute.getInUseWaitTime() + ""); properties_.setProperty(strPoolName + ".load-on-startup", attribute.isLoadOnStartup() + ""); properties_.setProperty(strPoolName + ".pool-algorithm", attribute.getPoolAlgorithm()); properties_.setProperty(strPoolName + ".inmemory-statistics-history-size", attribute.getStatisticalHistoryRecordCount() + ""); properties_.setProperty(strPoolName + ".sql-query", attribute.getSqlQuery()); return true; }
From source file:it.unimi.di.big.mg4j.document.DispatchingDocumentFactory.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override// www . j av a2s . c o m protected boolean parseProperty(final String key, final String[] values, final Reference2ObjectMap<Enum<?>, Object> metadata) throws ConfigurationException { if (sameKey(MetadataKeys.FIELDNAME, key)) { fieldName = values; numberOfFields = fieldName.length; return true; } else if (sameKey(MetadataKeys.KEY, key)) { final String dispatchingKeyName = ensureJustOne(key, values); final int lastDot = dispatchingKeyName.lastIndexOf('.'); try { dispatchingKey = Enum.valueOf((Class<Enum>) Class.forName(dispatchingKeyName.substring(0, lastDot)), dispatchingKeyName.substring(lastDot + 1)); } catch (ClassNotFoundException e) { throw new IllegalArgumentException( "The class specified in the key " + dispatchingKeyName + " cannot be found"); } return true; } else if (sameKey(MetadataKeys.RULE, key)) { String[] rules = values; value2factoryClass = new Object2ObjectLinkedOpenHashMap<String, Class<? extends DocumentFactory>>(); int i, m = rules.length; for (i = 0; i < m; i++) { int pos = rules[i].indexOf(':'); if (pos <= 0 || pos == rules[i].length() - 1) throw new ConfigurationException( "Rule " + rules[i] + " does not contain a colon or it is malformed"); if (rules[i].indexOf(':', pos + 1) >= 0) throw new ConfigurationException("Rule " + rules[i] + " contains too many colons"); String factoryName = rules[i].substring(pos + 1); Class<? extends DocumentFactory> factoryClass = null; try { factoryClass = (Class<? extends DocumentFactory>) Class.forName(factoryName); if (!(DocumentFactory.class.isAssignableFrom(factoryClass))) throw new ClassNotFoundException(); } catch (ClassNotFoundException e) { throw new ConfigurationException( "ParsingFactory " + factoryName + " is invalid; maybe the package name is missing"); } value2factoryClass.put(rules[i].substring(0, pos), factoryClass); } m = value2factoryClass.values().size(); return true; } else if (sameKey(MetadataKeys.MAP, key)) { String[] pieces = values; int i, m = pieces.length; rename = new int[m][]; for (i = 0; i < m; i++) { String[] subpieces = pieces[i].split(":"); if (i > 0 && subpieces.length != rename[0].length) throw new ConfigurationException("Length mismatch in the map " + values); rename[i] = new int[subpieces.length]; for (int k = 0; k < subpieces.length; k++) { try { rename[i][k] = Integer.parseInt(subpieces[k]); } catch (NumberFormatException e) { throw new ConfigurationException("Number format exception in the map " + values); } } } } return super.parseProperty(key, values, metadata); }
From source file:jdbc.pool.CXMLManager.java
public synchronized boolean delete(String strPoolName) throws ConfigurationException { if (strPoolName == null) { throw new NullPointerException("Pool Name not supplied."); }/*ww w . j av a2s . com*/ boolean bThrowException = true; int iSize = xmlPoolConfig.getMaxIndex("pool[@name]"); for (int i = 0; i <= iSize; i++) { if (xmlPoolConfig.getString("pool(" + i + ")[@name]").equals(strPoolName)) { xmlPoolConfig.clearProperty("pool(" + i + ")[@name]"); xmlPoolConfig.clearProperty("pool(" + i + ")[@driver]"); xmlPoolConfig.clearProperty("pool(" + i + ")[@vendor]"); xmlPoolConfig.clearProperty("pool(" + i + ")[@url]"); xmlPoolConfig.clearProperty("pool(" + i + ")[@user]"); xmlPoolConfig.clearProperty("pool(" + i + ")[@password]"); xmlPoolConfig.clearProperty("pool(" + i + ")[@initial-connections]"); xmlPoolConfig.clearProperty("pool(" + i + ")[@capacity-increament]"); xmlPoolConfig.clearProperty("pool(" + i + ")[@maximum-capacity]"); xmlPoolConfig.clearProperty("pool(" + i + ")[@inactive-time-out]"); xmlPoolConfig.clearProperty("pool(" + i + ")[@shrink-pool-interval]"); xmlPoolConfig.clearProperty("pool(" + i + ")[@critical-operation-time-limit]"); xmlPoolConfig.clearProperty("pool(" + i + ").in-use-wait-time"); xmlPoolConfig.clearProperty("pool(" + i + ").load-on-startup"); xmlPoolConfig.clearProperty("pool(" + i + ").max-usage-per-jdbc-connection"); xmlPoolConfig.clearProperty("pool(" + i + ").pool-algorithm"); xmlPoolConfig.clearProperty("pool(" + i + ").inmemory-statistics-history-size"); xmlPoolConfig.clearProperty("pool(" + i + ").sql-query"); bThrowException = false; save(); return true; } } if (bThrowException) { throw new ConfigurationException("Unable to find such a configuration. Pool Name #" + strPoolName); } return false; }
From source file:com.shanke.common.conf.CustomConfigurationBuilder.java
/** * Creates a configuration object from the specified configuration * declaration.// w w w.j a v a 2 s . co m * * @param decl * the configuration declaration * @return the new configuration object * @throws ConfigurationException * if an error occurs */ private AbstractConfiguration createConfigurationAt(ConfigurationDeclaration decl) throws ConfigurationException { try { return (AbstractConfiguration) BeanHelper.createBean(decl); } catch (Exception ex) { // redirect to configuration exceptions throw new ConfigurationException(ex); } }
From source file:jdbc.pool.CPropertyManager.java
public void save() throws ConfigurationException { if (logger_.isDebugEnabled()) { logger_.debug("Saving the configuration to disk.."); }/*from w ww .j av a 2 s.c o m*/ try { PrintWriter pwOut = new PrintWriter(new FileWriter(getConfigurationFile()), true); writeTemplate(pwOut, getConfigurationFile().getName()); StringTokenizer tokenizer = new StringTokenizer(properties_.getProperty("pools"), ";"); pwOut.println(""); pwOut.println("pools=" + properties_.getProperty("pools")); pwOut.println(""); while (tokenizer.hasMoreTokens()) { String strPoolName = tokenizer.nextToken(); pwOut.println(strPoolName + ".driver=" + properties_.getProperty(strPoolName + ".driver")); pwOut.println(strPoolName + ".vendor=" + properties_.getProperty(strPoolName + ".vendor")); pwOut.println(strPoolName + ".url=" + properties_.getProperty(strPoolName + ".url")); pwOut.println(strPoolName + ".user=" + properties_.getProperty(strPoolName + ".user")); pwOut.println(strPoolName + ".password=" + properties_.getProperty(strPoolName + ".password")); pwOut.println(strPoolName + ".initial-connections=" + properties_.getProperty(strPoolName + ".initial-connections")); pwOut.println(strPoolName + ".capacity-increament=" + properties_.getProperty(strPoolName + ".capacity-increament")); pwOut.println(strPoolName + ".maximum-capacity=" + properties_.getProperty(strPoolName + ".maximum-capacity")); pwOut.println(strPoolName + ".inactive-time-out=" + properties_.getProperty(strPoolName + ".inactive-time-out")); pwOut.println(strPoolName + ".shrink-pool-interval=" + properties_.getProperty(strPoolName + ".shrink-pool-interval")); pwOut.println(strPoolName + ".critical-operation-time-limit=" + properties_.getProperty(strPoolName + ".critical-operation-time-limit")); pwOut.println(strPoolName + ".max-usage-per-jdbc-connection=" + properties_.getProperty(strPoolName + ".max-usage-per-jdbc-connection")); pwOut.println(strPoolName + ".in-use-wait-time=" + properties_.getProperty(strPoolName + ".in-use-wait-time")); pwOut.println(strPoolName + ".load-on-startup=" + properties_.getProperty(strPoolName + ".load-on-startup")); pwOut.println(strPoolName + ".pool-algorithm=" + properties_.getProperty(strPoolName + ".pool-algorithm")); pwOut.println(strPoolName + ".inmemory-statistics-history-size=" + properties_.getProperty(strPoolName + ".inmemory-statistics-history-size")); pwOut.println(strPoolName + ".sql-query=" + properties_.getProperty(strPoolName + ".sql-query")); pwOut.println(""); } } catch (IOException e) { logger_.error("IOException ", e); throw new ConfigurationException("Unable to save the file. IOException"); } if (logger_.isDebugEnabled()) { logger_.debug("Configuration saved to disk.."); } }
From source file:jdbc.pool.CPropertyManager.java
public synchronized boolean delete(String strPoolName) throws ConfigurationException { StringTokenizer tokenizer = new StringTokenizer(properties_.getProperty("pools"), ";"); boolean bPoolConfigurationFound = false; while (tokenizer.hasMoreTokens()) { if (tokenizer.nextToken().equals(strPoolName)) { bPoolConfigurationFound = true; break; }/*from ww w. j a va 2 s .c o m*/ } if (!bPoolConfigurationFound) { throw new ConfigurationException("Pool Configuration not found."); } String strPools_ = properties_.getProperty("pools").replaceAll(strPoolName + ";", ""); properties_.setProperty("pools", strPools_); properties_.remove(strPoolName + ".driver"); properties_.remove(strPoolName + ".vendor"); properties_.remove(strPoolName + ".url"); properties_.remove(strPoolName + ".user"); properties_.remove(strPoolName + ".password"); properties_.remove(strPoolName + ".initial-connections"); properties_.remove(strPoolName + ".capacity-increament"); properties_.remove(strPoolName + ".maximum-capacity"); properties_.remove(strPoolName + ".inactive-time-out"); properties_.remove(strPoolName + ".shrink-pool-interval"); properties_.remove(strPoolName + ".critical-operation-time-limit"); properties_.remove(strPoolName + ".max-usage-per-jdbc-connection"); properties_.remove(strPoolName + ".in-use-wait-time"); properties_.remove(strPoolName + ".load-on-startup"); properties_.remove(strPoolName + ".pool-algorithm"); properties_.remove(strPoolName + ".inmemory-statistics-history-size"); properties_.remove(strPoolName + ".sql-query"); save(); return true; }
From source file:ch.admin.suis.msghandler.config.ClientConfigurationFactory.java
/** * This method validates the config.xml. A physical signing outbox (and corresponding processed) directory is only * allowed be referenced once.//from w w w . j a va 2 s. c o m * * @param signatureOutboxDir A File * @param processedDir the processed dir * @throws ConfigurationException Config problems */ private void checkSignatureOutbox(File signatureOutboxDir, File processedDir) throws ConfigurationException { if (checkSigningOutboxDirSet.contains(signatureOutboxDir)) { throw new ConfigurationException( "XML doublication error: <signingOutbox ... name=\"" + signatureOutboxDir.getAbsolutePath() + " ... \"> already defined. This value has to be unique."); } checkSigningOutboxDirSet.add(signatureOutboxDir); if (processedDir != null) { if (checkSigningProcessedDirSet.contains(processedDir)) { throw new ConfigurationException("XML doublication error: <signingOutbox ... processedDir=\"" + processedDir.getAbsolutePath() + " ... \"> already defined. This value has to be unique."); } checkSigningProcessedDirSet.add(processedDir); } }