}
private static SQLXML jsonToXml(CommandContext context,
final String rootName, final Reader r) throws TeiidComponentException,
TeiidProcessingException {
XMLType result = new XMLType(XMLSystemFunctions.saveToBufferManager(context.getBufferManager(), new XMLTranslator() {
@Override
public void translate(Writer writer) throws TransformerException,
IOException {
try {
JSONParser parser = new JSONParser();
XMLOutputFactory factory = getOutputFactory();
final XMLStreamWriter streamWriter = factory.createXMLStreamWriter(writer);
parser.parse(r, new JsonToXmlContentHandler(escapeName(rootName, true), streamWriter));
streamWriter.flush(); //woodstox needs a flush rather than a close
} catch (XMLStreamException e) {
throw new TransformerException(e);
} catch (ParseException e) {
throw new TransformerException(e);
} finally {
try {
r.close();
} catch (IOException e) {
}
}
}
}));
result.setType(Type.DOCUMENT);
return result;
}