import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
+import java.util.Set;
import java.util.Vector;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
import com.quantum.IQuantumConstants;
import com.quantum.Messages;
import com.quantum.model.xml.ModelToXMLConverter;
import com.quantum.sql.metadata.MetaDataXMLInterface;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
/**
* The collection of database bookmarks that the Quantum plug-in knows about.
* This collection is loaded by the QuantumPlugin class before any Quantum plugin
private List bookmarks = new Vector();
private boolean changed = false;
private PropertyChangeSupport support = new PropertyChangeSupport(this);
+ private Set drivers = Collections.synchronizedSet(new HashSet());
private BookmarkCollection() {
}
newBookmarks.add(bookmark);
}
i++;
+ this.drivers.add(new JDBCDriver(bookmark.getDriver(), driverFile));
}
if (overwrite) {
this.bookmarks = newBookmarks;
public void exportXML(Element root) {
System.out.println("Bookmarks: Saving to Element"); //$NON-NLS-1$
Element bookmarkRoot = MetaDataXMLInterface.createElementText(root,"bookmarks", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ for (Iterator i = this.drivers.iterator(); i.hasNext(); ) {
+ JDBCDriver driver = (JDBCDriver) i.next();
+ ModelToXMLConverter.getInstance().convert(bookmarkRoot, driver);
+ }
for (int i = 0; i < bookmarks.size(); i++) {
Bookmark b = (Bookmark) bookmarks.get(i);
ModelToXMLConverter.getInstance().convert(bookmarkRoot, b);
public void importXML(Element root) {
this.changed = true;
System.out.println("Bookmarks: Loading from Element"); //$NON-NLS-1$
- Vector newBookmarks = new Vector();
+ importDrivers(root);
+ Vector newBookmarks = importBookmarks(root);
+ this.bookmarks.addAll(newBookmarks);
+ this.support.firePropertyChange("bookmarks", null, null);
+ }
+
+ /**
+ * @param root
+ * @return
+ */
+ private void importDrivers(Element root) {
+ NodeList nodes = root.getElementsByTagName("jdbcDriver"); //$NON-NLS-1$
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Element driver = (Element) nodes.item(i);
+ addDriver(new JDBCDriver(
+ driver.getAttribute("className"),
+ driver.getAttribute("jarFileName"),
+ driver.getAttribute("name"),
+ driver.getAttribute("version")));
+ }
+ }
+
+ /**
+ * @param driver
+ */
+ public void addDriver(JDBCDriver driver) {
+ if (!this.drivers.contains(driver)) {
+ this.drivers.add(driver);
+ this.support.firePropertyChange("drivers", null, driver);
+ }
+ }
+
+ /**
+ * @param root
+ * @return
+ */
+ private Vector importBookmarks(Element root) {
+ Vector newBookmarks = new Vector();
NodeList nodes = root.getElementsByTagName("bookmark"); //$NON-NLS-1$
for (int i = 0; i < nodes.getLength(); i++) {
Bookmark bookmark = new Bookmark();
bookmark.setAutoCommit(Boolean.TRUE.toString().equalsIgnoreCase(
MetaDataXMLInterface.getElementText(column,"autoCommit", "True"))); //$NON-NLS-1$
bookmark.setAutoCommitPreference(MetaDataXMLInterface.getElementText(column,"autoCommitPreference", IQuantumConstants.autoCommitTrue)); //$NON-NLS-1$
- bookmark.setDriver(MetaDataXMLInterface.getElementText(column,"driver")); //$NON-NLS-1$
bookmark.addSchema(MetaDataXMLInterface.getElementText(column,"schema")); //$NON-NLS-1$
bookmark.setType(MetaDataXMLInterface.getElementText(column,"type")); //$NON-NLS-1$
- bookmark.setDriverFile(MetaDataXMLInterface.getElementText(column,"driverLocation")); //$NON-NLS-1$
NodeList children = column.getElementsByTagName(Messages.getString("ExportXMLAction.OtherSchemas"));
+
+ String driverClassName = MetaDataXMLInterface.getElementText(column,"driver"); //$NON-NLS-1$
+ String driverFile = MetaDataXMLInterface.getElementText(column,"driverLocation"); //$NON-NLS-1$
+
+ bookmark.setJDBCDriver(new JDBCDriver(driverClassName, driverFile));
+
if (children.getLength() > 0) {
importSchemas((Element) children.item(0), bookmark);
}
importQuickList(bookmark, column);
importQueryList(bookmark, column);
}
- this.bookmarks.addAll(newBookmarks);
- this.support.firePropertyChange("bookmarks", null, null);
- }
+ return newBookmarks;
+ }
- private void importSchemas(Element otherSchemas, Bookmark bookmark) {
+ private void importSchemas(Element otherSchemas, Bookmark bookmark) {
Vector vector = MetaDataXMLInterface.getVectorText(otherSchemas, Messages.getString("ExportXMLAction.SchemaName"));
List list = new ArrayList();
for (Iterator i = vector.iterator(); i.hasNext();) {
public Bookmark[] getBookmarks() {
return (Bookmark[]) this.bookmarks.toArray(new Bookmark[this.bookmarks.size()]);
}
+
+ public JDBCDriver[] getJDBCDrivers() {
+ return (JDBCDriver[]) this.drivers.toArray(new JDBCDriver[this.drivers.size()]);
+ }
/**
* @return
*/
return copyName;
}
+ /**
+ * @param driver
+ * @param driverFile
+ */
+ public JDBCDriver findDriver(String driverClassName, String driverFile) {
+ JDBCDriver temp = new JDBCDriver(driverClassName, driverFile);
+ return findDriver(temp);
+ }
+
+ /**
+ * @param temp
+ * @return
+ */
+ public JDBCDriver findDriver(JDBCDriver temp) {
+ JDBCDriver result = null;
+ for (Iterator i = this.drivers.iterator(); result == null && i.hasNext();) {
+ JDBCDriver driver = (JDBCDriver) i.next();
+ if (temp.equals(driver)) {
+ result = driver;
+ }
+ }
+ if (result == null) {
+ addDriver(temp);
+ result = temp;
+ }
+ return result;
+ }
+
}