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: MessageTypes.java,v 1.5 2004/01/31 13:44:24 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.core; 46 47 import javax.jms.BytesMessage; 48 import javax.jms.MapMessage; 49 import javax.jms.Message; 50 import javax.jms.ObjectMessage; 51 import javax.jms.StreamMessage; 52 import javax.jms.TextMessage; 53 54 55 /*** 56 * Helper class used to indicate what JMS message types to run a particular 57 * test case against 58 * 59 * @version $Revision: 1.5 $ $Date: 2004/01/31 13:44:24 $ 60 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 61 * @see MessageTestCase 62 * @see MessageTestRunner 63 */ 64 public final class MessageTypes { 65 66 /*** 67 * The 'message' message type 68 */ 69 public static final MessageTypes MESSAGE; 70 71 /*** 72 * The bytes message type 73 */ 74 public static final MessageTypes BYTES; 75 76 /*** 77 * The map message type 78 */ 79 public static final MessageTypes MAP; 80 81 /*** 82 * The object message type 83 */ 84 public static final MessageTypes OBJECT; 85 86 /*** 87 * The stream message type 88 */ 89 public static final MessageTypes STREAM; 90 91 /*** 92 * The text message type 93 */ 94 public static final MessageTypes TEXT; 95 96 /*** 97 * All message types 98 */ 99 public static final MessageTypes ALL; 100 101 /*** 102 * The messages types to run the test case against 103 */ 104 private final Class[] _types; 105 106 /*** 107 * The available message types. 108 * NOTE: Message.class *must* be the last element in the list. 109 */ 110 private static final Class[] MESSAGE_TYPES = { 111 BytesMessage.class, MapMessage.class, ObjectMessage.class, 112 StreamMessage.class, TextMessage.class, Message.class}; 113 114 115 /*** 116 * Construct a new instance to test against a single message type 117 * 118 * @param type the JMS message type 119 */ 120 private MessageTypes(Class type) { 121 Class[] types = new Class[]{type}; 122 _types = types; 123 } 124 125 /*** 126 * Construct a new instance to test against a set of message types 127 * 128 * @param types a list of JMS message types 129 */ 130 private MessageTypes(Class[] types) { 131 _types = types; 132 } 133 134 /*** 135 * Return the list of message types to test against 136 * 137 * @return the list of message types to test against 138 */ 139 public Class[] getTypes() { 140 return _types; 141 } 142 143 /*** 144 * Helper to return the type that a particular message implements 145 * 146 * @param message the message 147 * @return the type of the message 148 */ 149 public static Class getType(Message message) { 150 Class result = null; 151 for (int i = 0; i < MESSAGE_TYPES.length; ++i) { 152 if (MESSAGE_TYPES[i].isAssignableFrom(message.getClass())) { 153 result = MESSAGE_TYPES[i]; 154 break; 155 } 156 } 157 return result; 158 } 159 160 /*** 161 * Helper to convert a message name to a <code>MessageTypes</code> 162 * instance 163 * 164 * @param name the message name 165 * @return a MessageTypes instance corresponding to <code>name</code>, 166 * or <code>null</code> if <code>name</code> is invalid 167 */ 168 public static MessageTypes fromString(String name) { 169 MessageTypes result = null; 170 if ("all".equalsIgnoreCase(name)) { 171 result = MessageTypes.ALL; 172 } else { 173 name = "javax.jms." + name; 174 for (int i = 0; i < MESSAGE_TYPES.length; ++i) { 175 if (MESSAGE_TYPES[i].getName().equals(name)) { 176 result = new MessageTypes(MESSAGE_TYPES[i]); 177 break; 178 } 179 } 180 } 181 return result; 182 } 183 184 /*** 185 * Helper to convert a set of type strings to a <code>MessageTypes</code> 186 * instance 187 * 188 * @param names the message names 189 * @return a MessageTypes instance corresponding to <code>names</code> 190 */ 191 public static MessageTypes fromString(String[] names) { 192 MessageTypes result = null; 193 Class[] types = new Class[names.length]; 194 for (int i = 0; i < names.length; ++i) { 195 if ("all".equalsIgnoreCase(names[i])) { 196 result = MessageTypes.ALL; 197 break; 198 } else { 199 String name = "javax.jms." + names[i]; 200 for (int j = 0; j < MESSAGE_TYPES.length; ++j) { 201 if (MESSAGE_TYPES[j].getName().equals(name)) { 202 types[i] = MESSAGE_TYPES[j]; 203 break; 204 } 205 } 206 if (types[i] == null) { 207 throw new IllegalArgumentException( 208 "Invalid message type: " + names[i]); 209 } 210 } 211 } 212 if (result == null) { 213 result = new MessageTypes(types); 214 } 215 return result; 216 } 217 218 /*** 219 * Return a count of the message types 220 * 221 * @return the number of message types 222 */ 223 public int count() { 224 return _types.length; 225 } 226 227 static { 228 MESSAGE = new MessageTypes(Message.class); 229 BYTES = new MessageTypes(BytesMessage.class); 230 MAP = new MessageTypes(MapMessage.class); 231 OBJECT = new MessageTypes(ObjectMessage.class); 232 STREAM = new MessageTypes(StreamMessage.class); 233 TEXT = new MessageTypes(TextMessage.class); 234 ALL = new MessageTypes(MESSAGE_TYPES); 235 } 236 237 } 238

This page was automatically generated by Maven