KickJava   Java API By Example, From Geeks To Geeks.

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


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.jms.Queue JavaDoc;
25 import javax.jms.Topic JavaDoc;
26 import javax.resource.ResourceException JavaDoc;
27
28 import org.jboss.util.Strings;
29
30 /**
31  * The MCF default properties, settable in ra.xml or in deployer.
32  *
33  * @author Peter Antman
34  * @author <a HREF="mailto:adrian@jboss.com">Adrian Brock</a>
35  * @version $Revision: 38315 $
36  */

37 public class JmsMCFProperties
38    implements java.io.Serializable JavaDoc
39 {
40    static final long serialVersionUID = -7997396849692340121L;
41
42    public static final String JavaDoc QUEUE_TYPE = Queue JavaDoc.class.getName();
43    public static final String JavaDoc TOPIC_TYPE = Topic JavaDoc.class.getName();
44
45    String JavaDoc userName;
46    String JavaDoc password;
47    String JavaDoc clientID;
48    String JavaDoc providerJNDI = "java:DefaultJMSProvider";
49    int type = JmsConnectionFactory.BOTH;
50    
51    public JmsMCFProperties()
52    {
53       // empty
54
}
55    
56    /**
57     * Set userName, null by default.
58     */

59    public void setUserName(final String JavaDoc userName)
60    {
61       this.userName = userName;
62    }
63
64    /**
65     * Get userName, may be null.
66     */

67    public String JavaDoc getUserName()
68    {
69       return userName;
70    }
71    
72    /**
73     * Set password, null by default.
74     */

75    public void setPassword(final String JavaDoc password)
76    {
77       this.password = password;
78    }
79    
80    /**
81     * Get password, may be null.
82     */

83    public String JavaDoc getPassword()
84    {
85       return password;
86    }
87    
88    /**
89     * Get client id, may be null.
90     */

91    public String JavaDoc getClientID()
92    {
93       return clientID;
94    }
95    
96    /**
97     * Set client id, null by default.
98     */

99    public void setClientID(final String JavaDoc clientID)
100    {
101       this.clientID = clientID;
102    }
103
104    /**
105     * Set providerJNDI, the JMS provider adapter to use.
106     *
107     * <p>Defaults to java:DefaultJMSProvider.
108     */

109    public void setProviderJNDI(final String JavaDoc providerJNDI)
110    {
111       this.providerJNDI = providerJNDI;
112    }
113
114    /**
115     * Get providerJNDI. May not be null.
116     */

117    public String JavaDoc getProviderJNDI()
118    {
119       return providerJNDI;
120    }
121
122    /**
123     * Type of the JMS Session.
124     */

125    public int getType()
126    {
127       return type;
128    }
129
130    /**
131     * Set the default session type.
132     */

133    public void setType(int type)
134    {
135       this.type = type;
136    }
137
138    /**
139     * Helper method to set the default session type.
140     *
141     * @param type either javax.jms.Topic or javax.jms.Queue
142     * @exception ResourceException if type was not a valid type.
143     */

144    public void setSessionDefaultType(String JavaDoc type) throws ResourceException JavaDoc
145    {
146       if (type.equals(QUEUE_TYPE))
147          this.type = JmsConnectionFactory.QUEUE;
148       else if(type.equals(TOPIC_TYPE))
149          this.type = JmsConnectionFactory.TOPIC;
150       else
151          this.type = JmsConnectionFactory.BOTH;
152    }
153
154    public String JavaDoc getSessionDefaultType()
155    {
156       if (type == JmsConnectionFactory.BOTH)
157          return "both";
158       else if (type == JmsConnectionFactory.QUEUE)
159          return TOPIC_TYPE;
160       else
161          return QUEUE_TYPE;
162    }
163
164    /**
165     * Test for equality of all attributes.
166     */

167    public boolean equals(Object JavaDoc obj)
168    {
169       if (obj == null) return false;
170       
171       if (obj instanceof JmsMCFProperties)
172       {
173          JmsMCFProperties you = (JmsMCFProperties) obj;
174          return (Strings.compare(userName, you.getUserName()) &&
175                  Strings.compare(password, you.getPassword()) &&
176                  Strings.compare(providerJNDI, you.getProviderJNDI()) &&
177                  this.type == you.type);
178       }
179       
180       return false;
181    }
182  
183    /**
184     * Simple hashCode of all attributes.
185     */

186    public int hashCode()
187    {
188       // FIXME
189
String JavaDoc result = "" + userName + password + providerJNDI + type;
190       return result.hashCode();
191    }
192 }
193
Popular Tags