commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <si...@ecnetwork.co.nz>
Subject Re: [Digester] Parent Reference Help
Date Tue, 31 Aug 2004 00:41:35 GMT
On Tue, 2004-08-31 at 12:01, Ken Egervari wrote:
> Hi,
> 
>  
> 
> Is there any way to reference a parent object when parsing an XML document
> using the commons-digester component?  For example, let's assume that there
> is an addObjectCreate() rule that creates a Page object for the <page> tag
> and a SelectOne object for the <selectone> tag.  If I have the following XML
> (shown below), is there any way the reference of my Page object can be
> passed in the SelectOne object before the SelectOne's setters are called
> using a typical addSetProperties() rule?  I'm having trouble obtaining a
> reference since using addSetTop() is called after the setters are called.  
> 
>  
> 
> This is rather inconvenient since some setters (in SelectOne for instance)
> will often need access to the parent object (the Page object in this
> instance).  In other instances, I need to traverse up the graph of objects
> to the root.  Since the parent is not defined, this is impossible.  

Hmm.. I see that the SetTopRule is invoking the target method in the
end() method, ie when it sees the closing tag.

I don't see why it does this. If it were to invoke the target method in
begin(), then that would solve your issue, as:
  digester.addObjectCreate("page/selectone", SelectOne.class);
  digester.addSetTop("page/selectone", "setParentPage");
  digester.addSetProperties("page/selectone");
would then invoke the setParentPage before the property setter methods.

I don't currently see any reason *why* it waits until end() to invoke
the target method.

I suggest taking the source code for SetTopRule, copying it into your
namespace then modifying it so that the work is done in begin() rather
than end(), and seeing if this works for you. If it does, let us know as
I for one think this should be merged into the digester mainline code. 

You would of course use it as:
  NewSetTopRule rule = new NewSetTopRule("setParentPage");
  digester.addRule("page/selectone", rule);

NB: If a change is to be applied to digester CVS, I think it's actually
more likely to involve a modification which adds an extra constructor
param indicating whether invocation at begin or end is desired, and
default to the current behaviour, for backwards compatibility.


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