Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 8719 invoked from network); 26 May 2003 20:30:00 -0000 Received: from smtp-out3.blueyonder.co.uk (195.188.213.6) by daedalus.apache.org with SMTP; 26 May 2003 20:30:00 -0000 Received: from localhost ([80.194.24.21]) by smtp-out3.blueyonder.co.uk with Microsoft SMTPSVC(5.0.2195.5329); Mon, 26 May 2003 21:30:04 +0100 Date: Mon, 26 May 2003 21:31:00 +0100 Subject: Re: [digester] help with multi-argument constructor Content-Type: text/plain; charset=US-ASCII; format=flowed Mime-Version: 1.0 (Apple Message framework v482) From: robert burrell donkin To: "Jakarta Commons Users List" Content-Transfer-Encoding: 7bit In-Reply-To: <20030526191202.5012.qmail@web13506.mail.yahoo.com> Message-Id: X-Mailer: Apple Mail (2.482) X-OriginalArrivalTime: 26 May 2003 20:30:04.0500 (UTC) FILETIME=[96F9F940:01C323C5] X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N On Monday, May 26, 2003, at 08:12 PM, Christopher Bare wrote: > Thanks Simon and Robert for the insight into how these > rules work. I understand now why my idea is somewhat > at odds with the way digester is designed. > > You are correct that I want to use a setNext rule > after creating the User 0bject to add each user to an > aggregate object. Sorta like this: > > digester.addObjectCreate( "users", Users.class ); > > digester.addCallConstructor( "users/user", > User.class, 2 ); > digester.addCallParam( "users/user/id", 0 ); > digester.addCallParam( "users/user/name", 1 ); > > digester.addSetNext( "users/user", "addUser" ); > > If I understand correctly, the CallParam pushes values > onto the stack and the CallMethod rule pops them off > and finally invokes the method in the > end(java.lang.String namespace, java.lang.String name) > method of the rule. I was thinking that the > CallConstructor rule could work the same way, and that > the newly created object could be pushed onto the > stack in the end(...) method. Then the SetNext rule > could come along and pop do its thing. > > The issue with this, I guess, is that you need to > insure that the the constructor is called and the > object pushed onto the stack before SetNext's end(...) > is invoked. Or, is there more to it than that? you need to ensure that the constructor is called and the object pushed onto the stack before SetNext's end method is called and then popped off the stack after it's called. > If the > Constructor was invoked in the body(...) of my > hypothetical CallConstructorRule, that would > definitely push the new object first. Would body(...) > definitely be called -after- the params were pushed > onto the stack? yes. what happens is that when the digester endElement implementation is called, all the body calls for all the matched rules are called and then all the end calls. endElement for the parent has to be called (by the SAX parser) after each endElement is called for each child element - therefore any params which are going to be pushed onto the stack will have been. (the only exception is where you're setting a parameter from the body text of the parent - in this case, you'd need to be careful about the ordering.) - robert