KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > common > DatasourceImpl


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.j2ee.common;
21
22 import org.netbeans.modules.j2ee.deployment.common.api.Datasource;
23 import org.openide.util.NbBundle;
24
25
26 /**
27  *
28  * @author Libor Kotouc
29  */

30 public final class DatasourceImpl implements Datasource {
31     
32     private String JavaDoc jndiName;
33     private String JavaDoc url;
34     private String JavaDoc username;
35     private String JavaDoc password;
36     private String JavaDoc driverClassName;
37     private String JavaDoc description;
38     
39     private volatile int hash = -1;
40     
41     public DatasourceImpl(String JavaDoc jndiName, String JavaDoc url, String JavaDoc username, String JavaDoc password, String JavaDoc driverClassName) {
42         this.jndiName = jndiName;
43         this.url = url;
44         this.username = username;
45         this.password = password;
46         this.driverClassName = driverClassName;
47     }
48
49     public String JavaDoc getJndiName() {
50         return jndiName;
51     }
52
53     public String JavaDoc getUrl() {
54         return url;
55     }
56
57     public String JavaDoc getUsername() {
58         return username;
59     }
60
61     public String JavaDoc getPassword() {
62         return password;
63     }
64
65     public String JavaDoc getDriverClassName() {
66         return driverClassName;
67     }
68
69     public String JavaDoc getDisplayName() {
70         if (description == null) {
71             //TODO implement some meaningful description
72
description = getJndiName() + " [" + getUrl() + "]";
73         }
74         return description;
75     }
76
77     public boolean equals(Object JavaDoc obj) {
78         if (this == obj)
79             return true;
80         if (!(obj instanceof DatasourceImpl))
81             return false;
82         
83         DatasourceImpl ds = (DatasourceImpl)obj;
84         if (jndiName == null && ds.getJndiName() != null || jndiName != null && !jndiName.equals(ds.getJndiName()))
85             return false;
86         if (url == null && ds.getUrl() != null || url != null && !url.equals(ds.getUrl()))
87             return false;
88         if (username == null && ds.getUsername() != null || username != null && !username.equals(ds.getUsername()))
89             return false;
90         if (password == null && ds.getPassword() != null || password != null && !password.equals(ds.getPassword()))
91             return false;
92         if (driverClassName == null && ds.getDriverClassName() != null || driverClassName != null && !driverClassName.equals(ds.getDriverClassName()))
93             return false;
94         
95         return true;
96     }
97     
98     public int hashCode() {
99         if (hash == -1) {
100             int result = 17;
101             result += 37 * result + (jndiName == null ? 0 : jndiName.hashCode());
102             result += 37 * result + (url == null ? 0 : url.hashCode());
103             result += 37 * result + (username == null ? 0 : username.hashCode());
104             result += 37 * result + (password == null ? 0 : password.hashCode());
105             result += 37 * result + (driverClassName == null ? 0 : driverClassName.hashCode());
106             
107             hash = result;
108         }
109         
110         return hash;
111     }
112     
113     public String JavaDoc toString() {
114         return "[ " + // NOI18N
115
NbBundle.getMessage(DatasourceImpl.class, "LBL_DS_JNDI") + ": '" + jndiName + "', " + // NOI18N
116
NbBundle.getMessage(DatasourceImpl.class, "LBL_DS_URL") + ": '" + url + "', " + // NOI18N
117
NbBundle.getMessage(DatasourceImpl.class, "LBL_DS_USER") + ": '" + username + "', " + // NOI18N
118
NbBundle.getMessage(DatasourceImpl.class, "LBL_DS_PASS") + ": '" + password + "', " + // NOI18N
119
NbBundle.getMessage(DatasourceImpl.class, "LBL_DS_DRV") + ": '" + driverClassName + " ]"; // NOI18N
120
}
121 }
122
Popular Tags