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: DeliveryType.java,v 1.5 2004/01/31 13:44:24 tanderson Exp $ 44 */ 45 package org.exolab.jmscts.core; 46 47 import java.util.StringTokenizer; 48 49 import javax.jms.DeliveryMode; 50 51 52 /*** 53 * Helper class used to indicate what delivery, destination type and message 54 * receipt mode should be used to run a particular test case against 55 * 56 * @version $Revision: 1.5 $ $Date: 2004/01/31 13:44:24 $ 57 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a> 58 * @see DeliveryTypes 59 * @see SendReceiveTestCase 60 * @see SendReceiveTestRunner 61 */ 62 public class DeliveryType { 63 64 /*** 65 * The delivery mode. This is either DeliveryMode.PERSISTENT 66 * or DeliveryMode.NON_PERSISTENT 67 */ 68 private final int _deliveryMode; 69 70 /*** 71 * If true, destinations are administered, else they are temporary. 72 */ 73 private final boolean _administered; 74 75 /*** 76 * The type of message receipt to use 77 */ 78 private final ReceiptType _receipt; 79 80 81 /*** 82 * Create a new instance 83 * 84 * @param persistent if true, messages are to be sent using 85 * DeliveryMode.PERSISTENT delivery, else DeliveryMode.NON_PERSISTENT is 86 * used. 87 * @param administered if true, destinations are to be administered, else 88 * they are temporary 89 */ 90 public DeliveryType(boolean persistent, boolean administered) { 91 this(persistent, administered, null); 92 } 93 94 /*** 95 * Create a new instance 96 * 97 * @param persistent if true, messages are to be sent using 98 * DeliveryMode.PERSISTENT delivery, else DeliveryMode.NON_PERSISTENT is 99 * used. 100 * @param administered if true, destinations are to be administered, else 101 * they are temporary 102 * @param receipt the type of message receipt type. 103 * May be <code>null</code> 104 */ 105 public DeliveryType(boolean persistent, boolean administered, 106 ReceiptType receipt) { 107 _deliveryMode = (persistent) ? DeliveryMode.PERSISTENT 108 : DeliveryMode.NON_PERSISTENT; 109 _administered = administered; 110 _receipt = receipt; 111 } 112 113 /*** 114 * Returns the delivery mode. This is either 115 * <code>DeliveryMode.PERSISTENT</code> or 116 * <code>DeliveryMode.NON_PERSISTENT</code> 117 * 118 * @return the delivery mode 119 */ 120 public int getDeliveryMode() { 121 return _deliveryMode; 122 } 123 124 /*** 125 * DeReturns true if destinations are administered, false if destinations 126 * are temporary. 127 * 128 * @return <code>true</code> if destinations are administered, 129 * <code>false</code> otherwise 130 */ 131 public boolean getAdministered() { 132 return _administered; 133 } 134 135 /*** 136 * Returns the type of message receipt to be used 137 * 138 * @return the message receipt type, or <code>null</code> if no receipt 139 * type is specified 140 */ 141 public ReceiptType getReceiptType() { 142 return _receipt; 143 } 144 145 /*** 146 * Helper to parse a DeliveryType from a string 147 * 148 * @param type the string to parse 149 * @return the parsed delivery type 150 */ 151 public static DeliveryType fromString(String type) { 152 final int minTokens = 2; 153 final int maxTokens = 3; 154 DeliveryType result; 155 boolean persistent = false; 156 boolean administered = false; 157 ReceiptType receipt = null; 158 159 StringTokenizer tokens = new StringTokenizer(type, ", "); 160 int count = tokens.countTokens(); 161 162 if (count < minTokens || count > maxTokens) { 163 throw new IllegalArgumentException( 164 "Invalid delivery type: " + type); 165 } 166 167 String persistentStr = tokens.nextToken(); 168 String administeredStr = tokens.nextToken(); 169 170 if ("PERSISTENT".equals(persistentStr)) { 171 persistent = true; 172 } else if (!"NON_PERSISTENT".equals(persistentStr)) { 173 throw new IllegalArgumentException( 174 "Invalid delivery mode: expected one of PERSISTENT " 175 + "or NON_PERSISTENT but got " + persistentStr); 176 } 177 if ("administered".equals(administeredStr)) { 178 administered = true; 179 } else if (!"temporary".equals(administeredStr)) { 180 throw new IllegalArgumentException( 181 "Invalid destination type: expected one of administered " 182 + "or temporary but got " + administeredStr); 183 } 184 185 String receiptStr = null; 186 if (count == maxTokens) { 187 receiptStr = tokens.nextToken(); 188 receipt = ReceiptType.fromString(receiptStr); 189 result = new DeliveryType(persistent, administered, receipt); 190 } else { 191 result = new DeliveryType(persistent, administered); 192 } 193 return result; 194 } 195 196 }

This page was automatically generated by Maven