public void write(final ReportWriterContext reportWriter,
final XmlWriter xmlWriter,
final DataFactory dataFactory)
throws IOException, ReportWriterException
{
final ScriptableDataFactory scriptableDataFactory = (ScriptableDataFactory) dataFactory;
final AttributeList rootAttrs = new AttributeList();
rootAttrs.addNamespaceDeclaration("data", ScriptableDataFactoryModule.NAMESPACE);
xmlWriter.writeTag(ScriptableDataFactoryModule.NAMESPACE, "scriptable-datasource", rootAttrs, XmlWriter.OPEN);
final AttributeList configAttrs = new AttributeList();
configAttrs.setAttribute(ScriptableDataFactoryModule.NAMESPACE,
"language", String.valueOf(scriptableDataFactory.getLanguage()));
if (StringUtils.isEmpty(scriptableDataFactory.getScript()) == false)
{
configAttrs.setAttribute(ScriptableDataFactoryModule.NAMESPACE,
"script", String.valueOf(scriptableDataFactory.getScript()));
}
if (StringUtils.isEmpty(scriptableDataFactory.getScript()) == false)
{
configAttrs.setAttribute(ScriptableDataFactoryModule.NAMESPACE,
"shutdown-script", String.valueOf(scriptableDataFactory.getShutdownScript()));
}
xmlWriter.writeTag(ScriptableDataFactoryModule.NAMESPACE, "config", configAttrs, XmlWriterSupport.CLOSE);
final String[] queryNames = scriptableDataFactory.getQueryNames();
for (int i = 0; i < queryNames.length; i++)
{
final String queryName = queryNames[i];
final String query = scriptableDataFactory.getQuery(queryName);
xmlWriter.writeTag(ScriptableDataFactoryModule.NAMESPACE, "query", "name", queryName, XmlWriterSupport.OPEN);
xmlWriter.writeTextNormalized(query, false);
xmlWriter.writeCloseTag();
}
xmlWriter.writeCloseTag();