When a custom ScriptletFactory is registered via the extension mechanism the custom factory is never used. This is because the DefaultScriptletFactory throws an exception when a scriptlet could not be loaded. This is expected and the reason for a custom ScriptletFactory. Unfortunately the calling function (net.sf.jasperreports.engine.fill.JRFillDataset.createScriptlets() ) does not handle the exception and so the custom factory has no chance of creating the requested scriptlet.
I think JRFillDataset.createScriptlets should catch all exceptions and only rethrow one of them (possibly wrapped) if all registered ScriptletFactory implementations fail to load the scriptlet. Another solution would be to prevent DefaultScriptletFactory from throwing exceptions in the first place. Both solutions are complicated by the fact that ScriptletFactory attempts to load many (or all?) scriptlets from a report.
On a related note: DefaultScriptletFactory should probably not be a singleton so custom factories can extend from it. Collecting all the scriptlet class names out of the ScriptletFactoryContext is not trivial.
Recommended Comments