Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 36549 invoked from network); 9 May 2004 23:22:18 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 9 May 2004 23:22:18 -0000 Received: (qmail 97031 invoked by uid 500); 9 May 2004 23:21:52 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 96982 invoked by uid 500); 9 May 2004 23:21:52 -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 96887 invoked from network); 9 May 2004 23:21:51 -0000 Received: from unknown (HELO unxcoms01.ecnetwork.co.nz) (202.135.116.201) by daedalus.apache.org with SMTP; 9 May 2004 23:21:51 -0000 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 i49NLvXL009551 for ; Mon, 10 May 2004 11:21:57 +1200 Received: from pcjohns.ecnnz.ecnetwork.co.nz (unknown [202.135.190.30]) by serpent.ecnetwork.co.nz (Postfix) with ESMTP id A7C571035 for ; Mon, 10 May 2004 11:29:43 +1200 (NZST) Subject: Re: [digester] digester adds sub-objects before fully created From: Simon Kitching To: Jakarta Commons Users List In-Reply-To: <409E2C99.4010605@blueyonder.co.uk> References: <409E2C99.4010605@blueyonder.co.uk> Content-Type: text/plain Message-Id: <1084144916.5197.19.camel@pcsimon> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 Date: Mon, 10 May 2004 11:21:56 +1200 Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hi, On Mon, 2004-05-10 at 01:05, gary and sarah wrote: > I am using digester to read the following file > > with the following as an example of a rules > > // x axis > digester.addObjectCreate("tensor_frame/x_axis", > BasicProjections.class); > > digester.addCallMethod("tensor_frame/x_axis","setAxis",1,new > Class[]{Axis.class}); > digester.addObjectParam("tensor_frame/x_axis",0,Axis.X); > > digester.addBeanPropertySetter ("tensor_frame/x_axis/x", "x"); > digester.addBeanPropertySetter ("tensor_frame/x_axis/y", "y"); > digester.addBeanPropertySetter ("tensor_frame/x_axis/z", "z"); > digester.addSetNext("tensor_frame/x_axis", "addProjections"); > > // tensor_frame > digester.addObjectCreate("tensor_frame", BasicTensorFrame.class); > > however, basicTensorFrame.addprojections is being called with an > impcompletely constructed BasicProjections object... > > this apppears to be because the end clauses of rules are being called in > the reverse order from that in which they are declared: > It's more a side-effect of the stack-oriented nature of Digester. Yes, it's counter-intuitive. The reason that the CallMethodRule does the actual method invocation from the end method is that you need to be sure that all the param rules have fired. In particular, param rules that pass the element body text need to have completed their work. And end methods must be invoked in the reverse order relative to begin methods to ensure that rules which manipulate the digester object stack and param stack clean up correctly. Begin methods commonly push onto the stack, and end methods clean up the stack; failing to fire end in reverse order will severely stuff up the stack(s)! Workaround: add the SetNextRule before the CallMethodRule. Its end method will therefore be called after the CallMethodRule's end method, and so the object will be initialised before addProjections is invoked. It looks a little odd, but is a 100% reliable solution. The javadocs for the next release will have a big note pointing out this behaviour, and the appropriate workaround. In the CVS repository there is also an experimental alternative to CallMethodRule which doesn't suffer from this problem, but it won't make it in the next release. Regards, Simon --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org