1 /***
2 * Copyright (c) 2002, Reuters America Inc. All rights reserved.<p>
3 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
4 * conditions are met:<p>
5 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
7 * in the documentation and/or other materials provided with the distribution. Neither the name of Reuters America Inc. nor the
8 * names of its contributors may be used to endorse or promote products derived from this software without specific prior written
9 * permission.<p>
10 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
11 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
12 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
14 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<p>
16 */
17
18 package com.reuters.rc.db.adb;
19
20 import com.reuters.rc.db.*;
21 import com.tibco.tibrv.*;
22
23 /***
24 * This class represents the data of a MInstance message published
25 * by an ADB agent. It provides methods to extract the data from
26 * the MInstance message. A set of static methods is provided to
27 * extract the data from the MInstance message without having
28 * to create an instance of this class.<p>
29 *
30 * If a database table has the parent role in a parent-child relationship
31 * with another table and the ADB publishing agents are configured to published
32 * child rows, then, when the parent table is modified, ADB will publish
33 * the related rows from the child table(s). The child table data can be
34 * retrieved using an instance of this class.<p>
35 *
36 * @author Jawaid Hakim.
37 * @see AdbMInstChildPubMsgData
38 */
39 public class AdbMInstPubMsgData implements DbPubMsgData
40 {
41 /***
42 * Constructor.
43 * @param msgData Data published by ADB.
44 */
45 public AdbMInstPubMsgData(TibrvMsg msgData)
46 {
47 msgData_ = msgData;
48 valid_ = (msgData_ != null);
49 }
50
51 /***
52 * Check if the object contains a valid result set.
53 * @return <code>true</code> if the object contains a valid
54 * result set. Returns <code>false</code> if the object does
55 * not contain a valid result set.
56 */
57 public final boolean isValid()
58 {
59 return valid_;
60 }
61
62 /***
63 * Get the published data message.
64 * @return Published data message.
65 */
66 public final TibrvMsg getData()
67 {
68 return msgData_;
69 }
70
71 /***
72 * Get the message class - the message class is the name of the table
73 * from which the update is published.
74 * @return Message class name. <code>null</code> is returned if the
75 * class name is not formatted correctly.
76 */
77 public final String getClassName() throws AdbSystemException
78 {
79 return getClassName(msgData_);
80 }
81
82 /***
83 * Get the message class - the message class is the name of the table
84 * from which the update is published.
85 * @param rvMsg Message data.
86 * @return Message class name. <code>null</code> is returned if the
87 * class name is not found.
88 */
89 public static String getClassName(TibrvMsg rvMsg) throws AdbSystemException
90 {
91 try
92 {
93 String cls = (String)rvMsg.get(ADB_DATA_CLASS);
94 if (cls == null)
95 return null;
96
97 // The published class (table) name might be prefixed by CLASS_PREFIX.
98 // Strip it off before returning to caller.
99 int index = cls.indexOf(CLASS_PREFIX);
100 return (index < 0) ? cls : cls.substring(index + 1);
101 }
102 catch (TibrvException ex)
103 {
104 throw new AdbSystemException(ex);
105 }
106 }
107
108 /***
109 * Get the message subject.
110 * @return Message subject. Returns <code>null</code> if subject is not found.
111 */
112 public final String getSubject() throws AdbSystemException
113 {
114 try
115 {
116 return (String)msgData_.get(ADB_DATA_ADB_SUBJECT);
117 }
118 catch (TibrvException ex)
119 {
120 throw new AdbSystemException(ex);
121 }
122 }
123
124 /***
125 * Get the message subject.
126 * @param rvMsg Message data.
127 * @return Message subject. Returns <code>null</code> if subject is not found.
128 */
129 public static String getSubject(TibrvMsg rvMsg) throws AdbSystemException
130 {
131 try
132 {
133 return (String)rvMsg.get(ADB_DATA_ADB_SUBJECT);
134 }
135 catch (TibrvException ex)
136 {
137 throw new AdbSystemException(ex);
138 }
139 }
140
141 /***
142 * Get the message sequence number.
143 * @return Message sequence number. Returns <code>null</code> if sequence
144 * number is not found.
145 */
146 public final Long getSequence() throws AdbSystemException
147 {
148 try
149 {
150 return getSequence(msgData_);
151 }
152 catch (AdbSystemException ex)
153 {
154 throw new AdbSystemException(ex);
155 }
156 }
157
158 /***
159 * Get the message sequence number.
160 * @param rvMsg Message data.
161 * @return Message sequence number. Returns <code>null</code> if sequence
162 * number is not found.
163 */
164 public static Long getSequence(TibrvMsg rvMsg) throws AdbSystemException
165 {
166 try
167 {
168 return (Long)rvMsg.get(ADB_DATA_ADB_SEQUENCE);
169 }
170 catch (TibrvException ex)
171 {
172 throw new AdbSystemException(ex);
173 }
174 }
175
176 /***
177 * Get the message opcode. The opcode is the code returned by ADB.
178 * @return Message opcode.
179 * @see AdbOpcode
180 */
181 public final DbOpcode getOpcode() throws AdbSystemException
182 {
183 return getOpcode(msgData_);
184 }
185
186 /***
187 * Get the message opcode. The opcode is the code returned by ADB.
188 * @param rvMsg Message data.
189 * @return Message opcode. Returns <code>null</code> if opcode is not found.
190 * @see AdbOpcode
191 */
192 public static AdbOpcode getOpcode(TibrvMsg rvMsg) throws AdbSystemException
193 {
194 try
195 {
196 return AdbOpcode.getOpcode((Integer)rvMsg.get(ADB_DATA_ADB_OPCODE));
197 }
198 catch (TibrvException ex)
199 {
200 throw new AdbSystemException(ex);
201 }
202 }
203
204 /***
205 * Get the Agent Id.
206 * @return Agent id. Returns <code>null</code> if agent id is not found.
207 */
208 public final String getAgentId() throws AdbSystemException
209 {
210 try
211 {
212 return (String)msgData_.get(ADB_DATA_ADB_AGENT_ID);
213 }
214 catch (TibrvException ex)
215 {
216 throw new AdbSystemException(ex);
217 }
218 }
219
220 /***
221 * Get the Agent Id.
222 * @param rvMsg Message data.
223 * @return Agent id. Returns <code>null</code> if agent id is not found.
224 */
225 public static String getAgentId(TibrvMsg rvMsg) throws AdbSystemException
226 {
227 try
228 {
229 return (String)rvMsg.get(ADB_DATA_ADB_AGENT_ID);
230 }
231 catch (TibrvException ex)
232 {
233 throw new AdbSystemException(ex);
234 }
235 }
236
237 /***
238 * Get all the child table data.
239 * @returns Array of all child table data. The array length is <code>0</code>
240 * if no child table data is found.
241 * @see AdbMInstChildPubMsgData
242 */
243 public final DbChildPubMsgData[] getChildRowData()
244 {
245 try
246 {
247 // Collate the field names of all the child table data.
248 java.util.List childDataFldName = null;
249 TibrvMsg data = getData();
250 for (int i = 0; i < data.getNumFields(); ++i)
251 {
252 TibrvMsgField rvFld = data.getFieldByIndex(i);
253 if (rvFld.name.startsWith(ADB_CHILD_DATA_ADB_SEQUENCE))
254 {
255 if (childDataFldName == null)
256 childDataFldName = new java.util.ArrayList();
257
258 childDataFldName.add(rvFld.name);
259 }
260 }
261
262 // Process each child table data
263 AdbMInstChildPubMsgData[] result = new AdbMInstChildPubMsgData[(childDataFldName == null) ? 0 : childDataFldName.size()];
264 for (int i = result.length - 1; i >= 0; --i)
265 {
266 String fldName = (String)childDataFldName.get(i);
267 result[i] = new AdbMInstChildPubMsgData(fldName, (TibrvMsg)data.get(fldName));
268 }
269
270 return result;
271 }
272 catch (TibrvException ex)
273 {
274 return null;
275 }
276 }
277
278 /***
279 * Override.
280 */
281 public String toString()
282 {
283 return msgData_.toString();
284 }
285
286 /***
287 * Field names for ADB published messages.
288 */
289 private static final String CLASS_PREFIX = "P";
290 private static final String ADB_DATA_CLASS = "^class^";
291 private static final String ADB_DATA_ADB_SUBJECT = "ADB_SUBJECT";
292 private static final String ADB_DATA_ADB_SEQUENCE = "ADB_SEQUENCE";
293 private static final String ADB_DATA_ADB_OPCODE = "ADB_OPCODE";
294 private static final String ADB_DATA_ADB_AGENT_ID = "ADB_AGENT_ID";
295
296 /***
297 * If any rows are published from a child table then the data field will have
298 * the name ADB_SEQUENCE_<child-table-name>.
299 */
300 static final String ADB_CHILD_DATA_ADB_SEQUENCE = "ADB_SEQUENCE_";
301
302 /***
303 * Data published by ADB.
304 */
305 private final TibrvMsg msgData_;
306
307 /***
308 * Validity flag.
309 */
310 private final boolean valid_;
311 }
This page was automatically generated by Maven