Separate XDebugResponse from ResponseListner.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / model / JDBCDriver.java
index aff0f3c..d768589 100644 (file)
@@ -2,33 +2,34 @@ package com.quantum.model;
 
 import java.beans.PropertyChangeListener;
 import java.beans.PropertyChangeSupport;
+import java.io.File;
 import java.sql.Driver;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
 
 import com.quantum.util.JarUtil;
+import com.quantum.util.StringArrayComparator;
 
 
 /**
  * @author BC
  */
-public class JDBCDriver {
+public class JDBCDriver implements Comparable, Displayable {
        private String name;
        private String version;
        private String className;
-       private String jarFileName;
+       private List jarFileNames = Collections.synchronizedList(new ArrayList());
+       private String type;
        private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
        /**
         * @param className
         * @param jarFileName
         */
-       public JDBCDriver(String className, String jarFileName) {
-               super();
-               this.className = className;
-               this.jarFileName = jarFileName;
-       }
-       /**
-        * 
-        */
-       public JDBCDriver() {
+       public JDBCDriver(String className, String[] jarFileNames, String type) {
+               this(className, jarFileNames, type, null, null);
        }
        /**
         * @param className
@@ -36,11 +37,12 @@ public class JDBCDriver {
         * @param name
         * @param version
         */
-       public JDBCDriver(String className, String jarFileName, String name, String version) {
+       public JDBCDriver(String className, String[] jarFileNames, String type, String name, String version) {
                this.name = name;
                this.version = version;
+               this.type = type;
                this.className = className;
-               this.jarFileName = jarFileName;
+               this.jarFileNames.addAll(Arrays.asList(jarFileNames));
        }
        /**
         * @return Returns the className.
@@ -61,17 +63,21 @@ public class JDBCDriver {
        /**
         * @return Returns the jarFileName.
         */
-       public String getJarFileName() {
-               return this.jarFileName;
+       public String[] getJarFileNames() {
+               return (String[]) this.jarFileNames.toArray(new String[this.jarFileNames.size()]);
        }
        /**
         * @param jarFileName The jarFileName to set.
         */
-       public void setJarFileName(String jarFileName) {
-               if (jarFileName != null && !jarFileName.equals(this.jarFileName)) {
-                       String original = this.jarFileName;
-                       this.jarFileName = jarFileName;
-                       this.propertyChangeSupport.firePropertyChange("jarFileName", original, jarFileName);
+       public void setJarFileNames(String[] jarFileNames) {
+               StringArrayComparator comparator = new StringArrayComparator();
+               if (comparator.compare(
+                               (String[]) this.jarFileNames.toArray(new String[this.jarFileNames.size()]),
+                               jarFileNames) != 0) {
+                       String[] original = getJarFileNames();
+                       this.jarFileNames.clear();
+                       this.jarFileNames.addAll(Arrays.asList(jarFileNames));
+                       this.propertyChangeSupport.firePropertyChange("jarFileName", original, jarFileNames);
                }
        }
        /**
@@ -115,19 +121,27 @@ public class JDBCDriver {
                } else if (getClass() != object.getClass()) {
                        return false;
                } else {
-                       JDBCDriver that = (JDBCDriver) object;
-                       
-                       if (this.className == null && that.className != null) {
-                               return false;
-                       } else if (this.className != null && !this.className.equals(that.className)) {
-                               return false;
-                       } else if (this.jarFileName == null && that.jarFileName != null) {
-                               return false;
-                       } else if (this.jarFileName != null && !this.jarFileName.equals(that.jarFileName)) {
-                               return false;
-                       } else {
-                               return true;
-                       }
+                       return equals((JDBCDriver) object);
+               }
+       }
+       /**
+        * @param that
+        * @return
+        */
+       private boolean equals(JDBCDriver that) {
+               if (this.className == null && that.className != null) {
+                       return false;
+               } else if (this.className != null && !this.className.equals(that.className)) {
+                       return false;
+               } else if ((new StringArrayComparator()).compare(
+                               this.getJarFileNames(), that.getJarFileNames()) != 0) {
+                       return false;
+               } else if (this.type == null && that.type != null) {
+                       return false;
+               } else if (this.type != null && !this.type.equals(that.type)) {
+                       return false;
+               } else {
+                       return true;
                }
        }
        public int hashCode() {
@@ -135,14 +149,20 @@ public class JDBCDriver {
                if (this.className != null) {
                        hashCode ^= this.className.hashCode();
                }
-               if (this.jarFileName != null) {
-                       hashCode ^= this.jarFileName.hashCode();
+               for (Iterator i = this.jarFileNames.iterator(); i.hasNext();) {
+                       Object jarFile = i.next();
+                       if (jarFile != null) {
+                               hashCode ^= jarFile.hashCode();
+                       }
+               }
+               if (this.type != null) {
+                       hashCode ^= this.type.hashCode();
                }
                return hashCode;
        }
        
        public Driver getDriver() {
-               return JarUtil.loadDriver(getJarFileName(), getClassName());
+               return JarUtil.loadDriver(getJarFileNames(), getClassName());
        }
        /**
         * @param listener
@@ -170,4 +190,44 @@ public class JDBCDriver {
        public void removePropertyChangeListener(String arg0, PropertyChangeListener arg1) {
                this.propertyChangeSupport.removePropertyChangeListener(arg0, arg1);
        }
+       /**
+        * @return Returns the type.
+        */
+       public String getType() {
+               return this.type;
+       }
+       /**
+        * @param type The type to set.
+        */
+       public void setType(String type) {
+               if (type != null && !type.equals(this.type)) {
+                       String original = this.type;
+                       this.type = type;
+                       this.propertyChangeSupport.firePropertyChange("type", original, type);
+               }
+       }
+       /* (non-Javadoc)
+        * @see java.lang.Comparable#compareTo(java.lang.Object)
+        */
+       public int compareTo(Object object) {
+               return (new DisplayableComparator()).compare(this, object);
+       }
+       /* (non-Javadoc)
+        * @see com.quantum.model.Displayable#getDisplayName()
+        */
+       public String getDisplayName() {
+               return getName();
+       }
+       
+       public String getJarFilePath() {
+               StringBuffer buffer = new StringBuffer();
+               for (Iterator i = this.jarFileNames.iterator(); i.hasNext();) {
+                       String element = (String) i.next();
+                       buffer.append(element);
+                       if (i.hasNext()) {
+                               buffer.append(File.pathSeparator);
+                       }
+               }
+               return buffer.toString();
+       }
 }