KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > oc4j > config > OC4JDatasource


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

29 public class OC4JDatasource implements Datasource {
30     
31     private String JavaDoc jndiName;
32     private String JavaDoc url;
33     private String JavaDoc username;
34     private String JavaDoc password;
35     private String JavaDoc driverClassName;
36     private String JavaDoc minPoolSize = "5"; // NOI18N
37
private String JavaDoc maxPoolSize = "20"; // NOI18N
38
private String JavaDoc idleTimeoutMinutes = "5"; // NOI18N
39
private String JavaDoc description;
40     
41     private volatile int hash = -1;
42     
43     /** Creates a new instance of OC4JDatasource */
44     public OC4JDatasource(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             description = getJndiName() + " [" + getUrl() + "]";
87         }
88         return description;
89     }
90     
91     public boolean equals(Object JavaDoc obj) {
92         if (this == obj)
93             return true;
94         if (!(obj instanceof OC4JDatasource))
95             return false;
96         
97         OC4JDatasource ds = (OC4JDatasource) obj;
98         if (jndiName == null && ds.getJndiName() != null || jndiName != null && !jndiName.equals(ds.getJndiName()))
99             return false;
100         if (url == null && ds.getUrl() != null || url != null && !url.equals(ds.getUrl()))
101             return false;
102         if (username == null && ds.getUsername() != null || username != null && !username.equals(ds.getUsername()))
103             return false;
104         if (password == null && ds.getPassword() != null || password != null && !password.equals(ds.getPassword()))
105             return false;
106         if (driverClassName == null && ds.getDriverClassName() != null || driverClassName != null && !driverClassName.equals(ds.getDriverClassName()))
107             return false;
108         if (minPoolSize == null && ds.getMinPoolSize() != null || minPoolSize != null && !minPoolSize.equals(ds.getMinPoolSize()))
109             return false;
110         if (maxPoolSize == null && ds.getMaxPoolSize() != null || maxPoolSize != null && !maxPoolSize.equals(ds.getMaxPoolSize()))
111             return false;
112         if (idleTimeoutMinutes == null && ds.getIdleTimeoutMinutes() != null || idleTimeoutMinutes != null && !idleTimeoutMinutes.equals(ds.getIdleTimeoutMinutes()))
113             return false;
114         
115         return true;
116     }
117     
118     public int hashCode() {
119         if (hash == -1) {
120             int result = 17;
121             result += 37 * result + (jndiName == null ? 0 : jndiName.hashCode());
122             result += 37 * result + (url == null ? 0 : url.hashCode());
123             result += 37 * result + (username == null ? 0 : username.hashCode());
124             result += 37 * result + (password == null ? 0 : password.hashCode());
125             result += 37 * result + (driverClassName == null ? 0 : driverClassName.hashCode());
126             result += 37 * result + (minPoolSize == null ? 0 : minPoolSize.hashCode());
127             result += 37 * result + (maxPoolSize == null ? 0 : maxPoolSize.hashCode());
128             result += 37 * result + (idleTimeoutMinutes == null ? 0 : idleTimeoutMinutes.hashCode());
129             
130             hash = result;
131         }
132         
133         return hash;
134     }
135     
136     public String JavaDoc toString() {
137         return "[ " + // NOI18N
138
NbBundle.getMessage(OC4JDatasource.class, "LBL_DS_JNDI") + ": '" + jndiName + "', " + // NOI18N
139
NbBundle.getMessage(OC4JDatasource.class, "LBL_DS_URL") + ": '" + url + "', " + // NOI18N
140
NbBundle.getMessage(OC4JDatasource.class, "LBL_DS_USER") + ": '" + username + "', " + // NOI18N
141
NbBundle.getMessage(OC4JDatasource.class, "LBL_DS_PASS") + ": '" + password + "', " + // NOI18N
142
NbBundle.getMessage(OC4JDatasource.class, "LBL_DS_DRV") + ": '" + driverClassName + "', " + // NOI18N
143
NbBundle.getMessage(OC4JDatasource.class, "LBL_DS_MINPS") + ": '" + minPoolSize + "', " + // NOI18N
144
NbBundle.getMessage(OC4JDatasource.class, "LBL_DS_MAXPS") + ": '" + maxPoolSize + "', " + // NOI18N
145
NbBundle.getMessage(OC4JDatasource.class, "LBL_DS_IDLE") + ": '" + idleTimeoutMinutes + "' ]"; // NOI18N
146
}
147 }
Popular Tags