001: package org.apache.ojb.broker;
002:
003: /* Copyright 2002-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: import java.io.Serializable;
019:
020: /**
021: * A immutable key to identify PB instances in pools, ...
022: * <br>
023: * The used <i>jcdAlias</i> name represents an alias for a connection
024: * defined in the repository file.
025: *
026: * @author Armin Waibel
027: * @version $Id: PBKey.java,v 1.11.2.3 2005/12/21 22:22:07 tomdz Exp $
028: */
029: public class PBKey implements Cloneable, Serializable {
030: private static final long serialVersionUID = -8858811398162391578L;
031: private final String jcdAlias;
032: private final String user;
033: private final String password;
034: private int hashCode;
035:
036: /**
037: * Creates a new PBKey.
038: *
039: * @param jcdAlias The jdbc connection descriptor name as defined in the repository file
040: * @param user The username
041: * @param password The password
042: */
043: public PBKey(final String jcdAlias, final String user,
044: final String password) {
045: this .jcdAlias = jcdAlias;
046: this .user = user;
047: this .password = password;
048: }
049:
050: /**
051: * Convenience constructor for <code>PBKey(jcdAlias, null, null)</code>.
052: *
053: * @param jcdAlias The jdbc connection descriptor name as defined in the repository file
054: */
055: public PBKey(final String jcdAlias) {
056: this (jcdAlias, null, null);
057: }
058:
059: /**
060: * {@inheritDoc}
061: */
062: public boolean equals(Object obj) {
063: if (obj == this ) {
064: return true;
065: }
066: if (!(obj instanceof PBKey)) {
067: return false;
068: }
069: PBKey other = (PBKey) obj;
070: return this .jcdAlias.equals(other.getAlias())
071: && (user != null ? user.equals(other.user)
072: : null == other.user)
073: && (password != null ? password.equals(other.password)
074: : null == other.password);
075: }
076:
077: /**
078: * {@inheritDoc}
079: */
080: protected Object clone() throws CloneNotSupportedException {
081: return new PBKey(this .jcdAlias, this .user, this .password);
082: }
083:
084: /**
085: * {@inheritDoc}
086: */
087: public int hashCode() {
088: if (hashCode == 0) {
089: hashCode = jcdAlias.hashCode()
090: + (user != null ? user.hashCode() : 0)
091: + (password != null ? password.hashCode() : 0);
092: }
093: return hashCode;
094: }
095:
096: /**
097: * {@inheritDoc}
098: */
099: public String toString() {
100: return this .getClass().getName()
101: + ": jcdAlias="
102: + jcdAlias
103: + ", user="
104: + user
105: + (user != null ? ", password=*****" : ", password="
106: + password);
107: }
108:
109: /**
110: * Returns the jdbc connection descriptor name as defined in the repository file.
111: *
112: * @return The JCD alias
113: */
114: public String getAlias() {
115: return jcdAlias;
116: }
117:
118: /**
119: * Returns the jdbc connection descriptor name as defined in the repository file.
120: *
121: * @return The JCD alias
122: * @deprecated use {@link #getAlias} instead.
123: */
124: public String getRepositoryFile() {
125: return jcdAlias;
126: }
127:
128: /**
129: * Returns the username.
130: *
131: * @return The username
132: */
133: public String getUser() {
134: return user;
135: }
136:
137: /**
138: * Returns the password.
139: *
140: * @return The password
141: */
142: public String getPassword() {
143: return password;
144: }
145: }
|