001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.resource.adapter.jms;
023:
024: import javax.resource.spi.ConnectionRequestInfo;
025:
026: import javax.jms.Session;
027:
028: import org.jboss.util.Strings;
029:
030: /**
031: * Request information used in pooling
032: *
033: * @author <a href="mailto:peter.antman@tim.se">Peter Antman</a>.
034: * @author <a href="mailto:adrian@jboss.com">Adrian Brock</a>
035: * @version $Revision: 57189 $
036: */
037: public class JmsConnectionRequestInfo implements ConnectionRequestInfo {
038: private String userName;
039: private String password;
040: private String clientID;
041:
042: private boolean transacted = true;
043: private int acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
044: private int type = JmsConnectionFactory.BOTH;
045:
046: /**
047: * Creats with the MCF configured properties.
048: */
049: public JmsConnectionRequestInfo(JmsMCFProperties prop) {
050: this .userName = prop.getUserName();
051: this .password = prop.getPassword();
052: this .clientID = prop.getClientID();
053: this .type = prop.getType();
054: }
055:
056: /**
057: * Create with specified properties.
058: */
059: public JmsConnectionRequestInfo(final boolean transacted,
060: final int acknowledgeMode, final int type) {
061: this .transacted = transacted;
062: this .acknowledgeMode = acknowledgeMode;
063: this .type = type;
064: }
065:
066: /**
067: * Fill in default values if missing. Only applies to user and password.
068: */
069: public void setDefaults(JmsMCFProperties prop) {
070: if (userName == null)
071: userName = prop.getUserName();//May be null there to
072: if (password == null)
073: password = prop.getPassword();//May be null there to
074: if (clientID == null)
075: clientID = prop.getClientID();//May be null there to
076: }
077:
078: public String getUserName() {
079: return userName;
080: }
081:
082: public void setUserName(String name) {
083: userName = name;
084: }
085:
086: public String getPassword() {
087: return password;
088: }
089:
090: public void setPassword(String password) {
091: this .password = password;
092: }
093:
094: public String getClientID() {
095: return clientID;
096: }
097:
098: public void setClientID(String clientID) {
099: this .clientID = clientID;
100: }
101:
102: public boolean isTransacted() {
103: return transacted;
104: }
105:
106: public int getAcknowledgeMode() {
107: return acknowledgeMode;
108: }
109:
110: public int getType() {
111: return type;
112: }
113:
114: public boolean equals(Object obj) {
115: if (obj == null)
116: return false;
117: if (obj instanceof JmsConnectionRequestInfo) {
118: JmsConnectionRequestInfo you = (JmsConnectionRequestInfo) obj;
119: return (this .transacted == you.isTransacted()
120: && this .acknowledgeMode == you.getAcknowledgeMode()
121: && this .type == you.getType()
122: && Strings.compare(userName, you.getUserName())
123: && Strings.compare(password, you.getPassword()) && Strings
124: .compare(clientID, you.getClientID()));
125: } else
126: return false;
127: }
128:
129: public int hashCode() {
130: int hashCode = 0;
131: if (transacted)
132: hashCode += 1;
133: if (type == JmsConnectionFactory.QUEUE)
134: hashCode += 3;
135: else if (type == JmsConnectionFactory.TOPIC)
136: hashCode += 5;
137: if (acknowledgeMode == Session.AUTO_ACKNOWLEDGE)
138: hashCode += 7;
139: else if (acknowledgeMode == Session.DUPS_OK_ACKNOWLEDGE)
140: hashCode += 11;
141: if (userName != null)
142: hashCode += userName.hashCode();
143: if (password != null)
144: hashCode += password.hashCode();
145: if (clientID != null)
146: hashCode += clientID.hashCode();
147:
148: return hashCode;
149: }
150: }
|