package org.jboss.resource.adapter.jms;
import javax.resource.spi.ConnectionRequestInfo;
import javax.jms.Session;
import org.jboss.util.Strings;
public class JmsConnectionRequestInfo
implements ConnectionRequestInfo
{
private String userName;
private String password;
private String clientID;
private boolean transacted = true;
private int acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
private int type = JmsConnectionFactory.BOTH;
public JmsConnectionRequestInfo(JmsMCFProperties prop)
{
this.userName = prop.getUserName();
this.password = prop.getPassword();
this.clientID = prop.getClientID();
this.type = prop.getType();
}
public JmsConnectionRequestInfo(final boolean transacted,
final int acknowledgeMode,
final int type)
{
this.transacted = transacted;
this.acknowledgeMode = acknowledgeMode;
this.type = type;
}
public void setDefaults(JmsMCFProperties prop)
{
if (userName == null)
userName = prop.getUserName(); if (password == null)
password = prop.getPassword(); if (clientID == null)
clientID = prop.getClientID(); }
public String getUserName()
{
return userName;
}
public void setUserName(String name)
{
userName = name;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getClientID()
{
return clientID;
}
public void setClientID(String clientID)
{
this.clientID = clientID;
}
public boolean isTransacted()
{
return transacted;
}
public int getAcknowledgeMode()
{
return acknowledgeMode;
}
public int getType()
{
return type;
}
public boolean equals(Object obj)
{
if (obj == null) return false;
if (obj instanceof JmsConnectionRequestInfo)
{
JmsConnectionRequestInfo you = (JmsConnectionRequestInfo) obj;
return (this.transacted == you.isTransacted() &&
this.acknowledgeMode == you.getAcknowledgeMode() &&
this.type == you.getType() &&
Strings.compare(userName, you.getUserName()) &&
Strings.compare(password, you.getPassword()) &&
Strings.compare(clientID, you.getClientID()));
}
else
return false;
}
public int hashCode()
{
int hashCode = 0;
if (transacted)
hashCode += 1;
if (type == JmsConnectionFactory.QUEUE)
hashCode += 3;
else if (type == JmsConnectionFactory.TOPIC)
hashCode += 5;
if (acknowledgeMode == Session.AUTO_ACKNOWLEDGE)
hashCode += 7;
else if (acknowledgeMode == Session.DUPS_OK_ACKNOWLEDGE)
hashCode += 11;
if (userName != null)
hashCode += userName.hashCode();
if (password != null)
hashCode += password.hashCode();
if (clientID != null)
hashCode += clientID.hashCode();
return hashCode;
}
}