View Javadoc
1 /*** 2 * Copyright (c) 2002, CodeStreet LLC. 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 CodeStreet LLC. 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.codestreet.messageforge; 19 20 import com.tibco.tibrv.*; 21 import java.io.IOException; 22 import java.io.ObjectInputStream; 23 import java.io.ObjectOutputStream; 24 25 /*** 26 * Class to represent a <tt>TibrvMsg</tt> field. 27 * @see com.tibco.tibrv.TibrvMsg 28 * @author Jawaid Hakim. 29 */ 30 public class RFldTibrvMsg extends RFld 31 { 32 /*** 33 * Default constructor. 34 */ 35 public RFldTibrvMsg() 36 { 37 } 38 39 /*** 40 * Constructor. 41 * @param name Field name. Field names must follow the TibrvMsg 42 * field naming conventions. 43 * @param fieldId Field id. Field ids must be either <tt>0</tt> 44 * to indicate that there is no id on the field, or greater. In addition, 45 * field ids must be unique within a messages - no two fields are allowed 46 * to have the same field id. 47 * @see com.tibco.tibrv.TibrvMsg 48 */ 49 public RFldTibrvMsg(String name, int fieldId) 50 { 51 super(name, fieldId); 52 } 53 54 /*** 55 * Constructor. 56 * @param name Field name. Field names must follow the TibrvMsg 57 * field naming conventions. 58 * @param fieldId Field id. Field ids must be either <tt>0</tt> 59 * to indicate that there is no id on the field, or greater. In addition, 60 * field ids must be unique within a messages - no two fields are allowed 61 * to have the same field id. 62 * @param desc Field description. 63 * @see com.tibco.tibrv.TibrvMsg 64 */ 65 public RFldTibrvMsg(String name, int fieldId, String desc) 66 { 67 super(name, fieldId, desc); 68 } 69 70 /*** 71 * Get field type. 72 * @return Field type <tt>MSG</tt>. 73 * @see RFldType 74 */ 75 public final RFldType getType() 76 { 77 return RFldType.MSG; 78 } 79 80 /*** 81 * Check if another field is equal to this field. Equality is defined 82 * as the fields having the same string representation. A short cut 83 * that needs to be fixed for cases where the string representation is 84 * rounding off numbers etc. 85 * @param anObject Another field. 86 * @return <tt>true</tt> if another field is equal to this field. 87 * Otherwise, returns <tt>false</tt>. 88 */ 89 public boolean equals(Object anObject) 90 { 91 if (this == anObject) 92 { 93 return true; 94 } 95 else if (anObject == null || ! (anObject instanceof RFldTibrvMsg)) 96 { 97 return false; 98 } 99 RFldTibrvMsg another = (RFldTibrvMsg)anObject; 100 if (valSet_ && another.isValSet()) 101 return equals(dataObj_, another.getValue()); 102 else 103 return false; 104 } 105 106 /*** 107 * Recursive method to compare two <tt>TibrvMsg</tt>. The native <tt>equals</tt> 108 * method of TibrvMsg compares object references. We want to compare object values. This 109 * method compares the value of each field, calling itself recursively when comparing 110 * nested <tt>TibrvMsg</tt> fields. 111 * @param first First <tt>TibrvMsg</tt>. 112 * @param second Second <tt>TibrvMsg</tt>. 113 * @return <tt>true</tt> if the two <tt>TibrvMsg</tt> instances have the 114 * same number of fields, and each field has identical type and value. Otherwise, 115 * returns <tt>false</tt>. 116 */ 117 public static boolean equals(TibrvMsg first, TibrvMsg second) 118 { 119 if (first == second) 120 return true; 121 else if (first == null || second == null) 122 return false; 123 124 try 125 { 126 int fldCount = first.getNumFields(); 127 boolean eq = (fldCount == second.getNumFields()); 128 for (int i = fldCount - 1; eq && i >= 0; --i) 129 { 130 TibrvMsgField firstFld = first.getFieldByIndex(i); 131 TibrvMsgField secondFld = second.getField(firstFld.name); 132 if (secondFld != null && firstFld.type == secondFld.type) 133 { 134 if (firstFld.type != TibrvMsg.MSG) 135 eq = firstFld.data.equals(secondFld.data); 136 else 137 eq = equals((TibrvMsg)firstFld.data, (TibrvMsg)secondFld.data); 138 } 139 else 140 eq = false; 141 } 142 return eq; 143 } 144 catch (TibrvException ex) 145 { 146 return false; 147 } 148 } 149 150 /*** 151 * Returns the hash code value for the field. Since the equals method 152 * is using the comparison of the string representation of the tibrv message 153 * then the hashcode is the hashcode of this string. 154 * 155 * @return a hash code value for the field. 156 */ 157 public int hashCode() 158 { 159 return (valSet_) ? dataObj_.hashCode() : 1231; 160 } 161 162 /*** 163 * Reset the field value. 164 * @see #isValSet() 165 */ 166 public void reset() throws FieldValidationException 167 { 168 if (isLocked()) 169 throw new FieldValidationException("Field " + getName() + " is locked"); 170 171 valSet_ = false; 172 dataObj_ = null; 173 } 174 175 /*** 176 * Set data. 177 * @param newData New data. 178 */ 179 public RFld set(byte[] newData) throws FieldValidationException 180 { 181 try 182 { 183 return set(new TibrvMsg(newData)); 184 } 185 catch (TibrvException ex) 186 { 187 throw new FieldValidationException(ex); 188 } 189 } 190 191 /*** 192 * Set data. 193 * @param newData New data. 194 */ 195 public RFld set(Object newData) throws FieldValidationException 196 { 197 try 198 { 199 return set((TibrvMsg)newData); 200 } 201 catch (ClassCastException e) 202 { 203 return set(newData.toString()); 204 } 205 } 206 207 /*** 208 * Set data. 209 * @param newData New data. 210 */ 211 public RFld set(TibrvMsg newData) throws FieldValidationException 212 { 213 validate(newData); 214 215 dataObj_ = newData; 216 valSet_ = true; 217 218 return this; 219 } 220 221 /*** 222 * Set data. 223 * @param newData New data. 224 */ 225 public RFld set(java.util.Hashtable newData) throws FieldValidationException 226 { 227 validate(newData); 228 try 229 { 230 // Create a TibrvMsg from newData 231 TibrvMsg rvMsg = new TibrvMsg(); 232 set(newData, rvMsg); 233 234 // Set value from new TibrvMsg 235 return set(rvMsg); 236 } 237 catch (ProtocolException ex) 238 { 239 throw new FieldValidationException(ex); 240 } 241 } 242 243 /*** 244 * Set data. 245 * @param source Source <tt>java.util.Hashtable</tt>. 246 * @param target Target <tt>com.tibco.tibrv.TibrvMsg</tt>. 247 */ 248 public static void set(java.util.Hashtable source, TibrvMsg target) throws ProtocolException 249 { 250 try 251 { 252 for (java.util.Enumeration enum = source.keys(); enum.hasMoreElements(); ) 253 { 254 String nestedFldName = (String)enum.nextElement(); 255 Object nestedFldValue = source.get(nestedFldName); 256 if (nestedFldValue instanceof java.util.Hashtable) 257 { 258 TibrvMsg nestedRvMsg = new TibrvMsg(); 259 set((java.util.Hashtable)nestedFldValue, nestedRvMsg); 260 target.add(nestedFldName, nestedRvMsg); 261 } 262 else 263 target.add(nestedFldName, nestedFldValue); 264 } 265 } 266 catch (TibrvException ex) 267 { 268 throw new ProtocolException(ex); 269 } 270 } 271 272 /*** 273 * Set the field value from a JDOM element. 274 * @param elem Field value as a JDOM element. 275 */ 276 public final RFld set(org.jdom.Element elem) throws FieldValidationException 277 { 278 TibrvMsg rvMsg = new TibrvMsg(); 279 java.util.List fields = elem.getChildren(); 280 281 set(rvMsg, fields); 282 return set(rvMsg); 283 } 284 285 /*** 286 * Set the fields in the specified <tt>TibrvMsg</tt> from the list of JDOM 287 * field elements. 288 * @param rvMsg RV Message. 289 * @param fields List of JDOM elements. 290 */ 291 static void set(TibrvMsg rvMsg, java.util.List fields) throws FieldValidationException 292 { 293 if (fields != null) 294 { 295 for (java.util.Iterator iter = fields.iterator(); iter.hasNext(); ) 296 { 297 org.jdom.Element fld = (org.jdom.Element)iter.next(); 298 addField(rvMsg, fld); 299 } 300 } 301 } 302 303 /*** 304 * Add a field to target message. 305 * @param rvMsg Target message. 306 * @param fld Field. 307 */ 308 static void addField(TibrvMsg rvMsg, org.jdom.Element fld) throws FieldValidationException 309 { 310 // Sanity check - field name must be specified 311 String attrName = fld.getAttributeValue(XML_ATTR_NAME); 312 if (attrName == null) 313 throw new FieldValidationException("Field name is missing"); 314 315 try 316 { 317 String attrValue = fld.getAttributeValue(XML_ATTR_VALUE); 318 short fldType = getFieldType(fld.getName()); 319 if (fldType == RFldType.STRING.shortValue() || fldType == TibrvMsg.STRING) 320 rvMsg.add(attrName, attrValue); 321 else if (fldType == RFldType.DATETIME.shortValue() || fldType == TibrvMsg.DATETIME) 322 rvMsg.add(attrName, new java.util.Date(Long.parseLong(attrValue))); 323 else if (fldType == RFldType.IPADDR32.shortValue() || fldType == TibrvMsg.IPADDR32) 324 rvMsg.add(attrName, new com.tibco.tibrv.TibrvIPAddr(Integer.parseInt(attrValue))); 325 else if (fldType == RFldType.IPPORT16.shortValue() || fldType == TibrvMsg.IPPORT16) 326 rvMsg.add(attrName, new com.tibco.tibrv.TibrvIPPort(Integer.parseInt(attrValue))); 327 else if (fldType == RFldType.I8.shortValue() || fldType == TibrvMsg.I8) 328 rvMsg.add(attrName, new Byte(attrValue)); 329 else if (fldType == RFldType.I16.shortValue() || fldType == TibrvMsg.I16) 330 rvMsg.add(attrName, new Short(attrValue)); 331 else if (fldType == RFldType.I32.shortValue() || fldType == TibrvMsg.I32) 332 rvMsg.add(attrName, new Integer(attrValue)); 333 else if (fldType == RFldType.I64.shortValue() || fldType == TibrvMsg.I64) 334 rvMsg.add(attrName, new Long(attrValue)); 335 else if (fldType == RFldType.F32.shortValue() || fldType == TibrvMsg.F32) 336 rvMsg.add(attrName, new Float(attrValue)); 337 else if (fldType == RFldType.F64.shortValue() || fldType == TibrvMsg.F64) 338 rvMsg.add(attrName, new Double(attrValue)); 339 else if (fldType == RFldType.BOOL.shortValue() || fldType == TibrvMsg.BOOL) 340 rvMsg.add(attrName, new Boolean(attrValue)); 341 else if (fldType == RFldType.I8ARRAY.shortValue() || fldType == TibrvMsg.I8ARRAY) 342 rvMsg.add(attrName, RFldI8Array.parse(fld)); 343 else if (fldType == RFldType.I16ARRAY.shortValue() || fldType == TibrvMsg.I16ARRAY) 344 rvMsg.add(attrName, RFldI16Array.parse(fld)); 345 else if (fldType == RFldType.I32ARRAY.shortValue() || fldType == TibrvMsg.I32ARRAY) 346 rvMsg.add(attrName, RFldI32Array.parse(fld)); 347 else if (fldType == RFldType.I64ARRAY.shortValue() || fldType == TibrvMsg.I64ARRAY) 348 rvMsg.add(attrName, RFldI64Array.parse(fld)); 349 else if (fldType == RFldType.F32ARRAY.shortValue() || fldType == TibrvMsg.F32ARRAY) 350 rvMsg.add(attrName, RFldF32Array.parse(fld)); 351 else if (fldType == RFldType.F64ARRAY.shortValue() || fldType == TibrvMsg.F64ARRAY) 352 rvMsg.add(attrName, RFldF64Array.parse(fld)); 353 else if (fldType == RFldType.OPAQUE.shortValue() || fldType == TibrvMsg.OPAQUE) 354 rvMsg.add(attrName, RFldOpaque.decode(attrValue)); 355 else if (fldType == RFldType.XML.shortValue() || fldType == TibrvMsg.XML) 356 rvMsg.add(attrName, new TibrvXml(RFldOpaque.decode(attrValue))); 357 else if (fldType == RFldType.MSG.shortValue() || fldType == TibrvMsg.MSG) 358 { 359 TibrvMsg nestedRvMsg = new TibrvMsg(); 360 rvMsg.add(attrName, nestedRvMsg); 361 set(nestedRvMsg, fld.getChildren()); // recursion 362 } 363 else 364 throw new FieldValidationException("Unsupported field type: " + fldType); 365 } 366 catch (TibrvException ex) 367 { 368 throw new FieldValidationException(ex); 369 } 370 } 371 372 /*** 373 * Get the field type. 374 * @param xmlTag XML element tag. 375 * @see RFldType 376 */ 377 private static final short getFieldType(String xmlTag) throws FieldValidationException 378 { 379 if (xmlTag != null) 380 { 381 RFldType type = getType(xmlTag); 382 if (type != null) 383 return type.shortValue(); 384 } 385 386 throw new FieldValidationException("Unknown element name: " + xmlTag); 387 } 388 389 /*** 390 * Validate against constraints. A field is valid if either it's value is set 391 * and satisfies all constraints, or the the field is optional. 392 */ 393 public void validate() throws FieldValidationException 394 { 395 // Only need to check that non-optional fields have been set. If a 396 // field has been set then it must be valid since validation is done 397 // with each set. 398 if (! valSet_ && !optional_) 399 throw new FieldValidationException("Field not set: " + getName()); 400 } 401 402 /*** 403 * Check if a new value will satifsy constraints. 404 * @param newData New value. 405 */ 406 public void validate(TibrvMsg newData) throws FieldValidationException 407 { 408 if (locked_) 409 throw new FieldValidationException("Cannot modify locked field: " + getName()); 410 411 if (newData == null) 412 throw new FieldValidationException("New value is NULL for field: " + getName());; 413 } 414 415 /*** 416 * Check if a new value will satifsy constraints. 417 * @param newData New value. 418 */ 419 public void validate(java.util.Hashtable newData) throws FieldValidationException 420 { 421 if (isLocked()) 422 throw new FieldValidationException("Cannot modify locked field: " + getName()); 423 424 if (newData == null) 425 throw new FieldValidationException("New value is NULL for field: " + getName());; 426 } 427 428 /*** 429 * Get data. 430 * @return data Data. Returns <tt>null</tt> if the field value is not set. 431 */ 432 public TibrvMsg getValue() 433 { 434 return dataObj_; 435 } 436 437 /*** 438 * Get the field value as an object. 439 * @return Field value as an object. Reference to data is passed out so be 440 * very careful about modifying the data. Returns <tt>null</tt> if the 441 * field value is not set 442 */ 443 public Object getValueAsObject() 444 { 445 return dataObj_; 446 } 447 448 /*** 449 * Get the value of a nested field as an object. The name of the field 450 * can indicate nesting of any arbitrary level. For example, if the 451 * TibrvMsg field has the following content:<br> 452 * Content <br> 453 * [ <br> 454 * X <br> 455 * y 456 * [ <br> 457 * y <br> 458 * ] <br> 459 * ] <br> 460 * then calling this method with the field name 'X.y' and separator "." 461 * will return the value of the field y nested within X. 462 * @param name Field name. 463 * @param separator Field name separator. 464 * @return Value of a nested field as an object. Returns <tt>null</tt> if 465 * the field value is not set. 466 */ 467 public Object getValueAsObject(String name, String separator) 468 { 469 try 470 { 471 TibrvMsg containerRvMsg = dataObj_; 472 for (int beginIndex = name.indexOf(separator); beginIndex >= 0; ) 473 { 474 containerRvMsg = (TibrvMsg)containerRvMsg.get(name.substring(0, beginIndex)); 475 name = name.substring(beginIndex + 1); 476 beginIndex = name.indexOf(separator); 477 } 478 return (containerRvMsg != null) ? containerRvMsg.get(name) : null; 479 } 480 catch (TibrvException ex) 481 { 482 return null; 483 } 484 } 485 486 /*** 487 * Get the field value as a string. 488 * @return Field value as a string. Returns <tt>null</tt> if 489 * the field value is not set 490 */ 491 public String getValueAsString() 492 { 493 if (valSet_) 494 return dataObj_.toString(); 495 else 496 return null; 497 } 498 499 /*** 500 * Get the field value as a java.util.Hashtable. Every field type that is not directly 501 * supported within Tibrv - every field with type greater than or equal to 502 * RFldType.USER_FIRST - and including fields of type TibrvMsg will implement 503 * this method. Throws an exception if the nested field value is not set. 504 * @return Field value as java.util.Hashtable. 505 */ 506 public java.util.Hashtable getValueAsHashtable() throws FieldValidationException 507 { 508 if (! valSet_) 509 throw new FieldValidationException("Field not set: " + getName()); 510 511 return getValueAsHashtable(dataObj_); 512 } 513 514 /*** 515 * Get the value of a <tt>TibrvMsg</tt> as a <tt>java.util.Hashtable</tt>. 516 * @return Value of <tt>TibrvMsg</tt> as <tt>java.util.Hashtable</tt>. 517 * Returns <tt>null</tt> if the field value is not set. 518 */ 519 protected java.util.Hashtable getValueAsHashtable(TibrvMsg rvMsg) throws FieldValidationException 520 { 521 if (! valSet_) 522 throw new FieldValidationException("Field not set: " + getName()); 523 524 try 525 { 526 java.util.Hashtable flds = new java.util.Hashtable(); 527 for (int i = dataObj_.getNumFields() - 1; i >= 0; --i) 528 { 529 TibrvMsgField fld = dataObj_.getFieldByIndex(i); 530 if (fld.data instanceof TibrvMsg) 531 flds.put(fld.name, getValueAsHashtable((TibrvMsg)fld.data)); 532 else 533 flds.put(fld.name, fld.data); 534 } 535 return flds; 536 } 537 catch (TibrvException ex) 538 { 539 throw new FieldValidationException(ex); 540 } 541 } 542 543 /*** 544 * Write state of object to object output stream. 545 * @param out Object output stream. 546 */ 547 private void writeObject(ObjectOutputStream out) throws IOException 548 { 549 try 550 { 551 if (valSet_) 552 out.write(dataObj_.getAsBytes()); 553 } 554 catch (TibrvException ex) 555 { 556 throw new IOException(ex.toString()); 557 } 558 } 559 560 /*** 561 * Read state of object from object input stream. 562 * @param in Object input stream. 563 */ 564 private void readObject(ObjectInputStream in) throws IOException 565 { 566 try 567 { 568 if (valSet_) 569 dataObj_ = new TibrvMsg((byte[])in.readObject()); 570 } 571 catch (TibrvException ex) 572 { 573 throw new IOException(ex.toString()); 574 } 575 catch (ClassNotFoundException ex) 576 { 577 throw new IOException(ex.toString()); 578 } 579 } 580 581 /*** 582 * Write the field as XML to target writer. 583 * @param writer Output target. 584 * @param indent Indentation. 585 * @param newLines Newlines are inserted after each element if <tt>true</tt>. 586 * @param expandEmptyElements Empty elements - elements with no content - are expanded if <tt>true</tt>. 587 */ 588 public void marshal(java.io.Writer writer, int indentLevel, String indent, boolean newLines, boolean expandEmptyElements) throws ConverterException 589 { 590 if (! isValSet()) 591 throw new ConverterException("Field not set: " + getName()); 592 593 marshal(writer, XML_TAG, getName(), getValue(), getType().toString(), indentLevel, indent, newLines, expandEmptyElements); 594 } 595 596 /*** 597 * Write the field as XML to target writer. 598 * @param writer Output target. 599 * @param indent Indentation. 600 * @param newLines Newlines are inserted after each element if <tt>true</tt>. 601 * @param expandEmptyElements Empty elements - elements with no content - are expanded if <tt>true</tt>. 602 */ 603 final static void marshal(java.io.Writer writer, String tag, String name, TibrvMsg rvMsg, String type, int indentLevel, String indent, boolean newLines, boolean expandEmptyElements) throws ConverterException 604 { 605 try 606 { 607 ConverterXML.openTag(writer, tag, indentLevel, indent); 608 ConverterXML.writeAttribute(writer, XML_ATTR_NAME, name); 609 ConverterXML.closeStartTag(writer, newLines); 610 611 ++indentLevel; 612 for (int i = rvMsg.getNumFields() - 1; i >= 0; --i) 613 { 614 TibrvMsgField fld = rvMsg.getFieldByIndex(i); 615 if (fld.type == TibrvMsg.STRING) 616 RFld.marshal(writer, RFldString.XML_TAG, fld.name, (String)fld.data, String.valueOf(TibrvMsg.STRING), indentLevel, indent, newLines, expandEmptyElements); 617 else if (fld.type == TibrvMsg.I32) 618 RFld.marshal(writer, RFldI32.XML_TAG, fld.name, fld.data.toString(), String.valueOf(TibrvMsg.I32), indentLevel, indent, newLines, expandEmptyElements); 619 else if (fld.type == TibrvMsg.DATETIME) 620 RFld.marshal(writer, RFldDatetime.XML_TAG, fld.name, String.valueOf(((java.util.Date)fld.data).getTime()), String.valueOf(TibrvMsg.DATETIME), indentLevel, indent, newLines, expandEmptyElements); 621 else if (fld.type == TibrvMsg.BOOL) 622 RFld.marshal(writer, RFldBool.XML_TAG, fld.name, fld.data.toString(), String.valueOf(TibrvMsg.BOOL), indentLevel, indent, newLines, expandEmptyElements); 623 else if (fld.type == TibrvMsg.F32) 624 RFld.marshal(writer, RFldF32.XML_TAG, fld.name, fld.data.toString(), String.valueOf(TibrvMsg.F32), indentLevel, indent, newLines, expandEmptyElements); 625 else if (fld.type == TibrvMsg.F64) 626 RFld.marshal(writer, RFldF64.XML_TAG, fld.name, fld.data.toString(), String.valueOf(TibrvMsg.F64), indentLevel, indent, newLines, expandEmptyElements); 627 else if (fld.type == TibrvMsg.I8) 628 RFld.marshal(writer, RFldI8.XML_TAG, fld.name, fld.data.toString(), String.valueOf(TibrvMsg.I8), indentLevel, indent, newLines, expandEmptyElements); 629 else if (fld.type == TibrvMsg.I16) 630 RFld.marshal(writer, RFldI16.XML_TAG, fld.name, fld.data.toString(), String.valueOf(TibrvMsg.I16), indentLevel, indent, newLines, expandEmptyElements); 631 else if (fld.type == TibrvMsg.I64) 632 RFld.marshal(writer, RFldI64.XML_TAG, fld.name, fld.data.toString(), String.valueOf(TibrvMsg.I64), indentLevel, indent, newLines, expandEmptyElements); 633 else if (fld.type == TibrvMsg.F32ARRAY) 634 RFldArray.marshal(writer, RFldF32Array.XML_TAG, fld.name, fld.data, String.valueOf(TibrvMsg.F32ARRAY), indentLevel, indent, newLines, expandEmptyElements); 635 else if (fld.type == TibrvMsg.F64ARRAY) 636 RFldArray.marshal(writer, RFldF64Array.XML_TAG, fld.name, fld.data, String.valueOf(TibrvMsg.F64ARRAY), indentLevel, indent, newLines, expandEmptyElements); 637 else if (fld.type == TibrvMsg.I8ARRAY) 638 RFldArray.marshal(writer, RFldI8Array.XML_TAG, fld.name, fld.data, String.valueOf(TibrvMsg.I8ARRAY), indentLevel, indent, newLines, expandEmptyElements); 639 else if (fld.type == TibrvMsg.I16ARRAY) 640 RFldArray.marshal(writer, RFldI16Array.XML_TAG, fld.name, fld.data, String.valueOf(TibrvMsg.I16ARRAY), indentLevel, indent, newLines, expandEmptyElements); 641 else if (fld.type == TibrvMsg.I32ARRAY) 642 RFldArray.marshal(writer, RFldI32Array.XML_TAG, fld.name, fld.data, String.valueOf(TibrvMsg.I32ARRAY), indentLevel, indent, newLines, expandEmptyElements); 643 else if (fld.type == TibrvMsg.I64ARRAY) 644 RFldArray.marshal(writer, RFldI64Array.XML_TAG, fld.name, fld.data, String.valueOf(TibrvMsg.I64ARRAY), indentLevel, indent, newLines, expandEmptyElements); 645 else if (fld.type == TibrvMsg.IPADDR32) 646 RFld.marshal(writer, RFldTibrvIPAddr.XML_TAG, fld.name, String.valueOf(((TibrvIPAddr)fld.data).getAddr()), String.valueOf(TibrvMsg.IPADDR32), indentLevel, indent, newLines, expandEmptyElements); 647 else if (fld.type == TibrvMsg.IPPORT16) 648 RFld.marshal(writer, RFldTibrvIPPort.XML_TAG, fld.name, String.valueOf(((TibrvIPPort)fld.data).getPort()), String.valueOf(TibrvMsg.IPPORT16), indentLevel, indent, newLines, expandEmptyElements); 649 else if (fld.type == TibrvMsg.XML) 650 RFld.marshal(writer, RFldXml.XML_TAG, fld.name, RFldOpaque.encode(((TibrvXml)fld.data).getBytes()), String.valueOf(TibrvMsg.XML), indentLevel, indent, newLines, expandEmptyElements); 651 else if (fld.type == TibrvMsg.OPAQUE) 652 RFld.marshal(writer, RFldOpaque.XML_TAG, fld.name, RFldOpaque.encode((byte[])fld.data), String.valueOf(TibrvMsg.OPAQUE), indentLevel, indent, newLines, expandEmptyElements); 653 else if (fld.type == TibrvMsg.MSG) 654 marshal(writer, tag, fld.name, (TibrvMsg)fld.data, type, indentLevel, indent, newLines, expandEmptyElements); 655 else 656 throw new ConverterException("Unsupported data type: " + fld); 657 } 658 --indentLevel; 659 ConverterXML.closeTag(writer, tag, indentLevel, indent, newLines); 660 } 661 catch (java.io.IOException ex) 662 { 663 throw new ConverterException(ex); 664 } 665 catch (TibrvException ex) 666 { 667 throw new ConverterException(ex); 668 } 669 } 670 671 /*** 672 * Get the XML tag for this field type. 673 * @return XML tag for this field type. 674 */ 675 public final String getTag() 676 { 677 return XML_TAG; 678 } 679 680 /*** 681 * Set the XML tag for this field type. 682 * @param tag New XML tag for this field type. 683 */ 684 public static void setTag(String tag) 685 { 686 XML_TAG = tag; 687 } 688 689 /*** 690 * Get the <tt>RFldType</tt> object corresponding to 691 * the specified XML field tag. 692 * @param xmlTag XML tag of field. 693 * @return <tt>RFldType</tt> object corresponding to 694 * the specified XML field tag. Returns <tt>null</tt> if the 695 * corresponding <tt>RFldType</tt> is not defined. 696 */ 697 public static final RFldType getType(String xmlTag) 698 { 699 return (RFldType)TAG_TO_TYPE.get(xmlTag); 700 } 701 702 /*** 703 * Build XML tag to Class maping. 704 */ 705 static final void buildTags() 706 { 707 TAG_TO_TYPE = new java.util.HashMap(); 708 TAG_TO_TYPE.put(RFldDatetime.XML_TAG, RFldType.DATETIME); 709 TAG_TO_TYPE.put(RFldString.XML_TAG, RFldType.STRING); 710 TAG_TO_TYPE.put(RFldStringArray.XML_TAG, RFldType.STRINGARRAY); 711 TAG_TO_TYPE.put(RFldStringHashtable.XML_TAG, RFldType.STRINGHASHTABLE); 712 TAG_TO_TYPE.put(RFldI8.XML_TAG, RFldType.I8); 713 TAG_TO_TYPE.put(RFldI8Array.XML_TAG, RFldType.I8ARRAY); 714 TAG_TO_TYPE.put(RFldI16.XML_TAG, RFldType.I16); 715 TAG_TO_TYPE.put(RFldI16Array.XML_TAG, RFldType.I16ARRAY); 716 TAG_TO_TYPE.put(RFldI32.XML_TAG, RFldType.I32); 717 TAG_TO_TYPE.put(RFldI32Array.XML_TAG, RFldType.I32ARRAY); 718 TAG_TO_TYPE.put(RFldI64.XML_TAG, RFldType.I64); 719 TAG_TO_TYPE.put(RFldI64Array.XML_TAG, RFldType.I64ARRAY); 720 TAG_TO_TYPE.put(RFldF32.XML_TAG, RFldType.F32); 721 TAG_TO_TYPE.put(RFldF32Array.XML_TAG, RFldType.F32ARRAY); 722 TAG_TO_TYPE.put(RFldF64.XML_TAG, RFldType.F64); 723 TAG_TO_TYPE.put(RFldF64Array.XML_TAG, RFldType.F32ARRAY); 724 TAG_TO_TYPE.put(RFldBool.XML_TAG, RFldType.BOOL); 725 TAG_TO_TYPE.put(RFldTibrvMsg.XML_TAG, RFldType.MSG); 726 TAG_TO_TYPE.put(RFldTibrvMsgArray.XML_TAG, RFldType.MSGARRAY); 727 728 TAG_TO_TYPE.put(RFldTibrvIPPort.XML_TAG, RFldType.IPPORT16); 729 TAG_TO_TYPE.put(RFldTibrvIPAddr.XML_TAG, RFldType.IPADDR32); 730 731 TAG_TO_TYPE.put(RFldOpaque.XML_TAG, RFldType.OPAQUE); 732 TAG_TO_TYPE.put(RFldMsgObj.XML_TAG, RFldType.MSGOBJ); 733 TAG_TO_TYPE.put(RFldMsgObjArray.XML_TAG, RFldType.MSGOBJARRAY); 734 TAG_TO_TYPE.put(RFldMsgObjHashtable.XML_TAG, RFldType.MSGOBJHASHTABLE); 735 } 736 737 /*** 738 * XML tag for this element type. 739 */ 740 static transient String XML_TAG = "tibrvmsg"; 741 742 private static transient java.util.Map TAG_TO_TYPE; 743 static 744 { 745 buildTags(); 746 } 747 748 /*** 749 * Data. 750 */ 751 protected TibrvMsg dataObj_; 752 }

This page was automatically generated by Maven