1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 package org.coach.idltree; 26 27 import java.util.*; 28 29 35 public class XmlWriter implements IdlWriter { 36 private StringBuffer sb; 37 private int indent = 1; 38 39 44 public XmlWriter(int indent) { 45 clear(); 46 this.indent = indent; 47 } 48 49 52 public XmlWriter() { 53 clear(); 54 } 55 56 59 public void clear() { 60 sb = new StringBuffer ( 61 "<!DOCTYPE idlxml SYSTEM \"idlxml.dtd\">\n" + 63 "<idlxml>\n"); 64 } 65 66 private String indent() { 67 StringBuffer sb = new StringBuffer (""); 68 for (int i = 0; i < indent; i++) { 69 sb.append(" "); 70 } 71 return sb.toString(); 72 } 73 74 79 public void write_fixed(String v) { 80 sb.append(indent() + "<fixed>" + v + "</fixed>\n"); 81 } 82 83 88 public void write_double(String v) { 89 sb.append(indent() + "<double>" + v + "</double>\n"); 90 } 91 92 97 public void write_float(String v) { 98 sb.append(indent() + "<float>" + v + "</float>\n"); 99 } 100 101 106 public void write_longdouble(String v) { 107 sb.append(indent() + "<longdouble>" + v + "</longdouble>\n"); 108 } 109 110 115 public void write_ulonglong(String v) { 116 sb.append(indent() + "<ulonglong>" + v + "</ulonglong>\n"); 117 } 118 119 124 public void write_longlong(String v) { 125 sb.append(indent() + "<longlong>" + v + "</longlong>\n"); 126 } 127 128 133 public void write_ulong(String v) { 134 sb.append(indent() + "<ulong>" + v + "</ulong>\n"); 135 } 136 137 142 public void write_long(String v) { 143 sb.append(indent() + "<long>" + v + "</long>\n"); 144 } 145 146 151 public void write_ushort(String v) { 152 sb.append(indent() + "<ushort>" + v + "</ushort>\n"); 153 } 154 155 160 public void write_short(String v) { 161 sb.append(indent() + "<short>" + v + "</short>\n"); 162 } 163 164 169 public void write_octet(String v) { 170 sb.append(indent() + "<octet>" + v + "</octet>\n"); 171 } 172 173 178 public void write_boolean(String v) { 179 sb.append(indent() + "<boolean>" + v + "</boolean>\n"); 180 } 181 182 187 public void write_char(String v) { 188 sb.append(indent() + "<char>" + v + "</char>\n"); 189 } 190 191 196 public void write_wchar(String v) { 197 sb.append(indent() + "<wchar>" + v + "</wchar>\n"); 198 } 199 200 205 public void write_string(String v) { 206 if (v == null) { 207 v = ""; 208 } 209 sb.append(indent() + "<string>" + v + "</string>\n"); 210 } 211 212 217 public void write_wstring(String v) { 218 if (v == null) { 219 v = ""; 220 } 221 sb.append(indent() + "<wstring>" + v + "</wstring>\n"); 222 } 223 224 229 public void write_Object(String v) { 230 sb.append(indent() + "<object>" + v + "</object>\n"); 231 } 232 233 244 public void write_start_sequence(String id, int length) { 245 sb.append(indent() + "<sequence id=\"" + id + "\" length=\"" + length + "\">\n"); 246 indent++; 247 } 248 249 252 public void write_end_sequence() { 253 indent--; 254 sb.append(indent() + "</sequence>\n"); 255 } 256 257 268 public void write_start_array(String id, int length) { 269 sb.append(indent() + "<array id=\"" + id + "\" length=\"" + length + "\">\n"); 270 indent++; 271 } 272 273 276 public void write_end_array() { 277 indent--; 278 sb.append(indent() + "</array>\n"); 279 } 280 281 291 public void write_start_struct(String id) { 292 sb.append(indent() + "<struct id=\"" + id + "\">\n"); 293 indent++; 294 } 295 296 306 public void write_start_value(String id) { 307 sb.append(indent() + "<valuetype id=\"" + id + "\">\n"); 308 indent++; 309 } 310 311 319 public void write_start_member(String name) { 320 sb.append(indent() + "<member name=\"" + name + "\">\n"); 321 indent++; 322 } 323 324 327 public void write_end_member() { 328 indent--; 329 sb.append(indent() + "</member>\n"); 330 } 331 332 335 public void write_end_struct() { 336 indent--; 337 sb.append(indent() + "</struct>\n"); 338 } 339 340 343 public void write_end_value() { 344 indent--; 345 sb.append(indent() + "</valuetype>\n"); 346 } 347 348 358 public void write_start_union(String id) { 359 sb.append(indent() + "<union id=\"" + id + "\">\n"); 360 indent++; 361 } 362 363 368 public void write_union_tag(String v) { 369 sb.append(indent() + "<tag>" + v + "</tag>\n"); 370 } 371 372 375 public void write_end_union() { 376 indent--; 377 sb.append(indent() + "</union>\n"); 378 } 379 380 386 public void write_enum(String id, String v) { 387 sb.append(indent() + "<enum id=\"" + id + "\">" + v + "</enum>\n"); 388 } 389 390 396 public void write_interface(String id, String ior) { 397 sb.append(indent() + "<interface id=\"" + id + "\">" + ior + "</interface>\n"); 398 } 399 400 406 public void write_component(String id, String ior) { 407 sb.append(indent() + "<component id=\"" + id + "\">" + ior + "</component>\n"); 408 } 409 410 419 public void write_start_operation(String name, String interfaceId) { 420 sb.append(indent() + "<operation name=\"" + name + "\" id=\"" + interfaceId + "\">\n"); 421 indent++; 422 } 423 424 432 public void write_start_inpar(String name) { 433 sb.append(indent() + "<in name=\"" + name + "\">\n"); 434 indent++; 435 } 436 437 440 public void write_end_inpar() { 441 indent--; 442 sb.append(indent() + "</in>\n"); 443 } 444 445 453 public void write_start_outpar(String name) { 454 sb.append(indent() + "<out name=\"" + name + "\">\n"); 455 indent++; 456 } 457 458 461 public void write_end_outpar() { 462 indent--; 463 sb.append(indent() + "</out>\n"); 464 } 465 466 474 public void write_start_inoutpar(String name) { 475 sb.append(indent() + "<inout name=\"" + name + "\">\n"); 476 indent++; 477 } 478 479 482 public void write_end_inoutpar() { 483 indent--; 484 sb.append(indent() + "</inout>\n"); 485 } 486 487 493 public void write_start_return() { 494 sb.append(indent() + "<return>\n"); 495 indent++; 496 } 497 498 501 public void write_end_return() { 502 indent--; 503 sb.append(indent() + "</return>\n"); 504 } 505 506 514 public void write_start_exception(String id) { 515 sb.append(indent() + "<exception id=\"" + id + "\">\n"); 516 indent++; 517 } 518 519 522 public void write_end_exception() { 523 indent--; 524 sb.append(indent() + "</exception>\n"); 525 } 526 527 530 public void write_end_operation() { 531 indent--; 532 sb.append(indent() + "</operation>\n"); 533 } 534 535 545 public void write_start_reply(String name, String interfaceId) { 546 sb.append(indent() + "<reply name=\"" + name + "\" id=\"" + interfaceId + "\">\n"); 547 indent++; 548 } 549 550 553 public void write_end_reply() { 554 indent--; 555 sb.append(indent() + "</reply>\n"); 556 } 557 558 563 public String toString() { 564 indent--; 565 sb.append("</idlxml>\n"); 566 return sb.toString(); 567 } 568 569 577 public void write_start_any() { 578 sb.append(indent() + "<any>\n"); 579 indent++; 580 } 581 582 585 public void write_end_any() { 586 indent--; 587 sb.append(indent() + "</any>\n"); 588 } 589 } | Popular Tags |