1 package com.quantum.model;
3 import java.beans.PropertyChangeListener;
4 import java.beans.PropertyChangeSupport;
6 import java.sql.Driver;
7 import java.util.ArrayList;
8 import java.util.Arrays;
9 import java.util.Collections;
10 import java.util.Iterator;
11 import java.util.List;
13 import com.quantum.util.JarUtil;
14 import com.quantum.util.StringArrayComparator;
20 public class JDBCDriver implements Comparable, Displayable {
22 private String version;
23 private String className;
24 private List jarFileNames = Collections.synchronizedList(new ArrayList());
26 private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
31 public JDBCDriver(String className, String[] jarFileNames, String type) {
32 this(className, jarFileNames, type, null, null);
40 public JDBCDriver(String className, String[] jarFileNames, String type, String name, String version) {
42 this.version = version;
44 this.className = className;
45 this.jarFileNames.addAll(Arrays.asList(jarFileNames));
48 * @return Returns the className.
50 public String getClassName() {
51 return this.className;
54 * @param className The className to set.
56 public void setClassName(String className) {
57 if (className != null && !className.equals(this.className)) {
58 String original = this.className;
59 this.className = className;
60 this.propertyChangeSupport.firePropertyChange("className", original, className);
64 * @return Returns the jarFileName.
66 public String[] getJarFileNames() {
67 return (String[]) this.jarFileNames.toArray(new String[this.jarFileNames.size()]);
70 * @param jarFileName The jarFileName to set.
72 public void setJarFileNames(String[] jarFileNames) {
73 StringArrayComparator comparator = new StringArrayComparator();
74 if (comparator.compare(
75 (String[]) this.jarFileNames.toArray(new String[this.jarFileNames.size()]),
77 String[] original = getJarFileNames();
78 this.jarFileNames.clear();
79 this.jarFileNames.addAll(Arrays.asList(jarFileNames));
80 this.propertyChangeSupport.firePropertyChange("jarFileName", original, jarFileNames);
84 * @return Returns the name.
86 public String getName() {
87 return this.name == null || this.name.trim().length() == 0 ? getClassName() : this.name;
90 * @param name The name to set.
92 public void setName(String name) {
93 if (name != null && !name.equals(this.name)) {
94 String original = this.name;
96 this.propertyChangeSupport.firePropertyChange("name", original, name);
100 * @return Returns the version.
102 public String getVersion() {
106 * @param version The version to set.
108 public void setVersion(String version) {
109 if (version != null && !version.equals(this.version)) {
110 String original = this.version;
111 this.version = version;
112 this.propertyChangeSupport.firePropertyChange("version", original, version);
116 public boolean equals(Object object) {
117 if (super.equals(object)) {
119 } else if (object == null) {
121 } else if (getClass() != object.getClass()) {
124 return equals((JDBCDriver) object);
131 private boolean equals(JDBCDriver that) {
132 if (this.className == null && that.className != null) {
134 } else if (this.className != null && !this.className.equals(that.className)) {
136 } else if ((new StringArrayComparator()).compare(
137 this.getJarFileNames(), that.getJarFileNames()) != 0) {
139 } else if (this.type == null && that.type != null) {
141 } else if (this.type != null && !this.type.equals(that.type)) {
147 public int hashCode() {
149 if (this.className != null) {
150 hashCode ^= this.className.hashCode();
152 for (Iterator i = this.jarFileNames.iterator(); i.hasNext();) {
153 Object jarFile = i.next();
154 if (jarFile != null) {
155 hashCode ^= jarFile.hashCode();
158 if (this.type != null) {
159 hashCode ^= this.type.hashCode();
164 public Driver getDriver() {
165 return JarUtil.loadDriver(getJarFileNames(), getClassName());
170 public void addPropertyChangeListener(PropertyChangeListener listener) {
171 this.propertyChangeSupport.addPropertyChangeListener(listener);
174 * @param propertyName
177 public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
178 this.propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
183 public void removePropertyChangeListener(PropertyChangeListener arg0) {
184 this.propertyChangeSupport.removePropertyChangeListener(arg0);
190 public void removePropertyChangeListener(String arg0, PropertyChangeListener arg1) {
191 this.propertyChangeSupport.removePropertyChangeListener(arg0, arg1);
194 * @return Returns the type.
196 public String getType() {
200 * @param type The type to set.
202 public void setType(String type) {
203 if (type != null && !type.equals(this.type)) {
204 String original = this.type;
206 this.propertyChangeSupport.firePropertyChange("type", original, type);
210 * @see java.lang.Comparable#compareTo(java.lang.Object)
212 public int compareTo(Object object) {
213 return (new DisplayableComparator()).compare(this, object);
216 * @see com.quantum.model.Displayable#getDisplayName()
218 public String getDisplayName() {
222 public String getJarFilePath() {
223 StringBuffer buffer = new StringBuffer();
224 for (Iterator i = this.jarFileNames.iterator(); i.hasNext();) {
225 String element = (String) i.next();
226 buffer.append(element);
228 buffer.append(File.pathSeparator);
231 return buffer.toString();