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: MessagePropertyComparer.java,v 1.3 2004/01/31 13:44:24 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.core; 46 47 import java.util.Enumeration; 48 import java.util.HashMap; 49 50 import javax.jms.Message; 51 52 53 /*** 54 * A helper class for comparing the properties of two messages. 55 * 56 * @version $Revision: 1.3 $ $Date: 2004/01/31 13:44:24 $ 57 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 58 */ 59 public class MessagePropertyComparer implements MessageComparer { 60 61 /*** 62 * If true, indicates that messages may contain provider specific 63 * properties. 64 * Note that this does not include JMSXGroupID or JMSXGroupSeq properties, 65 * which may only be set by the client 66 */ 67 private final boolean _provider; 68 69 /*** 70 * Construct a new instance 71 * 72 * @param provider if true, either message may contain provider properties 73 * i.e those prefixed with JMSX or JMS_. These will be ignored. 74 * <br> 75 * Note that this does not include JMSXGroupID or JMSXGroupSeq properties, 76 * which may only be set by the client 77 */ 78 public MessagePropertyComparer(boolean provider) { 79 _provider = provider; 80 } 81 82 /*** 83 * Compare two message's properties 84 * 85 * @param message1 one message to be tested for equality 86 * @param message2 the other message to be tested for equality 87 * @return <code>true</code> if message1 and message2 are equal 88 * @throws Exception for any error 89 */ 90 public boolean compare(Message message1, Message message2) 91 throws Exception { 92 int count1 = 0; // maintains a count of the elements in each message 93 int count2 = 0; // in the unlikely event than a provider allows 94 // duplicate map names 95 HashMap map1 = new HashMap(); 96 HashMap map2 = new HashMap(); 97 Enumeration iter1 = message1.getPropertyNames(); 98 Enumeration iter2 = message2.getPropertyNames(); 99 while (iter1.hasMoreElements()) { 100 String name = (String) iter1.nextElement(); 101 if (!ignore(name)) { 102 map1.put(name, message1.getObjectProperty(name)); 103 ++count1; 104 } 105 } 106 while (iter2.hasMoreElements()) { 107 String name = (String) iter2.nextElement(); 108 if (!ignore(name)) { 109 map2.put(name, message2.getObjectProperty(name)); 110 ++count2; 111 } 112 } 113 return (count1 == count2) ? map1.equals(map2) : false; 114 } 115 116 /*** 117 * Determines if a property should be ignored 118 * 119 * @param name the name of the property 120 * @return <code>true</code> if the property should be ignored 121 */ 122 private boolean ignore(String name) { 123 boolean result = false; 124 if (_provider) { 125 if ((name.startsWith("JMSX") && !(name.equals("JMSXGroupID") 126 || name.equals("JMSXGroupSeq"))) 127 || name.startsWith("JMS_")) { 128 result = true; 129 } 130 } 131 return result; 132 } 133 134 }

This page was automatically generated by Maven