1 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 30 public final class DatasourceImpl implements Datasource { 31 32 private String jndiName; 33 private String url; 34 private String username; 35 private String password; 36 private String driverClassName; 37 private String description; 38 39 private volatile int hash = -1; 40 41 public DatasourceImpl(String jndiName, String url, String username, String password, String 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 getJndiName() { 50 return jndiName; 51 } 52 53 public String getUrl() { 54 return url; 55 } 56 57 public String getUsername() { 58 return username; 59 } 60 61 public String getPassword() { 62 return password; 63 } 64 65 public String getDriverClassName() { 66 return driverClassName; 67 } 68 69 public String getDisplayName() { 70 if (description == null) { 71 description = getJndiName() + " [" + getUrl() + "]"; 73 } 74 return description; 75 } 76 77 public boolean equals(Object 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 toString() { 114 return "[ " + NbBundle.getMessage(DatasourceImpl.class, "LBL_DS_JNDI") + ": '" + jndiName + "', " + NbBundle.getMessage(DatasourceImpl.class, "LBL_DS_URL") + ": '" + url + "', " + NbBundle.getMessage(DatasourceImpl.class, "LBL_DS_USER") + ": '" + username + "', " + NbBundle.getMessage(DatasourceImpl.class, "LBL_DS_PASS") + ": '" + password + "', " + NbBundle.getMessage(DatasourceImpl.class, "LBL_DS_DRV") + ": '" + driverClassName + " ]"; } 121 } 122 | Popular Tags |