db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r481151 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/io/DatabaseIO.java java/org/apache/ddlutils/io/LocalEntityResolver.java test/org/apache/ddlutils/io/TestDatabaseIO.java
Date Fri, 01 Dec 2006 04:53:49 GMT
Author: tomdz
Date: Thu Nov 30 20:53:48 2006
New Revision: 481151

URL: http://svn.apache.org/viewvc?view=rev&rev=481151
Log:
Fix for DDLUTILS-136

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DatabaseIO.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/io/LocalEntityResolver.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatabaseIO.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DatabaseIO.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DatabaseIO.java?view=diff&rev=481151&r1=481150&r2=481151
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DatabaseIO.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/io/DatabaseIO.java Thu Nov 30 20:53:48
2006
@@ -132,18 +132,25 @@
      * @param output The target output writer
      * @return The writer
      */
-    protected BeanWriter getWriter(Writer output) throws IntrospectionException, SAXException,
IOException
+    protected BeanWriter getWriter(Writer output) throws DdlUtilsException
     {
-        BeanWriter writer = new BeanWriter(output);
-
-        writer.getXMLIntrospector().register(getBetwixtMapping());
-        writer.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
-        writer.getXMLIntrospector().getConfiguration().setWrapCollectionsInElement(false);
-        writer.getXMLIntrospector().getConfiguration().setElementNameMapper(new HyphenatedNameMapper());
-        writer.getBindingConfiguration().setMapIDs(false);
-        writer.enablePrettyPrint();
-
-        return writer;
+        try
+        {
+            BeanWriter writer = new BeanWriter(output);
+    
+            writer.getXMLIntrospector().register(getBetwixtMapping());
+            writer.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(true);
+            writer.getXMLIntrospector().getConfiguration().setWrapCollectionsInElement(false);
+            writer.getXMLIntrospector().getConfiguration().setElementNameMapper(new HyphenatedNameMapper());
+            writer.getBindingConfiguration().setMapIDs(false);
+            writer.enablePrettyPrint();
+    
+            return writer;
+        }
+        catch (Exception ex)
+        {
+            throw new DdlUtilsException(ex);
+        }
     }
 
     /**
@@ -233,6 +240,7 @@
         model.initialize();
         return model;
     }
+
     /**
      * Writes the database model to the specified file.
      * 
@@ -249,7 +257,7 @@
             {
                 writer = new BufferedWriter(new FileWriter(filename));
     
-                getWriter(writer).write(model);
+                write(model, writer);
                 writer.flush();
             }
             finally
@@ -275,14 +283,7 @@
      */
     public void write(Database model, OutputStream output) throws DdlUtilsException
     {
-        try
-        {
-            getWriter(new OutputStreamWriter(output)).write(model);
-        }
-        catch (Exception ex)
-        {
-            throw new DdlUtilsException(ex);
-        }
+        write(model, getWriter(new OutputStreamWriter(output)));
     }
 
     /**
@@ -294,9 +295,21 @@
      */
     public void write(Database model, Writer output) throws DdlUtilsException
     {
+        write(model, getWriter(output));
+    }
+
+    /**
+     * Internal method that writes the database model using the given bean writer.
+     * 
+     * @param model  The database model
+     * @param writer The bean writer
+     */
+    private void write(Database model, BeanWriter writer) throws DdlUtilsException
+    {
         try
         {
-            getWriter(output).write(model);
+            writer.writeXmlDeclaration("<?xml version=\"1.0\"?>\n<!DOCTYPE database
SYSTEM \"" + LocalEntityResolver.DTD_PREFIX + "\">");
+            writer.write(model);
         }
         catch (Exception ex)
         {

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/io/LocalEntityResolver.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/io/LocalEntityResolver.java?view=diff&rev=481151&r1=481150&r2=481151
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/io/LocalEntityResolver.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/io/LocalEntityResolver.java Thu Nov 30
20:53:48 2006
@@ -36,7 +36,7 @@
 public class LocalEntityResolver implements EntityResolver
 {
     /** The default DTD. */
-    private static final String DTD_PREFIX = "http://db.apache.org/torque/dtd/database";
+    public static final String DTD_PREFIX = "http://db.apache.org/torque/dtd/database";
 
     /**
      * {@inheritDoc}

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatabaseIO.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatabaseIO.java?view=diff&rev=481151&r1=481150&r2=481151
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatabaseIO.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDatabaseIO.java Thu Nov 30 20:53:48
2006
@@ -130,6 +130,7 @@
                      column.getDescription());
         assertEquals("javaId", column.getJavaName());
         assertEquals(
+            "<?xml version=\"1.0\"?>\n<!DOCTYPE database SYSTEM \"" + LocalEntityResolver.DTD_PREFIX
+ "\">\n" +
             "  <database name=\"test\">\n" +
             "    <table name=\"SomeTable\" description=\"Some table\">\n" +
             "      <column name=\"ID\" primaryKey=\"true\" required=\"true\" type=\"INTEGER\"
autoIncrement=\"false\" description=\"The primary key\" javaName=\"javaId\"/>\n" +
@@ -254,6 +255,7 @@
                      ref.getForeignColumnName());
 
         assertEquals(
+            "<?xml version=\"1.0\"?>\n<!DOCTYPE database SYSTEM \"" + LocalEntityResolver.DTD_PREFIX
+ "\">\n" +
             "  <database name=\"test\">\n" +
             "    <table name=\"SomeTable\" description=\"Some table\">\n" +
             "      <column name=\"ID\" primaryKey=\"true\" required=\"true\" type=\"VARCHAR\"
size=\"16\" autoIncrement=\"false\" description=\"The primary key\"/>\n" +
@@ -392,6 +394,7 @@
         assertNull(indexColumn.getSize());
 
         assertEquals(
+            "<?xml version=\"1.0\"?>\n<!DOCTYPE database SYSTEM \"" + LocalEntityResolver.DTD_PREFIX
+ "\">\n" +
             "  <database name=\"test\">\n" +
             "    <table name=\"TableWidthIndex\">\n" +
             "      <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"DOUBLE\"
autoIncrement=\"false\"/>\n" +
@@ -510,6 +513,7 @@
         assertNull(indexColumn.getSize());
 
         assertEquals(
+            "<?xml version=\"1.0\"?>\n<!DOCTYPE database SYSTEM \"" + LocalEntityResolver.DTD_PREFIX
+ "\">\n" +
             "  <database name=\"test\">\n" +
             "    <table name=\"TableWidthIndices\">\n" +
             "      <column name=\"id\" primaryKey=\"false\" required=\"true\" type=\"SMALLINT\"
autoIncrement=\"true\"/>\n" +
@@ -914,6 +918,7 @@
         assertNull(indexColumn.getSize());
 
         assertEquals(
+            "<?xml version=\"1.0\"?>\n<!DOCTYPE database SYSTEM \"" + LocalEntityResolver.DTD_PREFIX
+ "\">\n" +
             "  <database name=\"test\">\n" +
             "    <table name=\"A\" description=\"Table A\">\n" +
             "      <column name=\"id\" primaryKey=\"true\" required=\"true\" type=\"INTEGER\"
autoIncrement=\"true\" description=\"The primary key of table A\"/>\n" +
@@ -1333,6 +1338,7 @@
         assertNull(column.getDescription());
 
         assertEquals(
+            "<?xml version=\"1.0\"?>\n<!DOCTYPE database SYSTEM \"" + LocalEntityResolver.DTD_PREFIX
+ "\">\n" +
             "  <database name=\"test\">\n" +
             "    <table name=\"SomeTable\">\n" +
             "      <column name=\"intField\" primaryKey=\"false\" required=\"false\" type=\"TINYINT\"
autoIncrement=\"false\"/>\n" +



Mime
View raw message