List of usage examples for org.apache.commons.configuration ConfigurationException ConfigurationException
public ConfigurationException(Throwable cause)
ConfigurationException
with specified nested Throwable
. From source file:org.jpac.configuration.Configuration.java
public static Configuration getInstance() throws ConfigurationException { if (instance == null) { try {//from w w w.j av a2 s. com instance = new Configuration(); } catch (Exception exc) { throw new ConfigurationException(exc); } } return instance; }
From source file:org.jpac.configuration.Property.java
public Property(String key) throws ConfigurationException { Configuration configuration = Configuration.getInstance(); this.key = key; // check if the property exists inside configuration if (!configuration.containsKey(this.key)) { //if not found, check if is a class property int lastPunktIndex = this.key.lastIndexOf("."); this.key = this.key.substring(0, lastPunktIndex).replace(".", "..") + this.key.substring(lastPunktIndex); if (!configuration.containsKey(this.key)) { throw new ConfigurationException("property " + key + " does not exist!"); } else {/* w w w. j ava 2 s . c om*/ this.classProperty = true; } } }
From source file:org.jpac.configuration.Property.java
private void assertKey(String key) throws ConfigurationException { if (key.contains(".")) { throw new ConfigurationException("a period ('.') is not allowed as part of the key"); }//www . j a v a 2 s .co m }
From source file:org.kitodo.config.enums.KitodoConfigFile.java
/** * Get by configuration file name.//from w w w.ja v a 2 s. c o m * * @param name * of configuration file * @return File */ public static KitodoConfigFile getByName(String name) throws ConfigurationException { for (KitodoConfigFile file : KitodoConfigFile.values()) { if (file.getName().equals(name)) { return file; } } throw new ConfigurationException("Configuration file '" + name + "' doesn't exists!"); }
From source file:org.kitodo.production.metadata.copier.DataCopyrule.java
/** * Factory method to create a class implementing the metadata copy rule * referenced by a given command string. * * @param command/*from www .j a va2 s .c om*/ * A space-separated string consisting of subject (aka. patiens), * operator (aka. agens) and (optional) objects (depending on * what objects the operator requires). * @return a class implementing the metadata copy rule referenced * @throws ConfigurationException * if the operator cannot be resolved or the number of arguments * doesnt match */ public static DataCopyrule createFor(String command) throws ConfigurationException { List<String> arguments = Arrays.asList(command.split("\\s+")); String operator; try { operator = arguments.get(1); } catch (IndexOutOfBoundsException e) { throw new ConfigurationException("Missing operator (second argument) in line: " + command); } Class<? extends DataCopyrule> ruleClass = AVAILABLE_RULES.get(operator); if (ruleClass == null) { throw new ConfigurationException("Unknown operator: " + operator); } DataCopyrule ruleImplementation; try { ruleImplementation = ruleClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new MetadataException(e.getMessage(), e); } ruleImplementation.setSubject(arguments.get(0)); if (ruleImplementation.getMaxObjects() > 0) { List<String> objects = arguments.subList(2, arguments.size()); if (objects.size() < ruleImplementation.getMinObjects()) { throw new ConfigurationException("Too few arguments in line: " + command); } if (objects.size() > ruleImplementation.getMaxObjects()) { throw new ConfigurationException("Too many arguments in line: " + command); } ruleImplementation.setObjects(objects); } return ruleImplementation; }
From source file:org.kitodo.production.metadata.copier.MetadataPathSelector.java
/** * Creates a new MetadataPathSelector./*from w ww . jav a2s .c o m*/ * * @param path * path to create sub-selector, passed to { * {@link #create(String)}. * @throws ConfigurationException * if the path is invalid */ public MetadataPathSelector(String path) throws ConfigurationException { String pathSegment = matchCurrentPathSegment(path); Matcher pathSelectorHasElementSelector = SEGMENT_WITH_ELEMENT_SELELCTOR_SCHEME.matcher(pathSegment); if (pathSelectorHasElementSelector.matches()) { docStructType = pathSelectorHasElementSelector.group(1); String indexSymbol = pathSelectorHasElementSelector.group(2); try { index = getIndexValue(indexSymbol); if (index instanceof Integer && (Integer) index < 0) { throw new ConfigurationException("Negative element count is not allowed, in path: " + path); } } catch (NumberFormatException e) { throw new ConfigurationException("Cannot create metadata path selector: " + e.getMessage(), e); } } else { docStructType = pathSegment; index = null; } selector = MetadataSelector.create(path.substring(pathSegment.length() + 1)); }
From source file:org.kitodo.production.metadata.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/*from ww w. ja va 2s .c o m*/ * path expression to parse * @return the path segment for this selector * @throws ConfigurationException * if the path cannot be parsed */ private 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:org.kitodo.production.metadata.copier.MetadataSelector.java
/** * Factory method to create a metadata selector. Depending on the path, the * required implementation will be constructed. * * @param path/*from ww w . jav a 2s .c o m*/ * path to create a metadata selector from. * @return a metadata selector instance representing the given paht * @throws ConfigurationException * if the path cannot be evaluated */ public static MetadataSelector create(String path) throws ConfigurationException { if (path.startsWith(METADATA_SEPARATOR)) { throw new UnsupportedOperationException("Dead code pending removal"); } if (path.startsWith(METADATA_PATH_SEPARATOR)) { if (path.indexOf(METADATA_SEPARATOR, 1) > -1) { throw new UnsupportedOperationException("Dead code pending removal"); } else { return new MetadataPathSelector(path); } } throw new ConfigurationException( "Cannot create metadata selector: Path must start with \"@\" or \"/\", but is: " + path); }
From source file:org.mifos.dmt.configuration.DMTPropertiesLoader.java
private DMTPropertiesLoader() throws ConfigurationException { config = new CompositeConfiguration(); config.addConfiguration(new SystemConfiguration()); config.addConfiguration(new EnvironmentConfiguration()); String confPath = config.getString("DMT_CONF"); if (confPath == null || confPath == "" || confPath.equalsIgnoreCase("")) { throw new ConfigurationException("DMT_CONF not defined"); }/*from w ww . ja v a2 s . co m*/ config.addConfiguration(new PropertiesConfiguration(confPath + "\\dmt.custom.properties")); config.addConfiguration(new PropertiesConfiguration("dmt.properties")); config.setThrowExceptionOnMissing(true); }
From source file:org.opennaas.extensions.ofertie.ncl.provisioner.components.mockup.NetworkSelectorMockup.java
public void init() throws IOException, ConfigurationException { log.debug("Reading configuration file " + RESOURCE_ID_FILE); ConfigurationAdminUtil configurationAdmin = new ConfigurationAdminUtil(Activator.getBundleContext()); resourceName = configurationAdmin.getProperty(RESOURCE_ID_FILE, RESOURCE_NAME_KEY); resourceType = configurationAdmin.getProperty(RESOURCE_ID_FILE, RESOURCE_TYPE_KEY); if (StringUtils.isEmpty(resourceName) || StringUtils.isEmpty(resourceType)) throw new ConfigurationException(RESOURCE_ID_FILE + " file should contain attributes " + RESOURCE_NAME_KEY + " and " + RESOURCE_TYPE_KEY); log.info("NetworkSelector initalized with configured resource " + resourceType + ":" + resourceName); }