1 /*
2 * Copyright (c) 2004, RV Test Team
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * Neither the name of the "RV Test Team" nor the names of its contributors may
16 * be used to endorse or promote products derived from this software without
17 * specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 * THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32 package com.reuters.msgtest.tibrvfields;
33
34 import com.tibco.tibrv.TibrvMsg;
35 import com.tibco.tibrv.TibrvMsgField;
36 import java.text.MessageFormat;
37
38
39 /***
40 * @author Michael Ward
41 */
42 public class FieldComparerFactory {
43 public static final String UNKNOWN_TYPE_MSG = "RvTestCase: ERROR *** Comparison of Field Type {0} not yet supported. Please report to mailing list.";
44
45 public FieldComparer getFieldComparer(TibrvMsgField field) {
46 switch (field.type) {
47 case TibrvMsg.MSG:
48 return new MessageComparer();
49
50 case TibrvMsg.STRING:
51 case TibrvMsg.BOOL:
52 case TibrvMsg.I8:
53 case TibrvMsg.I16:
54 case TibrvMsg.I32:
55 case TibrvMsg.I64:
56 case TibrvMsg.U64:
57 case TibrvMsg.F32:
58 case TibrvMsg.IPPORT16:
59 case TibrvMsg.IPADDR32:
60 return new PrimitivesComparer();
61
62 case TibrvMsg.F64:
63 return new DoubleComparer();
64
65 case TibrvMsg.DATETIME:
66 return new DateTimeComparer();
67
68 case TibrvMsg.U8:
69 case TibrvMsg.U16:
70 case TibrvMsg.U32:
71 return new UnicodeComparer();
72
73 case TibrvMsg.I8ARRAY:
74 case TibrvMsg.U8ARRAY:
75 case TibrvMsg.I16ARRAY:
76 case TibrvMsg.U16ARRAY:
77 case TibrvMsg.I32ARRAY:
78 case TibrvMsg.U32ARRAY:
79 case TibrvMsg.I64ARRAY:
80 case TibrvMsg.F32ARRAY:
81 case TibrvMsg.F64ARRAY:
82 return new ArrayComparer();
83
84 case TibrvMsg.XML:
85 return new XmlComparer();
86
87 default: // includes TibrvMsg.ENCRYPTED
88
89 String error = MessageFormat.format(UNKNOWN_TYPE_MSG,
90 new Object[] { TibrvMsg.getTypeName(field.type) });
91 throw new UnsupportedOperationException(error);
92 }
93 }
94 }