commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <skitch...@apache.org>
Subject Re: [Digester] setting properties from the app's runtime
Date Mon, 30 May 2005 02:34:53 GMT
On Wed, 2005-05-25 at 00:50 +0200, Timo Boewing wrote:
> Hello all,
> 
> I am working with Digester since some time now and am very happy with
> it; however, I have one major problem with it: whenever I let Digester
> create objects using addObjectCreate(), i want to set a property on this
> instance before calls of addSetProperties() or so are made. This
> property is not from the XML but from the app's runtime, say, a global
> variable.

Hi Timo,

Sorry I didn't see your email earlier.

You can use ObjectParamRule to pass arbitrary objects as part of a
CallMethodRule. However CallMethodRule rules actually invoke the target
method when the xml end tag is reached, which might not be what you want
if you *must* have the call made before addSetProperties.

An alternative is to use FactoryCreateRule rather than ObjectCreateRule
to create your object. You can then provide a custom
ObjectCreationFactory which configures your new instance however it
wants.

Or you can write a custom rule, QuestionInitialiserRule, that makes the
necessary call, and add it:
  Rule questionInitialiserRule = new QuestionInitialiserRule(...);

  digester.addObjectCreate(...);
  digester.addRule(..., questionInitialiserRule);
  digester.addSetProperties(...);
  ....
A custom rule like this should be about 20 lines of code.


I would think that using FactoryCreateRule is probably the best option
given your description.

Regards,

Simon


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message