KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > resource > adapter > jms > JmsConnectionRequestInfo


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.resource.adapter.jms;
23
24 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
25
26 import javax.jms.Session JavaDoc;
27
28 import org.jboss.util.Strings;
29
30 /**
31  * Request information used in pooling
32  *
33  * @author <a HREF="mailto:peter.antman@tim.se">Peter Antman</a>.
34  * @author <a HREF="mailto:adrian@jboss.com">Adrian Brock</a>
35  * @version $Revision: 38315 $
36  */

37 public class JmsConnectionRequestInfo
38    implements ConnectionRequestInfo JavaDoc
39 {
40    private String JavaDoc userName;
41    private String JavaDoc password;
42    private String JavaDoc clientID;
43
44    private boolean transacted = true;
45    private int acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
46    private int type = JmsConnectionFactory.BOTH;
47
48    /**
49     * Creats with the MCF configured properties.
50     */

51    public JmsConnectionRequestInfo(JmsMCFProperties prop)
52    {
53       this.userName = prop.getUserName();
54       this.password = prop.getPassword();
55       this.clientID = prop.getClientID();
56       this.type = prop.getType();
57    }
58
59    /**
60     * Create with specified properties.
61     */

62    public JmsConnectionRequestInfo(final boolean transacted,
63                    final int acknowledgeMode,
64                    final int type)
65    {
66       this.transacted = transacted;
67       this.acknowledgeMode = acknowledgeMode;
68       this.type = type;
69    }
70    
71    /**
72     * Fill in default values if missing. Only applies to user and password.
73     */

74    public void setDefaults(JmsMCFProperties prop)
75    {
76       if (userName == null)
77          userName = prop.getUserName();//May be null there to
78
if (password == null)
79          password = prop.getPassword();//May be null there to
80
if (clientID == null)
81          clientID = prop.getClientID();//May be null there to
82
}
83
84    public String JavaDoc getUserName()
85    {
86       return userName;
87    }
88     
89    public void setUserName(String JavaDoc name)
90    {
91       userName = name;
92    }
93
94    public String JavaDoc getPassword()
95    {
96       return password;
97    }
98
99    public void setPassword(String JavaDoc password)
100    {
101       this.password = password;
102    }
103
104    public String JavaDoc getClientID()
105    {
106       return clientID;
107    }
108
109    public void setClientID(String JavaDoc clientID)
110    {
111       this.clientID = clientID;
112    }
113
114    public boolean isTransacted()
115    {
116       return transacted;
117    }
118     
119    public int getAcknowledgeMode()
120    {
121       return acknowledgeMode;
122    }
123
124    public int getType()
125    {
126       return type;
127    }
128
129    public boolean equals(Object JavaDoc obj)
130    {
131       if (obj == null) return false;
132       if (obj instanceof JmsConnectionRequestInfo)
133       {
134          JmsConnectionRequestInfo you = (JmsConnectionRequestInfo) obj;
135          return (this.transacted == you.isTransacted() &&
136             this.acknowledgeMode == you.getAcknowledgeMode() &&
137             this.type == you.getType() &&
138             Strings.compare(userName, you.getUserName()) &&
139             Strings.compare(password, you.getPassword()) &&
140             Strings.compare(clientID, you.getClientID()));
141       }
142       else
143          return false;
144    }
145  
146    public int hashCode()
147    {
148       int hashCode = 0;
149       if (transacted)
150          hashCode += 1;
151       if (type == JmsConnectionFactory.QUEUE)
152          hashCode += 3;
153       else if (type == JmsConnectionFactory.TOPIC)
154          hashCode += 5;
155       if (acknowledgeMode == Session.AUTO_ACKNOWLEDGE)
156          hashCode += 7;
157       else if (acknowledgeMode == Session.DUPS_OK_ACKNOWLEDGE)
158          hashCode += 11;
159       if (userName != null)
160          hashCode += userName.hashCode();
161       if (password != null)
162          hashCode += password.hashCode();
163       if (clientID != null)
164          hashCode += clientID.hashCode();
165       
166       return hashCode;
167    }
168 }
169
Popular Tags