epugh 2004/01/23 03:52:36
Modified: configuration/xdocs changes.xml
configuration/src/test/org/apache/commons/configuration
TestConfigurationFactory.java
configuration/src/java/org/apache/commons/configuration
ConfigurationFactory.java
Added: configuration/src/java/org/apache/commons/configuration/exception
ConfigurationLoadException.java
configuration/conf testDigesterBadXML.xml
Log:
Add ConfigurationLoadException plus test case
Revision Changes Path
1.5 +3 -0 jakarta-commons/configuration/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/xdocs/changes.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- changes.xml 18 Jan 2004 16:15:46 -0000 1.4
+++ changes.xml 23 Jan 2004 11:52:36 -0000 1.5
@@ -7,6 +7,9 @@
<body>
<release version="1.0-dev-4" date="">
+ <action dev="epugh" type="add">
+ ConfigurationFactory now throws ConfigurationLoadException.
+ </action>
<action dev="ebourg" type="add">
New DatabaseConfiguration that uses a database to store the
properties. It supports 2 table structures :
<ul>
1.4 +18 -1
jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationFactory.java
Index: TestConfigurationFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationFactory.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestConfigurationFactory.java 16 Jan 2004 17:31:39 -0000 1.3
+++ TestConfigurationFactory.java 23 Jan 2004 11:52:36 -0000 1.4
@@ -56,8 +56,12 @@
import java.io.File;
import java.util.Collection;
+
import junit.framework.TestCase;
+import org.apache.commons.configuration.exception.ConfigurationLoadException;
+import org.xml.sax.SAXParseException;
+
/**
* Test the ConfigurationFactory.
*
@@ -73,6 +77,7 @@
private File testDigesterFileNamespaceAware = new
File("conf/testDigesterConfigurationNamespaceAware.xml");
private File testDigesterFileBasePath = new
File("conf/testDigesterConfigurationBasePath.xml");
private File testDigesterFileEnhanced = new
File("conf/testDigesterConfiguration2.xml");
+ private File testDigesterBadXML = new File("conf/testDigesterBadXML.xml");
private String testBasePath = new File("conf").getAbsolutePath();
@@ -173,6 +178,18 @@
{
configurationFactory.setConfigurationURL(testDigesterFileEnhanced.toURL());
checkUnionConfig();
+ }
+
+ public void testThrowingConfigurationInitializationException() throws Exception
+ {
+ configurationFactory.setConfigurationFileName(testDigesterBadXML.toString());
+ try {
+ Configuration c = configurationFactory.getConfiguration();
+ fail("Should have throw an Exception");
+ }
+ catch (ConfigurationLoadException cle){
+ assertTrue(cle.getCause() instanceof SAXParseException);
+ }
}
private void checkUnionConfig() throws Exception
1.1
jakarta-commons/configuration/src/java/org/apache/commons/configuration/exception/ConfigurationLoadException.java
Index: ConfigurationLoadException.java
===================================================================
package org.apache.commons.configuration.exception;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgement may appear in the software itself,
* if and wherever such third-party acknowledgements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import org.apache.commons.lang.exception.NestableException;;
/**
* Any exception that occurs while initializing a Configuration
* object.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Eric Pugh</a>
*
* @version $Id: ConfigurationLoadException.java,v 1.1 2004/01/23 11:52:36 epugh Exp
$
*/
public class ConfigurationLoadException extends NestableException {
public ConfigurationLoadException(Throwable root) {
super(root);
}
public ConfigurationLoadException(String string, Throwable root) {
super(string, root);
}
public ConfigurationLoadException(String s) {
super(s);
}
}
1.1 jakarta-commons/configuration/conf/testDigesterBadXML.xml
Index: testDigesterBadXML.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- Configuration test file that tests that bad
XML generates a SAXException that is properly
wrapped in a ConfigurationInitializationException -->
<configuration>
<additional>
<dom4j
className="org.apache.commons.configuration.HierarchicalDOM4JConfiguration"
fileName="testHierarchicalDOM4JConfiguration.xml"/>
</configuration>
1.5 +21 -6
jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationFactory.java
Index: ConfigurationFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationFactory.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ConfigurationFactory.java 23 Jan 2004 11:08:56 -0000 1.4
+++ ConfigurationFactory.java 23 Jan 2004 11:52:36 -0000 1.5
@@ -53,6 +53,7 @@
* <http://www.apache.org/>.
*/
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Collection;
@@ -60,6 +61,7 @@
import java.util.LinkedList;
import java.util.Stack;
+import org.apache.commons.configuration.exception.ConfigurationLoadException;
import org.apache.commons.digester.AbstractObjectCreationFactory;
import org.apache.commons.digester.Digester;
import org.apache.commons.digester.ObjectCreationFactory;
@@ -144,17 +146,25 @@
* @throws Exception A generic exception that we had trouble during the
* loading of the configuration data.
*/
- public Configuration getConfiguration() throws Exception
+ public Configuration getConfiguration() throws ConfigurationLoadException
{
Digester digester;
+ InputStream input = null;
ConfigurationBuilder builder = new ConfigurationBuilder();
URL url = getConfigurationURL();
+ try {
if(url == null)
{
url = ConfigurationUtils.getURL(impliciteBasePath,
getConfigurationFileName());
} /* if */
- InputStream input = url.openStream();
+ input = url.openStream();
+ }
+ catch (Exception e)
+ {
+ log.error("Exception caught opening stream to URL", e);
+ throw new ConfigurationLoadException("Exception caught opening stream
to URL",e);
+ }
if (getDigesterRules() == null)
{
@@ -177,11 +187,16 @@
digester.parse(input);
input.close();
}
- catch (SAXException e)
+ catch (SAXException saxe)
{
- log.error("SAX Exception caught", e);
- throw e;
+ log.error("SAX Exception caught", saxe);
+ throw new ConfigurationLoadException("SAX Exception caught",saxe);
}
+ catch (IOException ioe)
+ {
+ log.error("IO Exception caught", ioe);
+ throw new ConfigurationLoadException("IO Exception caught",ioe);
+ }
return builder.getConfiguration();
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]