01: package org.objectweb.celtix.bus.bindings.xml;
02:
03: import java.io.*;
04: import org.w3c.dom.*;
05:
06: import org.objectweb.celtix.helpers.XMLUtils;
07:
08: public class XMLMessage {
09:
10: private Document root;
11: private XMLUtils xmlUtils = new XMLUtils();
12: private XMLFault xmlFault;
13:
14: public XMLMessage() {
15: this .root = xmlUtils.newDocument();
16: }
17:
18: public void writeTo(OutputStream out) throws IOException {
19: xmlUtils.writeTo(this .root, out);
20: }
21:
22: public Document getRoot() {
23: return this .root;
24: }
25:
26: public void setRoot(Document r) {
27: this .root = r;
28: }
29:
30: public void appendChild(Node child) {
31: if (root != null) {
32: root.appendChild(child);
33: }
34: }
35:
36: public boolean hasChildNodes() {
37: return this .root.hasChildNodes();
38: }
39:
40: public void removeContents() {
41: xmlUtils.removeContents(this .root);
42: }
43:
44: public void setFault(XMLFault fault) {
45: this .xmlFault = fault;
46: }
47:
48: // Creates a new XMLFault object and adds it to this XML Message root object.
49: public XMLFault addFault() {
50: xmlFault = new XMLFault();
51: Node faultRoot = xmlUtils.createElementNS(this .root,
52: XMLConstants.XML_FAULT_ROOT);
53: appendChild(faultRoot);
54: xmlFault.setFaultRoot(faultRoot);
55: return xmlFault;
56: }
57:
58: public XMLFault getFault() {
59: return this .xmlFault;
60: }
61:
62: public boolean hasFault() {
63: return this .xmlFault != null;
64: }
65:
66: public String toString() {
67: return xmlUtils.toString(this.root);
68: }
69: }
|