Updated .cvsignore to be more minimalist, and only excludes the bin dir
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / model / xml / ModelToXMLConverter.java
index 908b239..e295b03 100644 (file)
@@ -1,9 +1,12 @@
 package com.quantum.model.xml;
 
-import com.quantum.Messages;
+import java.sql.SQLException;
+
 import com.quantum.model.Bookmark;
 import com.quantum.model.Column;
 import com.quantum.model.Entity;
+import com.quantum.model.JDBCDriver;
+import com.quantum.model.NotConnectedException;
 import com.quantum.model.Schema;
 import com.quantum.sql.metadata.MetaDataXMLInterface;
 
@@ -28,6 +31,25 @@ public class ModelToXMLConverter {
     public void createRoot(Document document) {
         document.appendChild(document.createElement("SAVED_DATA"));
     }
+    public void convert(Element bookmarkRoot, JDBCDriver jdbcDriver) {
+        Document document = bookmarkRoot.getOwnerDocument();
+        Element driverNode = document.createElement("jdbcDriver");
+        driverNode.setAttribute("name", jdbcDriver.getName());
+        driverNode.setAttribute("version", jdbcDriver.getVersion());
+        driverNode.setAttribute("type", jdbcDriver.getType());
+        driverNode.setAttribute("className", jdbcDriver.getClassName());
+        
+        String[] fileNames = jdbcDriver.getJarFileNames();
+        for (int i = 0, length = fileNames == null ? 0 : fileNames.length; i < length; i++) {
+               if (fileNames[i] != null) {
+                               Element fileName = document.createElement("jar");
+                               fileName.setAttribute("fileName", fileNames[i]);
+                               driverNode.appendChild(fileName);
+               }
+               }
+        
+        bookmarkRoot.appendChild(driverNode);
+    }
 
     public void convert(Element bookmarkRoot, Bookmark b) {
         Document document = bookmarkRoot.getOwnerDocument();
@@ -39,19 +61,24 @@ public class ModelToXMLConverter {
         MetaDataXMLInterface.createElementText(bookmark,"connect", b.getConnect()); //$NON-NLS-1$
                MetaDataXMLInterface.createElementText(bookmark,"autoCommit", b.isAutoCommit() ? "true" : "false"); //$NON-NLS-1$
                MetaDataXMLInterface.createElementText(bookmark,"autoCommitPreference", b.getAutoCommitPreference()); //$NON-NLS-1$
-        MetaDataXMLInterface.createElementText(bookmark,"driver", b.getDriver()); //$NON-NLS-1$
-        MetaDataXMLInterface.createElementText(bookmark,"type", b.getType()); //$NON-NLS-1$
-               MetaDataXMLInterface.createElementText(bookmark,"driverLocation", b.getDriverFile()); //$NON-NLS-1$
-        Element otherSchemas = (Element) bookmark.appendChild(document.createElement(Messages.getString("ExportXMLAction.OtherSchemas"))); //$NON-NLS-1$
-        Schema[] schemas = b.getSchemas();
-        for (int i = 0, length = (schemas == null) ? 0 : schemas.length;
-            i < length;
-            i++) {
-            if (!schemas[i].isDefault()) {
-                MetaDataXMLInterface.createElementText(
-                    otherSchemas,Messages.getString("ExportXMLAction.SchemaName"), schemas[i].getName()); //$NON-NLS-1$
-            }
+        MetaDataXMLInterface.createElementText(bookmark,"driver", b.getJDBCDriver().getClassName()); //$NON-NLS-1$
+        MetaDataXMLInterface.createElementText(bookmark,"type", b.getJDBCDriver().getType()); //$NON-NLS-1$
+        String[] fileNames = b.getJDBCDriver().getJarFileNames();
+        for (int i = 0, length = fileNames == null ? 0 : fileNames.length; i < length; i++) {
+                       MetaDataXMLInterface.createElementText(bookmark,"driverLocation", fileNames[i]);
+               }
+        Element otherSchemas = (Element) bookmark.appendChild(document.createElement("Other_Schemas")); //$NON-NLS-1$
+        otherSchemas.setAttribute("schemaRule", 
+                       b.useAllSchemas() 
+                                       ? "useAll" 
+                                       : b.useUsernameAsSchema() ? "useDefault" : "useSelected");
+        
+        Schema[] schemas = b.getSchemaSelections();
+        for (int i = 0, length = (schemas == null) ? 0 : schemas.length; i < length; i++) {
+            MetaDataXMLInterface.createElementText(
+                otherSchemas,"schema", schemas[i].getName()); //$NON-NLS-1$
         }
+        
         Entity[] quickList = b.getQuickListEntries();
         Element quickListEntity = document.createElement("quickList");
         for (int j = 0, length = (quickList == null) ? 0 : quickList.length;
@@ -74,8 +101,13 @@ public class ModelToXMLConverter {
         if (entity.getSchema() != null) {
             element.setAttribute("schema", entity.getSchema());
         }
+        element.setAttribute("isSynonym", entity.isSynonym() ? "true" : "false");
         if (recurse) {
-            convert(element, entity.getColumns());
+            try {
+                               convert(element, entity.getColumns());
+                       } catch (NotConnectedException e) {
+                       } catch (SQLException e) {
+                       }
         }
         parent.appendChild(element);
     }