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: AckTypes.java,v 1.4 2004/01/31 13:44:24 tanderson Exp $
44 */
45 package org.exolab.jmscts.core;
46
47
48 /***
49 * Helper class used to indicate what message acknowledgement types to run a
50 * particular test case against
51 *
52 * @version $Revision: 1.4 $ $Date: 2004/01/31 13:44:24 $
53 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
54 * @see AckType
55 * @see SessionTestCase
56 * @see SessionTestRunner
57 */
58 public class AckTypes {
59
60 /***
61 * Transacted session
62 */
63 public static final AckType TRANSACTED = AckType.TRANSACTED;
64
65 /***
66 * Non-transacted session, session automatically acknowledges messages
67 */
68 public static final AckType AUTO_ACKNOWLEDGE = AckType.AUTO_ACKNOWLEDGE;
69
70 /***
71 * Non-transacted session, client ackwnowledges messages
72 */
73 public static final AckType CLIENT_ACKNOWLEDGE =
74 AckType.CLIENT_ACKNOWLEDGE;
75
76 /***
77 * Non-transacted session, messages are lazily acknowledged
78 */
79 public static final AckType DUPS_OK_ACKNOWLEDGE =
80 AckType.DUPS_OK_ACKNOWLEDGE;
81
82 /***
83 * All session message acknowledgement types
84 */
85 public static final AckTypes ALL;
86
87 /***
88 * Non transacted sessions
89 */
90 public static final AckTypes NON_TRANSACTIONAL;
91
92 /***
93 * Transacted sessions
94 */
95 public static final AckTypes TRANSACTIONAL;
96
97 /***
98 * The message acknowledgement types to test against
99 */
100 private AckType[] _types;
101
102 /***
103 * Construct a new instance to test against a set of message
104 * acknowledgement types
105 *
106 * @param types a list of message acknowledgement types
107 */
108 public AckTypes(AckType[] types) {
109 if (types == null) {
110 throw new IllegalArgumentException("Argument types is null");
111 }
112 if (types.length == 0) {
113 throw new IllegalArgumentException(
114 "Argument types has no elements");
115 }
116 _types = types;
117 }
118
119 /***
120 * Construct a new instance to test against a single acknowledgement type
121 *
122 * @param type the message acknowledgement type
123 */
124 public AckTypes(AckType type) {
125 if (type == null) {
126 throw new IllegalArgumentException("Argument type is null");
127 }
128 _types = new AckType[]{type};
129 }
130
131 /***
132 * Returns the list of message acknowledgement types to test against
133 *
134 * @return the list of message acknowledgement types to test against
135 */
136 public AckType[] getTypes() {
137 return _types;
138 }
139
140 /***
141 * Helper to convert a set of stringified acknowledgement types to a
142 * <code>AckTypes</code> instance
143 *
144 * @param types the acknowledgement types
145 * @return an instance corresponding to <code>types</code>,
146 * or <code>null</code> if <code>types</code> is invalid
147 */
148 public static AckTypes fromString(String[] types) {
149 AckTypes result = null;
150 AckType[] set = new AckType[types.length];
151 for (int i = 0; i < types.length; ++i) {
152 if ("all".equalsIgnoreCase(types[i])) {
153 result = ALL;
154 break;
155 } else {
156 set[i] = AckType.fromString(types[i]);
157 }
158 }
159 if (result == null) {
160 result = new AckTypes(set);
161 }
162 return result;
163 }
164
165 static {
166 ALL = new AckTypes(new AckType[]{
167 TRANSACTED, AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE,
168 DUPS_OK_ACKNOWLEDGE});
169 NON_TRANSACTIONAL = new AckTypes(new AckType[]{AUTO_ACKNOWLEDGE,
170 CLIENT_ACKNOWLEDGE,
171 DUPS_OK_ACKNOWLEDGE});
172 TRANSACTIONAL = new AckTypes(TRANSACTED);
173 }
174
175 }
176
This page was automatically generated by Maven