robert burrell donkin <[EMAIL PROTECTED]> writes:
> hi daniel
>
> i'm a little ill at the moment so you'll have to forgive me if i'm a
> little slow today
Heya Robert, sorry to hear that -- get well soon.
> On Tuesday, August 12, 2003, at 01:16 AM, Daniel Rall wrote:
...
> > <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.
>
> i trust that you're using CVS HEAD (the integration of digester and
> betwixt has been improved since the last release).
Sorry I left that tidbit out -- using 1.0 alpha 1. I don't mind using
an unreleased version so long as there is a tag on the CVS repo so
that I can later match up the exact source code to the library
included in Scarab. Alpha 1 is working well for me, is there
compelling reason to upgrade?
> > 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;
> > }
> > }
> > }
...
> the first problem is that importErrors really is a field (as opposed
> to a property). at the moment, betwixt and digester only really deal
> with properties out of the box.
Yes, I figured I simply needed to hook some custom logic into the
processing.
> the second problem is that digester rules are additive. when the
> scarab-issues element is encountered, the betwixt rule will create an
> instance of ScarabIssues and push it onto the main digester stack and
> then the object create rule will create an instance of ScarabIssues
> and push it also onto the stack. the property setting rules work on
> the top element on the stack - the one created by the object create
> rule. betwixt will return the bean that it has created.
*nod* To clarify for me, Betwixt will not return the bean that my
ObjectCreateRule created, though that bean is the one which has all
the properties set on it?
> i've got a lot of half finished betwixt code sitting around here, some
> of which would provide an elegant solution to your problem. it would
> allow you to register a custom factory (with betwixt) to create
> ScarabIssues beans. unfortunately, it may be a while before that makes
> it into the betwixt codebase.
That sounds delicious. If there's any code I can try out for you, I'm
game.
> for the moment, i'd suggest replacing the object create rule with a
> custom Rule implementation something like:
>
>
> SetFieldRule extends Rule {
> public void begin (java.lang.String namespace,
> java.lang,String name, org.sax.Attributes attributes){
>
> ScarabIssues issues = (ScarabIssues) getDigester().peek();
> issues.importErrors = this.importErrors;
> }
> }
>
> registered with the same matching path.
>
> hope that helps.
That worked perfectly.
http://scarab.tigris.org/source/browse/scarab/src/java/org/tigris/scarab/util/xmlissues/ImportIssues.java.diff?r1=1.24&r2=1.25
Unrelated question: is it possible to use HyphenatedNameMapper's
mapTypeToElementName(String typeName) (or something of the sort) to
transform ScarabIssues.class into the String "scarab-issues" (to
obviate the hard-coding of magic strings)?
--
Daniel Rall
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]