KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tomcat5 > config > TomcatDatasource


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tomcat5.config;
21
22 import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
23
24 /**
25  * Tomcat datasource implementation
26  *
27  * @author sherold
28  */

29 public class TomcatDatasource implements Datasource {
30     
31     private final String JavaDoc username;
32     private final String JavaDoc url;
33     private final String JavaDoc password;
34     private final String JavaDoc jndiName;
35     private final String JavaDoc driverClassName;
36     private int hash;
37     
38     /**
39      * Creates a new instance of TomcatDatasource
40      */

41     public TomcatDatasource(String JavaDoc username, String JavaDoc url, String JavaDoc password, String JavaDoc jndiName, String JavaDoc driverClassName) {
42         this.username = username;
43         this.url = url;
44         this.password = password;
45         this.jndiName = jndiName;
46         this.driverClassName = driverClassName;
47     }
48
49     public String JavaDoc getUsername() {
50         return username;
51     }
52
53     public String JavaDoc getUrl() {
54         return url;
55     }
56
57     public String JavaDoc getPassword() {
58         return password;
59     }
60
61     public String JavaDoc getJndiName() {
62         return jndiName;
63     }
64
65     public String JavaDoc getDriverClassName() {
66         return driverClassName;
67     }
68
69     public String JavaDoc getDisplayName() {
70         return jndiName + " [" + url + "]"; // NOI18N
71
}
72     
73     public boolean equals(Object JavaDoc obj) {
74         if (this == obj) {
75             return true;
76         }
77         if (!(obj instanceof TomcatDatasource)) {
78             return false;
79         }
80         TomcatDatasource ds = (TomcatDatasource)obj;
81         if ((jndiName == null && ds.jndiName != null) || (jndiName != null && !jndiName.equals(ds.jndiName))) {
82             return false;
83         }
84         if ((url == null && ds.url != null) || (url != null && !url.equals(ds.url))) {
85             return false;
86         }
87         if ((username == null && ds.username != null) || (username != null && !username.equals(ds.username))) {
88             return false;
89         }
90         if ((password == null && ds.password != null) || (password != null && !password.equals(ds.password))) {
91             return false;
92         }
93         if ((driverClassName == null && ds.driverClassName != null) || (driverClassName != null && !driverClassName.equals(ds.driverClassName))) {
94             return false;
95         }
96         return true;
97     }
98     
99     public int hashCode() {
100         if (hash == 0) {
101             int result = 17;
102             result += 37 * result + (jndiName == null ? 0 : jndiName.hashCode());
103             result += 37 * result + (url == null ? 0 : url.hashCode());
104             result += 37 * result + (username == null ? 0 : username.hashCode());
105             result += 37 * result + (password == null ? 0 : password.hashCode());
106             result += 37 * result + (driverClassName == null ? 0 : driverClassName.hashCode());
107             hash = result;
108         }
109         return hash;
110     }
111     
112     public String JavaDoc toString() {
113         StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
114         sb.append("TomcatDatasource [username=").append(username); // NOI18N
115
sb.append(", url=").append(url); // NOI18N
116
sb.append(", password=").append(password); // NOI18N
117
sb.append(", jndiName=").append(jndiName); // NOI18N
118
sb.append(", driverClassName=").append(driverClassName).append("]"); // NOI18N
119
return sb.toString();
120     }
121     
122 }
123
Popular Tags