commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r737777 - in /commons/proper/configuration/branches/configuration2_experimental/src: main/java/org/apache/commons/configuration2/XMLConfiguration.java test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
Date Mon, 26 Jan 2009 18:40:33 GMT
Author: rgoers
Date: Mon Jan 26 18:40:33 2009
New Revision: 737777

URL: http://svn.apache.org/viewvc?rev=737777&view=rev
Log:
Do not validate on save. Add validate method

Modified:
    commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
    commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java

Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java?rev=737777&r1=737776&r2=737777&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
Mon Jan 26 18:40:33 2009
@@ -890,46 +890,52 @@
         {
             Transformer transformer = createTransformer();
             Source source = new DOMSource(createDocument());
-            Result result;
-            StringWriter buffer = null;
-            if (isSchemaValidation())
-            {
-                buffer = new StringWriter();
-                result = new StreamResult(buffer);
-            }
-            else
-            {
-                result = new StreamResult(writer);
-            }
+            Result result = new StreamResult(writer);
             transformer.transform(source, result);
-            if (isSchemaValidation())
-            {
-                DocumentBuilder builder = createDocumentBuilder();
-                Reader reader = new StringReader(buffer.getBuffer().toString());
-                builder.parse(new InputSource(reader));
-                writer.write(buffer.getBuffer().toString());
-                writer.close();
-            }
         }
-        catch (SAXException e)
+        catch (TransformerException e)
+        {
+            throw new ConfigurationException(e.getMessage(), e);
+        }
+        catch (TransformerFactoryConfigurationError err)
+        {
+            throw new ConfigurationException(err.getMessage(), err);
+        }
+    }
+
+
+    /**
+     * Validate the document against the Schema.
+     * @throws ConfigurationException if the validation fails.
+     */
+    public void validate() throws ConfigurationException
+    {
+        try
         {
-            throw new ConfigurationException("Unable to save the configuration", e);
+            Transformer transformer = createTransformer();
+            Source source = new DOMSource(createDocument());
+            StringWriter writer = new StringWriter();
+            Result result = new StreamResult(writer);
+            transformer.transform(source, result);
+            Reader reader = new StringReader(writer.getBuffer().toString());
+            DocumentBuilder builder = createDocumentBuilder();
+            builder.parse(new InputSource(reader));
         }
-        catch (ParserConfigurationException e)
+        catch (SAXException e)
         {
-            throw new ConfigurationException("Unable to save the configuration", e);
+            throw new ConfigurationException("Validation failed", e);
         }
         catch (IOException e)
         {
-            throw new ConfigurationException("Unable to save the configuration", e);
+            throw new ConfigurationException("Validation failed", e);
         }
         catch (TransformerException e)
         {
-            throw new ConfigurationException(e.getMessage(), e);
+            throw new ConfigurationException("Validation failed", e);
         }
-        catch (TransformerFactoryConfigurationError err)
+        catch (ParserConfigurationException pce)
         {
-            throw new ConfigurationException(err.getMessage(), err);
+            throw new ConfigurationException("Validation failed", pce);
         }
     }
 

Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java?rev=737777&r1=737776&r2=737777&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
(original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
Mon Jan 26 18:40:33 2009
@@ -1431,6 +1431,7 @@
         conf.setSchemaValidation(true);
         conf.load();
         conf.setProperty("Employee.SSN", "123456789");
+        conf.validate();
         conf.save(testSaveConf);
         conf = new XMLConfiguration(testSaveConf);
         assertEquals("123456789", conf.getString("Employee.SSN"));
@@ -1451,7 +1452,7 @@
         conf.setProperty("Employee.Email", "JohnDoe@apache.org");
         try
         {
-            conf.save(testSaveConf);
+            conf.validate();
             fail("No validation failure on save");
         }
         catch (Exception e)



Mime
View raw message