View Javadoc
1 /*** 2 * Redistribution and use of this software and associated documentation 3 * ("Software"), with or without modification, are permitted provided 4 * that the following conditions are met: 5 * 6 * 1. Redistributions of source code must retain copyright 7 * statements and notices. Redistributions must also contain a 8 * copy of this document. 9 * 10 * 2. Redistributions in binary form must reproduce the 11 * above copyright notice, this list of conditions and the 12 * following disclaimer in the documentation and/or other 13 * materials provided with the distribution. 14 * 15 * 3. The name "Exolab" must not be used to endorse or promote 16 * products derived from this Software without prior written 17 * permission of Exoffice Technologies. For written permission, 18 * please contact tma@netspace.net.au. 19 * 20 * 4. Products derived from this Software may not be called "Exolab" 21 * nor may "Exolab" appear in their names without prior written 22 * permission of Exoffice Technologies. Exolab is a registered 23 * trademark of Exoffice Technologies. 24 * 25 * 5. Due credit should be given to the Exolab Project 26 * (http://www.exolab.org/). 27 * 28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 39 * OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Copyright 2001-2004 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * $Id: ConnectionFactoryTypes.java,v 1.4 2004/01/31 13:44:24 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.core; 46 47 import javax.jms.ConnectionFactory; 48 import javax.jms.QueueConnectionFactory; 49 import javax.jms.TopicConnectionFactory; 50 import javax.jms.XAQueueConnectionFactory; 51 import javax.jms.XATopicConnectionFactory; 52 53 54 /*** 55 * Helper class used to indicate what JMS connection factory types to run a 56 * particular test case against 57 * 58 * @version $Revision: 1.4 $ $Date: 2004/01/31 13:44:24 $ 59 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 60 * @see ConnectionFactoryTestCase 61 * @see ProviderTestRunner 62 */ 63 public final class ConnectionFactoryTypes { 64 65 /*** 66 * Queue connection factory 67 */ 68 public static final ConnectionFactoryTypes QUEUE; 69 70 /*** 71 * Topic connection factory 72 */ 73 public static final ConnectionFactoryTypes TOPIC; 74 75 /*** 76 * XA queue connection factory 77 */ 78 public static final ConnectionFactoryTypes XAQUEUE; 79 80 /*** 81 * XA topic connection factory 82 */ 83 public static final ConnectionFactoryTypes XATOPIC; 84 85 /*** 86 * All queue connection factory types 87 */ 88 public static final ConnectionFactoryTypes ALL_QUEUE; 89 90 /*** 91 * All topic connection factory types 92 */ 93 public static final ConnectionFactoryTypes ALL_TOPIC; 94 95 /*** 96 * All connection factory types 97 */ 98 public static final ConnectionFactoryTypes ALL; 99 100 101 /*** 102 * The available connection factory types. 103 */ 104 public static final Class[] TYPES = { 105 QueueConnectionFactory.class, TopicConnectionFactory.class, 106 XAQueueConnectionFactory.class, XATopicConnectionFactory.class}; 107 108 /*** 109 * The connection factory types to run the test case against 110 */ 111 private final Class[] _types; 112 113 /*** 114 * Construct a new instance to test against a single factory type 115 * 116 * @param type the connection factory type 117 */ 118 private ConnectionFactoryTypes(Class type) { 119 this(new Class[]{type}); 120 } 121 122 /*** 123 * Construct a new instance to test against a set of factory types 124 * 125 * @param types a list of connection factory types 126 */ 127 private ConnectionFactoryTypes(Class[] types) { 128 _types = types; 129 } 130 131 /*** 132 * Return the list of connection factory types to test against 133 * 134 * @return the list of connection factory types to test against 135 */ 136 public Class[] getTypes() { 137 return _types; 138 } 139 140 /*** 141 * Returns a stringified version of this, for debugging purposes 142 * 143 * @return a stringified version of this 144 */ 145 public String toString() { 146 StringBuffer result = new StringBuffer(); 147 for (int i = 0; i < _types.length; ++i) { 148 if (i > 0) { 149 result.append(","); 150 } 151 result.append(_types[i].getName()); 152 } 153 return result.toString(); 154 } 155 156 /*** 157 * Return a count of the connection factory types 158 * 159 * @return the number of connection factory types 160 */ 161 public int count() { 162 return _types.length; 163 } 164 165 /*** 166 * Helper to return the type that a particular factory implements 167 * 168 * @param factory the connection factory 169 * @return the type of the factory 170 */ 171 public static Class getType(ConnectionFactory factory) { 172 Class result = null; 173 for (int i = 0; i < TYPES.length; ++i) { 174 if (TYPES[i].isAssignableFrom(factory.getClass())) { 175 result = TYPES[i]; 176 break; 177 } 178 } 179 return result; 180 } 181 182 /*** 183 * Helper to convert a factory name to a 184 * <code>ConnectionFactoryTypes</code> instance 185 * 186 * @param name the factory name 187 * @return an instance corresponding to <code>name</code>, 188 * or <code>null</code> if <code>name</code> is invalid 189 */ 190 public static ConnectionFactoryTypes fromString(String name) { 191 ConnectionFactoryTypes result = null; 192 if ("all".equalsIgnoreCase(name)) { 193 result = ConnectionFactoryTypes.ALL; 194 } else { 195 name = "javax.jms." + name; 196 Class[] types = ALL.getTypes(); 197 for (int i = 0; i < types.length; ++i) { 198 if (types[i].getName().equals(name)) { 199 result = new ConnectionFactoryTypes(types[i]); 200 break; 201 } 202 } 203 } 204 return result; 205 } 206 207 /*** 208 * Helper to convert a set of factory names to a 209 * <code>ConnectionFactoryTypes</code> instance 210 * 211 * @param names the factory names 212 * @return an instance corresponding to <code>names</code>, 213 * or <code>null</code> if <code>names</code> is invalid 214 */ 215 public static ConnectionFactoryTypes fromString(String[] names) { 216 ConnectionFactoryTypes result = null; 217 Class[] classes = new Class[names.length]; 218 for (int i = 0; i < names.length; ++i) { 219 if ("all".equalsIgnoreCase(names[i])) { 220 result = ALL; 221 break; 222 } else { 223 Class[] types = ALL.getTypes(); 224 String name = "javax.jms." + names[i]; 225 for (int j = 0; j < types.length; ++j) { 226 if (types[j].getName().equals(name)) { 227 classes[i] = types[j]; 228 break; 229 } 230 } 231 if (classes[i] == null) { 232 throw new IllegalArgumentException( 233 "Invalid factory: " + names[i]); 234 } 235 } 236 } 237 if (result == null) { 238 result = new ConnectionFactoryTypes(classes); 239 } 240 return result; 241 } 242 243 static { 244 QUEUE = new ConnectionFactoryTypes(new Class[]{ 245 QueueConnectionFactory.class}); 246 TOPIC = new ConnectionFactoryTypes(new Class[]{ 247 TopicConnectionFactory.class}); 248 XAQUEUE = new ConnectionFactoryTypes(new Class[]{ 249 XAQueueConnectionFactory.class}); 250 XATOPIC = new ConnectionFactoryTypes(new Class[]{ 251 XATopicConnectionFactory.class}); 252 253 ALL_QUEUE = new ConnectionFactoryTypes(new Class[]{ 254 QueueConnectionFactory.class, XAQueueConnectionFactory.class}); 255 ALL_TOPIC = new ConnectionFactoryTypes(new Class[]{ 256 TopicConnectionFactory.class, XATopicConnectionFactory.class}); 257 258 ALL = new ConnectionFactoryTypes(new Class[]{ 259 QueueConnectionFactory.class, TopicConnectionFactory.class, 260 XAQueueConnectionFactory.class, XATopicConnectionFactory.class}); 261 } 262 263 }

This page was automatically generated by Maven