Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 14425 invoked from network); 31 Aug 2004 00:07:36 -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:07:36 -0000 Received: (qmail 5088 invoked by uid 500); 31 Aug 2004 00:07:31 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 5026 invoked by uid 500); 31 Aug 2004 00:07:31 -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 5013 invoked by uid 99); 31 Aug 2004 00:07:31 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=RCVD_BY_IP,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of craigmcc@gmail.com designates 64.233.170.201 as permitted sender) Received: from [64.233.170.201] (HELO mproxy.gmail.com) (64.233.170.201) by apache.org (qpsmtpd/0.27.1) with ESMTP; Mon, 30 Aug 2004 17:07:29 -0700 Received: by mproxy.gmail.com with SMTP id 75so233914rnk for ; Mon, 30 Aug 2004 17:07:24 -0700 (PDT) Received: by 10.38.3.58 with SMTP id 58mr789538rnc; Mon, 30 Aug 2004 17:07:24 -0700 (PDT) Received: by 10.38.72.8 with HTTP; Mon, 30 Aug 2004 17:07:24 -0700 (PDT) Message-ID: Date: Mon, 30 Aug 2004 17:07:24 -0700 From: Craig McClanahan Reply-To: Craig McClanahan To: Jakarta Commons Users List Subject: Re: [Digester] Parent Reference Help In-Reply-To: <20040831000001.73D48A42@fep6.cogeco.net> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <20040831000001.73D48A42@fep6.cogeco.net> X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N The simplest way to address this need is to use the object stack that Digester creates for you. Every time you execute an Object Create Rule, for example, the new instance gets pushed on to the stack, so that Digester rules for nested elements can get to it easily: Page page = (Page) digester.peek(); There's examples of this in the "Package Documentation" part of the Digester javadocs: http://jakarta.apache.org/commons/digester/apidocs/org/apache/commons/digester/package-summary.html#package_description as well as in the source code to rules like SetParentRule and SetNextRule, which rely on exactly this capability in order to perform their functions. Craig On Mon, 30 Aug 2004 20:01:02 -0400, 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. > > If I cannot access the parent as the setters are being called, I'm basically > forced to put this logic in the parent's addChild method instead where all > the attributes have been mapped to the object's properties already, but this > makes the object less convenient outside the digester. > > > > > validatorId="singlereference" > > errorMessage="There are no languages in the database." /> > > > I'm not flooding the message with source code because I don't think it's > required. The specifics of the example are unimportant and I'm more > interested in a general solution. > > Thanks for helping me out and best regards, > > > Ken Egervari > > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org