suppress "variable not initialized" error for break statements. In switch-case statem...
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / model / JDBCDriver.java
1 package com.quantum.model;
2
3 import java.beans.PropertyChangeListener;
4 import java.beans.PropertyChangeSupport;
5 import java.io.File;
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;
12
13 import com.quantum.util.JarUtil;
14 import com.quantum.util.StringArrayComparator;
15
16
17 /**
18  * @author BC
19  */
20 public class JDBCDriver implements Comparable, Displayable {
21         private String name;
22         private String version;
23         private String className;
24         private List jarFileNames = Collections.synchronizedList(new ArrayList());
25         private String type;
26         private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
27         /**
28          * @param className
29          * @param jarFileName
30          */
31         public JDBCDriver(String className, String[] jarFileNames, String type) {
32                 this(className, jarFileNames, type, null, null);
33         }
34         /**
35          * @param className
36          * @param jarFileName
37          * @param name
38          * @param version
39          */
40         public JDBCDriver(String className, String[] jarFileNames, String type, String name, String version) {
41                 this.name = name;
42                 this.version = version;
43                 this.type = type;
44                 this.className = className;
45                 this.jarFileNames.addAll(Arrays.asList(jarFileNames));
46         }
47         /**
48          * @return Returns the className.
49          */
50         public String getClassName() {
51                 return this.className;
52         }
53         /**
54          * @param className The className to set.
55          */
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);
61                 }
62         }
63         /**
64          * @return Returns the jarFileName.
65          */
66         public String[] getJarFileNames() {
67                 return (String[]) this.jarFileNames.toArray(new String[this.jarFileNames.size()]);
68         }
69         /**
70          * @param jarFileName The jarFileName to set.
71          */
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()]),
76                                 jarFileNames) != 0) {
77                         String[] original = getJarFileNames();
78                         this.jarFileNames.clear();
79                         this.jarFileNames.addAll(Arrays.asList(jarFileNames));
80                         this.propertyChangeSupport.firePropertyChange("jarFileName", original, jarFileNames);
81                 }
82         }
83         /**
84          * @return Returns the name.
85          */
86         public String getName() {
87                 return this.name == null || this.name.trim().length() == 0 ? getClassName() : this.name;
88         }
89         /**
90          * @param name The name to set.
91          */
92         public void setName(String name) {
93                 if (name != null && !name.equals(this.name)) {
94                         String original = this.name;
95                         this.name = name;
96                         this.propertyChangeSupport.firePropertyChange("name", original, name);
97                 }
98         }
99         /**
100          * @return Returns the version.
101          */
102         public String getVersion() {
103                 return this.version;
104         }
105         /**
106          * @param version The version to set.
107          */
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);
113                 }
114         }
115         
116         public boolean equals(Object object) {
117                 if (super.equals(object)) {
118                         return true;
119                 } else if (object == null) {
120                         return false;
121                 } else if (getClass() != object.getClass()) {
122                         return false;
123                 } else {
124                         return equals((JDBCDriver) object);
125                 }
126         }
127         /**
128          * @param that
129          * @return
130          */
131         private boolean equals(JDBCDriver that) {
132                 if (this.className == null && that.className != null) {
133                         return false;
134                 } else if (this.className != null && !this.className.equals(that.className)) {
135                         return false;
136                 } else if ((new StringArrayComparator()).compare(
137                                 this.getJarFileNames(), that.getJarFileNames()) != 0) {
138                         return false;
139                 } else if (this.type == null && that.type != null) {
140                         return false;
141                 } else if (this.type != null && !this.type.equals(that.type)) {
142                         return false;
143                 } else {
144                         return true;
145                 }
146         }
147         public int hashCode() {
148                 int hashCode = 31;
149                 if (this.className != null) {
150                         hashCode ^= this.className.hashCode();
151                 }
152                 for (Iterator i = this.jarFileNames.iterator(); i.hasNext();) {
153                         Object jarFile = i.next();
154                         if (jarFile != null) {
155                                 hashCode ^= jarFile.hashCode();
156                         }
157                 }
158                 if (this.type != null) {
159                         hashCode ^= this.type.hashCode();
160                 }
161                 return hashCode;
162         }
163         
164         public Driver getDriver() {
165                 return JarUtil.loadDriver(getJarFileNames(), getClassName());
166         }
167         /**
168          * @param listener
169          */
170         public void addPropertyChangeListener(PropertyChangeListener listener) {
171                 this.propertyChangeSupport.addPropertyChangeListener(listener);
172         }
173         /**
174          * @param propertyName
175          * @param listener
176          */
177         public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
178                 this.propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
179         }
180         /**
181          * @param arg0
182          */
183         public void removePropertyChangeListener(PropertyChangeListener arg0) {
184                 this.propertyChangeSupport.removePropertyChangeListener(arg0);
185         }
186         /**
187          * @param arg0
188          * @param arg1
189          */
190         public void removePropertyChangeListener(String arg0, PropertyChangeListener arg1) {
191                 this.propertyChangeSupport.removePropertyChangeListener(arg0, arg1);
192         }
193         /**
194          * @return Returns the type.
195          */
196         public String getType() {
197                 return this.type;
198         }
199         /**
200          * @param type The type to set.
201          */
202         public void setType(String type) {
203                 if (type != null && !type.equals(this.type)) {
204                         String original = this.type;
205                         this.type = type;
206                         this.propertyChangeSupport.firePropertyChange("type", original, type);
207                 }
208         }
209         /* (non-Javadoc)
210          * @see java.lang.Comparable#compareTo(java.lang.Object)
211          */
212         public int compareTo(Object object) {
213                 return (new DisplayableComparator()).compare(this, object);
214         }
215         /* (non-Javadoc)
216          * @see com.quantum.model.Displayable#getDisplayName()
217          */
218         public String getDisplayName() {
219                 return getName();
220         }
221         
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);
227                         if (i.hasNext()) {
228                                 buffer.append(File.pathSeparator);
229                         }
230                 }
231                 return buffer.toString();
232         }
233 }