synchronized from quantum plugin
[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.sql.Driver;
6
7 import com.quantum.util.JarUtil;
8
9
10 /**
11  * @author BC
12  */
13 public class JDBCDriver {
14         private String name;
15         private String version;
16         private String className;
17         private String jarFileName;
18         private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
19         /**
20          * @param className
21          * @param jarFileName
22          */
23         public JDBCDriver(String className, String jarFileName) {
24                 super();
25                 this.className = className;
26                 this.jarFileName = jarFileName;
27         }
28         /**
29          * 
30          */
31         public JDBCDriver() {
32         }
33         /**
34          * @param className
35          * @param jarFileName
36          * @param name
37          * @param version
38          */
39         public JDBCDriver(String className, String jarFileName, String name, String version) {
40                 this.name = name;
41                 this.version = version;
42                 this.className = className;
43                 this.jarFileName = jarFileName;
44         }
45         /**
46          * @return Returns the className.
47          */
48         public String getClassName() {
49                 return this.className;
50         }
51         /**
52          * @param className The className to set.
53          */
54         public void setClassName(String className) {
55                 if (className != null && !className.equals(this.className)) {
56                         String original = this.className;
57                         this.className = className;
58                         this.propertyChangeSupport.firePropertyChange("className", original, className);
59                 }
60         }
61         /**
62          * @return Returns the jarFileName.
63          */
64         public String getJarFileName() {
65                 return this.jarFileName;
66         }
67         /**
68          * @param jarFileName The jarFileName to set.
69          */
70         public void setJarFileName(String jarFileName) {
71                 if (jarFileName != null && !jarFileName.equals(this.jarFileName)) {
72                         String original = this.jarFileName;
73                         this.jarFileName = jarFileName;
74                         this.propertyChangeSupport.firePropertyChange("jarFileName", original, jarFileName);
75                 }
76         }
77         /**
78          * @return Returns the name.
79          */
80         public String getName() {
81                 return this.name == null || this.name.trim().length() == 0 ? getClassName() : this.name;
82         }
83         /**
84          * @param name The name to set.
85          */
86         public void setName(String name) {
87                 if (name != null && !name.equals(this.name)) {
88                         String original = this.name;
89                         this.name = name;
90                         this.propertyChangeSupport.firePropertyChange("name", original, name);
91                 }
92         }
93         /**
94          * @return Returns the version.
95          */
96         public String getVersion() {
97                 return this.version;
98         }
99         /**
100          * @param version The version to set.
101          */
102         public void setVersion(String version) {
103                 if (version != null && !version.equals(this.version)) {
104                         String original = this.version;
105                         this.version = version;
106                         this.propertyChangeSupport.firePropertyChange("version", original, version);
107                 }
108         }
109         
110         public boolean equals(Object object) {
111                 if (super.equals(object)) {
112                         return true;
113                 } else if (object == null) {
114                         return false;
115                 } else if (getClass() != object.getClass()) {
116                         return false;
117                 } else {
118                         JDBCDriver that = (JDBCDriver) object;
119                         
120                         if (this.className == null && that.className != null) {
121                                 return false;
122                         } else if (this.className != null && !this.className.equals(that.className)) {
123                                 return false;
124                         } else if (this.jarFileName == null && that.jarFileName != null) {
125                                 return false;
126                         } else if (this.jarFileName != null && !this.jarFileName.equals(that.jarFileName)) {
127                                 return false;
128                         } else {
129                                 return true;
130                         }
131                 }
132         }
133         public int hashCode() {
134                 int hashCode = 31;
135                 if (this.className != null) {
136                         hashCode ^= this.className.hashCode();
137                 }
138                 if (this.jarFileName != null) {
139                         hashCode ^= this.jarFileName.hashCode();
140                 }
141                 return hashCode;
142         }
143         
144         public Driver getDriver() {
145                 return JarUtil.loadDriver(getJarFileName(), getClassName());
146         }
147         /**
148          * @param listener
149          */
150         public void addPropertyChangeListener(PropertyChangeListener listener) {
151                 this.propertyChangeSupport.addPropertyChangeListener(listener);
152         }
153         /**
154          * @param propertyName
155          * @param listener
156          */
157         public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
158                 this.propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
159         }
160         /**
161          * @param arg0
162          */
163         public void removePropertyChangeListener(PropertyChangeListener arg0) {
164                 this.propertyChangeSupport.removePropertyChangeListener(arg0);
165         }
166         /**
167          * @param arg0
168          * @param arg1
169          */
170         public void removePropertyChangeListener(String arg0, PropertyChangeListener arg1) {
171                 this.propertyChangeSupport.removePropertyChangeListener(arg0, arg1);
172         }
173 }