I'm looking for a way of using Digester's addRule(FactoryCreateRule)
method [1] with Betwixt's BeanReader to extend the processing used to
create an instance to "perform other setup processing" [2]. I want to
retain the existing recursive XML -> JavaBean processing behavior of
BeanReader, and set another instance field using some contextual
information which isn't available from my XML.
<scarab-issues>
<import-type>create-different-db</import-type>
<module>
...
</module>
...
</scarab-issues>
When beginning processing the <scarab-issues> element, I'd like to set
the instance field. Other than that, I'd like things to act like I'm
using a vanilla BeanReader. I've tried simply making an extra
BeanReader.addRule() call (inheritted from its Digester superclass),
but when I attempt to access children of <scarab-issues> when
processing using my additional rule, they're null. Here's a brief
synopsis of the code in question (or is that questionable code? ;)
...
BeanReader reader = new BeanReader();
reader.setXMLIntrospector(createXMLIntrospector());
reader.registerBeanClass(ScarabIssues.class);
reader.addRule("scarab-issues",
new FactoryCreateRule(new ScarabIssuesFactory()));
reader.setErrorHandler(this);
return reader;
}
/**
* An ObjectCreationFactory which sets the ImportErrors instance
* used by a ScarabIssues instance.
*/
class ScarabIssuesFactory extends AbstractObjectCreationFactory
{
public Object createObject(Attributes attributes)
{
ScarabIssues si = new ScarabIssues();
si.importErrors = this.importErrors;
LOG.info("DLR: Called createObject(" + attributes + ')');
return si;
}
}
}
Spare a clue?
--
Daniel Rall
[1]
http://jakarta.apache.org/commons/digester/apidocs/org/apache/commons/digester/FactoryCreateRule.html
[2]
http://jakarta.apache.org/commons/digester/apidocs/org/apache/commons/digester/package-summary.html#doc.Rules
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]