iWay Service Manager works internally with XD trees, described earlier. Some external services you may want to use require JDOM trees. A utility class is available to convert between the two. To use it, make an instance of XDJDOMUtilities in the com.ibi.edaqm package. The methods exposed are:
Converts the tree rooted in the passed node to a JDOM document.
Converts the JDOM document to an XDNode tree.
This example makes a JDOM, converts it to an XDNode tree, and then goes the other way.
try
{
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(in); // make a JDOM doc
in.close();
XMLOutputter outputter = new XMLOutputter();
FileOutputStream out = new FileOutputStream(fileParsedJDOM);
outputter.output(doc, out); // print JDOM doc
XDJDOMUtilities jdu = new XDJDOMUtilities();
XDNode xnode = jdu.convertJDOMtoXD(doc);
out = new FileOutputStream(fileJDOMToXD);
out.write(XD.doflat(xnode,true).getBytes()); // print XD tree
doc = jdu.convertXDtoJDOM(xnode); // back to JDOM
out = new FileOutputStream(fileXDToJDOM);
outputter.output(doc, out); // print JDOM doc
}
catch (Exception e)
{
logger.debug("Exception received: "+ e); e.printStackTrace();
}| iWay Software |