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.jms.Queue;
025: import javax.jms.Topic;
026: import javax.resource.ResourceException;
027:
028: import org.jboss.util.Strings;
029:
030: /**
031: * The MCF default properties, settable in ra.xml or in deployer.
032: *
033: * @author Peter Antman
034: * @author <a href="mailto:adrian@jboss.com">Adrian Brock</a>
035: * @version $Revision: 57189 $
036: */
037: public class JmsMCFProperties implements java.io.Serializable {
038: static final long serialVersionUID = -7997396849692340121L;
039:
040: public static final String QUEUE_TYPE = Queue.class.getName();
041: public static final String TOPIC_TYPE = Topic.class.getName();
042:
043: String userName;
044: String password;
045: String clientID;
046: String providerJNDI = "java:DefaultJMSProvider";
047: int type = JmsConnectionFactory.BOTH;
048:
049: public JmsMCFProperties() {
050: // empty
051: }
052:
053: /**
054: * Set userName, null by default.
055: */
056: public void setUserName(final String userName) {
057: this .userName = userName;
058: }
059:
060: /**
061: * Get userName, may be null.
062: */
063: public String getUserName() {
064: return userName;
065: }
066:
067: /**
068: * Set password, null by default.
069: */
070: public void setPassword(final String password) {
071: this .password = password;
072: }
073:
074: /**
075: * Get password, may be null.
076: */
077: public String getPassword() {
078: return password;
079: }
080:
081: /**
082: * Get client id, may be null.
083: */
084: public String getClientID() {
085: return clientID;
086: }
087:
088: /**
089: * Set client id, null by default.
090: */
091: public void setClientID(final String clientID) {
092: this .clientID = clientID;
093: }
094:
095: /**
096: * Set providerJNDI, the JMS provider adapter to use.
097: *
098: * <p>Defaults to java:DefaultJMSProvider.
099: */
100: public void setProviderJNDI(final String providerJNDI) {
101: this .providerJNDI = providerJNDI;
102: }
103:
104: /**
105: * Get providerJNDI. May not be null.
106: */
107: public String getProviderJNDI() {
108: return providerJNDI;
109: }
110:
111: /**
112: * Type of the JMS Session.
113: */
114: public int getType() {
115: return type;
116: }
117:
118: /**
119: * Set the default session type.
120: */
121: public void setType(int type) {
122: this .type = type;
123: }
124:
125: /**
126: * Helper method to set the default session type.
127: *
128: * @param type either javax.jms.Topic or javax.jms.Queue
129: * @exception ResourceException if type was not a valid type.
130: */
131: public void setSessionDefaultType(String type)
132: throws ResourceException {
133: if (type.equals(QUEUE_TYPE))
134: this .type = JmsConnectionFactory.QUEUE;
135: else if (type.equals(TOPIC_TYPE))
136: this .type = JmsConnectionFactory.TOPIC;
137: else
138: this .type = JmsConnectionFactory.BOTH;
139: }
140:
141: public String getSessionDefaultType() {
142: if (type == JmsConnectionFactory.BOTH)
143: return "both";
144: else if (type == JmsConnectionFactory.QUEUE)
145: return TOPIC_TYPE;
146: else
147: return QUEUE_TYPE;
148: }
149:
150: /**
151: * Test for equality of all attributes.
152: */
153: public boolean equals(Object obj) {
154: if (obj == null)
155: return false;
156:
157: if (obj instanceof JmsMCFProperties) {
158: JmsMCFProperties you = (JmsMCFProperties) obj;
159: return (Strings.compare(userName, you.getUserName())
160: && Strings.compare(password, you.getPassword())
161: && Strings.compare(providerJNDI, you
162: .getProviderJNDI()) && this .type == you.type);
163: }
164:
165: return false;
166: }
167:
168: /**
169: * Simple hashCode of all attributes.
170: */
171: public int hashCode() {
172: // FIXME
173: String result = "" + userName + password + providerJNDI + type;
174: return result.hashCode();
175: }
176: }
|