KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > jboss4 > config > JBossDatasource


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.jboss4.config;
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 JBossDatasource 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 minPoolSize = "5"; // NOI18N
38
private String JavaDoc maxPoolSize = "20"; // NOI18N
39
private String JavaDoc idleTimeoutMinutes = "5"; // NOI18N
40
private String JavaDoc description;
41     
42     private volatile int hash = -1;
43     
44     public JBossDatasource(String JavaDoc jndiName, String JavaDoc url, String JavaDoc username, String JavaDoc password, String JavaDoc driverClassName) {
45         this.jndiName = jndiName;
46         this.url = url;
47         this.username = username;
48         this.password = password;
49         this.driverClassName = driverClassName;
50     }
51
52     public String JavaDoc getJndiName() {
53         return jndiName;
54     }
55
56     public String JavaDoc getUrl() {
57         return url;
58     }
59
60     public String JavaDoc getUsername() {
61         return username;
62     }
63
64     public String JavaDoc getPassword() {
65         return password;
66     }
67
68     public String JavaDoc getDriverClassName() {
69         return driverClassName;
70     }
71
72     public String JavaDoc getMinPoolSize() {
73         return minPoolSize;
74     }
75
76     public String JavaDoc getMaxPoolSize() {
77         return maxPoolSize;
78     }
79
80     public String JavaDoc getIdleTimeoutMinutes() {
81         return idleTimeoutMinutes;
82     }
83     
84     public String JavaDoc getDisplayName() {
85         if (description == null) {
86             //TODO implement some meaningful description
87
description = getJndiName() + " [" + getUrl() + "]";
88         }
89         return description;
90     }
91
92     public boolean equals(Object JavaDoc obj) {
93         if (this == obj)
94             return true;
95         if (!(obj instanceof JBossDatasource))
96             return false;
97         
98         JBossDatasource ds = (JBossDatasource)obj;
99         if (jndiName == null && ds.getJndiName() != null || jndiName != null && !jndiName.equals(ds.getJndiName()))
100             return false;
101         if (url == null && ds.getUrl() != null || url != null && !url.equals(ds.getUrl()))
102             return false;
103         if (username == null && ds.getUsername() != null || username != null && !username.equals(ds.getUsername()))
104             return false;
105         if (password == null && ds.getPassword() != null || password != null && !password.equals(ds.getPassword()))
106             return false;
107         if (driverClassName == null && ds.getDriverClassName() != null || driverClassName != null && !driverClassName.equals(ds.getDriverClassName()))
108             return false;
109         if (minPoolSize == null && ds.getMinPoolSize() != null || minPoolSize != null && !minPoolSize.equals(ds.getMinPoolSize()))
110             return false;
111         if (maxPoolSize == null && ds.getMaxPoolSize() != null || maxPoolSize != null && !maxPoolSize.equals(ds.getMaxPoolSize()))
112             return false;
113         if (idleTimeoutMinutes == null && ds.getIdleTimeoutMinutes() != null || idleTimeoutMinutes != null && !idleTimeoutMinutes.equals(ds.getIdleTimeoutMinutes()))
114             return false;
115         
116         return true;
117     }
118     
119     public int hashCode() {
120         if (hash == -1) {
121             int result = 17;
122             result += 37 * result + (jndiName == null ? 0 : jndiName.hashCode());
123             result += 37 * result + (url == null ? 0 : url.hashCode());
124             result += 37 * result + (username == null ? 0 : username.hashCode());
125             result += 37 * result + (password == null ? 0 : password.hashCode());
126             result += 37 * result + (driverClassName == null ? 0 : driverClassName.hashCode());
127             result += 37 * result + (minPoolSize == null ? 0 : minPoolSize.hashCode());
128             result += 37 * result + (maxPoolSize == null ? 0 : maxPoolSize.hashCode());
129             result += 37 * result + (idleTimeoutMinutes == null ? 0 : idleTimeoutMinutes.hashCode());
130             
131             hash = result;
132         }
133         
134         return hash;
135     }
136     
137     public String JavaDoc toString() {
138         return "[ " + // NOI18N
139
NbBundle.getMessage(JBossDatasource.class, "LBL_DS_JNDI") + ": '" + jndiName + "', " + // NOI18N
140
NbBundle.getMessage(JBossDatasource.class, "LBL_DS_URL") + ": '" + url + "', " + // NOI18N
141
NbBundle.getMessage(JBossDatasource.class, "LBL_DS_USER") + ": '" + username + "', " + // NOI18N
142
NbBundle.getMessage(JBossDatasource.class, "LBL_DS_PASS") + ": '" + password + "', " + // NOI18N
143
NbBundle.getMessage(JBossDatasource.class, "LBL_DS_DRV") + ": '" + driverClassName + "', " + // NOI18N
144
NbBundle.getMessage(JBossDatasource.class, "LBL_DS_MINPS") + ": '" + minPoolSize + "', " + // NOI18N
145
NbBundle.getMessage(JBossDatasource.class, "LBL_DS_MAXPS") + ": '" + maxPoolSize + "', " + // NOI18N
146
NbBundle.getMessage(JBossDatasource.class, "LBL_DS_IDLE") + ": '" + idleTimeoutMinutes + "' ]"; // NOI18N
147
}
148 }
149
Popular Tags