public String writeDataFactory(final WriteableDocumentBundle bundle,
final DataFactory dataFactory,
final BundleWriterState state)
throws IOException, BundleWriterException
{
final HQLDataFactory hqlDataFactory = (HQLDataFactory) dataFactory;
final String fileName = BundleUtilities.getUniqueName(bundle, state.getFileName(), "datasources/hibernate-ds{0}.xml");
if (fileName == null)
{
throw new IOException("Unable to generate unique name for Inline-Data-Source");
}
final OutputStream outputStream = bundle.createEntry(fileName, "text/xml");
final DefaultTagDescription tagDescription = new DefaultTagDescription(ClassicEngineBoot.getInstance().getGlobalConfig(), HibernateDataFactoryModule.TAG_DEF_PREFIX);
final XmlWriter xmlWriter = new XmlWriter(new OutputStreamWriter(outputStream, "UTF-8"), tagDescription, " ", "\n");
final AttributeList rootAttrs = new AttributeList();
if (xmlWriter.isNamespaceDefined(HibernateDataFactoryModule.NAMESPACE) == false)
{
rootAttrs.addNamespaceDeclaration("data", HibernateDataFactoryModule.NAMESPACE);
}
xmlWriter.writeTag(HibernateDataFactoryModule.NAMESPACE, "hibernate-datasource", rootAttrs, XmlWriter.OPEN);
try
{
writeConnectionInfo(xmlWriter, hqlDataFactory.getSessionProvider());
}
catch (ReportWriterException e)
{
throw new BundleWriterException("Failed to write connection info", e);
}
final String[] queryNames = hqlDataFactory.getQueryNames();
for (int i = 0; i < queryNames.length; i++)
{
final String queryName = queryNames[i];
final String query = hqlDataFactory.getQuery(queryName);
xmlWriter.writeTag(HibernateDataFactoryModule.NAMESPACE, "query", "name", queryName, XmlWriter.OPEN);
xmlWriter.writeTextNormalized(query, false);
xmlWriter.writeCloseTag();
}
xmlWriter.writeCloseTag();