Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 24922 invoked from network); 31 Aug 2004 00:42:05 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 31 Aug 2004 00:42:05 -0000 Received: (qmail 39764 invoked by uid 500); 31 Aug 2004 00:41:57 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 39719 invoked by uid 500); 31 Aug 2004 00:41:56 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 39703 invoked by uid 99); 31 Aug 2004 00:41:56 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from [202.135.116.201] (HELO unxcoms01.ecnetwork.co.nz) (202.135.116.201) by apache.org (qpsmtpd/0.27.1) with ESMTP; Mon, 30 Aug 2004 17:41:54 -0700 Received: from serpent.ecnetwork.co.nz (serpent [202.135.190.10]) by unxcoms01.ecnetwork.co.nz (8.12.8/8.12.8) with ESMTP id i7V0fpc1022633 for ; Tue, 31 Aug 2004 12:41:51 +1200 Received: from [202.135.190.30] (unknown [202.135.190.30]) by serpent.ecnetwork.co.nz (Postfix) with ESMTP id 6C0331035 for ; Tue, 31 Aug 2004 12:43:24 +1200 (NZST) Subject: Re: [Digester] Parent Reference Help From: Simon Kitching To: Jakarta Commons Users List In-Reply-To: <20040831000001.73D48A42@fep6.cogeco.net> References: <20040831000001.73D48A42@fep6.cogeco.net> Content-Type: text/plain Message-Id: <1093912895.25477.19.camel@pcsimon> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 Date: Tue, 31 Aug 2004 12:41:35 +1200 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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 tag > and a SelectOne object for the 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