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: AbstractMessageComparer.java,v 1.2 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 * A helper class for comparing messages. This class provides no comparison 57 * functionality, other than to verify that the supplied messages are of 58 * the same type and not the same instance. Comparison is left to subclasses. 59 * 60 * @version $Revision: 1.2 $ $Date: 2004/01/31 13:44:24 $ 61 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 62 */ 63 public class AbstractMessageComparer implements MessageComparer { 64 65 /*** 66 * Compare two messages. This method delegates the comparison to 67 * the appropriate method if the messages are of the same type, and not 68 * the same instance. 69 * 70 * @param message1 one message to be tested for equality 71 * @param message2 the other message to be tested for equality 72 * @return <code>true</code> if message1 and message2 are equal 73 * @throws Exception for any error 74 */ 75 public boolean compare(Message message1, Message message2) 76 throws Exception { 77 78 if (message1 == null) { 79 throw new IllegalArgumentException("Argument message1 is null"); 80 } 81 if (message2 == null) { 82 throw new IllegalArgumentException("Argument message2 is null"); 83 } 84 85 boolean equal = (message1 == message2); 86 if (!equal) { 87 Class type1 = MessageTypes.getType(message1); 88 Class type2 = MessageTypes.getType(message2); 89 if (type1 == BytesMessage.class && type2 == BytesMessage.class) { 90 equal = compareBytesMessages((BytesMessage) message1, 91 (BytesMessage) message2); 92 } else if (type1 == MapMessage.class 93 && type2 == MapMessage.class) { 94 equal = compareMapMessages((MapMessage) message1, 95 (MapMessage) message2); 96 } else if (type1 == ObjectMessage.class 97 && type2 == ObjectMessage.class) { 98 equal = compareObjectMessages((ObjectMessage) message1, 99 (ObjectMessage) message2); 100 } else if (type1 == StreamMessage.class 101 && type2 == StreamMessage.class) { 102 equal = compareStreamMessages((StreamMessage) message1, 103 (StreamMessage) message2); 104 } else if (type1 == TextMessage.class 105 && type2 == TextMessage.class) { 106 equal = compareTextMessages((TextMessage) message1, 107 (TextMessage) message2); 108 } else if (type1 == Message.class && type2 == Message.class) { 109 equal = compareMessages(message1, message2); 110 } 111 } 112 return equal; 113 } 114 115 /*** 116 * Compare two Message instances. This method does nothing - 117 * subclasses needing the functionality must implement it. 118 * 119 * @param message1 one message to be tested for equality 120 * @param message2 the other message to be tested for equality 121 * @return <code>false</code> if invoked 122 * @throws Exception for any error 123 */ 124 public boolean compareMessages(Message message1, Message message2) 125 throws Exception { 126 return false; 127 } 128 129 /*** 130 * Compare two BytesMessage instances. This method does nothing - 131 * subclasses needing the functionality must implement it. 132 * 133 * @param message1 one message to be tested for equality 134 * @param message2 the other message to be tested for equality 135 * @return <code>false</code> if invoked 136 * @throws Exception for any error 137 */ 138 public boolean compareBytesMessages(BytesMessage message1, 139 BytesMessage message2) 140 throws Exception { 141 return false; 142 } 143 144 /*** 145 * Compare two MapMessage instances. This method does nothing - 146 * subclasses needing the functionality must implement it. 147 * 148 * @param message1 one message to be tested for equality 149 * @param message2 the other message to be tested for equality 150 * @return <code>false</code> if invoked 151 * @throws Exception for any error 152 */ 153 public boolean compareMapMessages(MapMessage message1, 154 MapMessage message2) throws Exception { 155 return false; 156 } 157 158 /*** 159 * Compare two ObjectMessage instances. This method does nothing - 160 * subclasses needing the functionality must implement it. 161 * 162 * @param message1 one message to be tested for equality 163 * @param message2 the other message to be tested for equality 164 * @return <code>false</code> if invoked 165 * @throws Exception for any error 166 */ 167 public boolean compareObjectMessages(ObjectMessage message1, 168 ObjectMessage message2) 169 throws Exception { 170 return false; 171 } 172 173 /*** 174 * Compare two StreamMessage instances. This method does nothing - 175 * subclasses needing the functionality must implement it. 176 * 177 * @param message1 one message to be tested for equality 178 * @param message2 the other message to be tested for equality 179 * @return <code>false</code> if invoked 180 * @throws Exception for any error 181 */ 182 public boolean compareStreamMessages(StreamMessage message1, 183 StreamMessage message2) 184 throws Exception { 185 return false; 186 } 187 188 /*** 189 * Compare two TextMessage instances. This method does nothing - 190 * subclasses needing the functionality must implement it. 191 * 192 * @param message1 one message to be tested for equality 193 * @param message2 the other message to be tested for equality 194 * @return <code>false</code> if invoked 195 * @throws Exception for any error 196 */ 197 public boolean compareTextMessages(TextMessage message1, 198 TextMessage message2) throws Exception { 199 return false; 200 } 201 202 }

This page was automatically generated by Maven