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 21070 invoked by uid 98); 27 Jan 2003 22:05:07 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Received: (qmail 21050 invoked from network); 27 Jan 2003 22:05:05 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 27 Jan 2003 22:05:05 -0000 Received: (qmail 86024 invoked by uid 500); 27 Jan 2003 22:03:34 -0000 Received: (qmail 85925 invoked from network); 27 Jan 2003 22:03:34 -0000 Received: from cobra.ecnetwork.co.nz (202.135.116.44) by daedalus.apache.org with SMTP; 27 Jan 2003 22:03:34 -0000 Received: from serpent.ecnetwork.co.nz (serpent [202.135.190.10]) by cobra.ecnetwork.co.nz (8.11.4/8.11.3) with SMTP id h0RMAqj01393 for ; Tue, 28 Jan 2003 11:10:53 +1300 Received: (qmail 32449 invoked by uid 0); 27 Jan 2003 22:05:20 -0000 Received: from pcsimon.ecnnz.ecnetwork.co.nz (202.135.190.44) by serpent.ecnetwork.co.nz with SMTP; 27 Jan 2003 22:05:20 -0000 Subject: RE: [Digester] How to specify a parameter from top-of-stack From: Simon Kitching To: Jakarta Commons Users List In-Reply-To: References: Content-Type: text/plain Organization: Message-Id: <1043704747.2163.30.camel@PCSIMON.ecnnz.ecnetwork.co.nz> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.0 Date: 28 Jan 2003 10:59:07 +1300 Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Hi Naresh, Isn't the "SetTopRule" what you want? class Product { ..... public void addToParent(HashMap parent) { parent.put(this.partNumber, this); } } digester.addSetTop("/products/product", "addToParent", "java.util.HashMap"); I presume the same functionality is available via the xml config.. Regards, Simon On Sat, 2003-01-25 at 07:07, Naresh Bhatia wrote: > Yep, I found it in the latest nightly build. > Naresh > > -----Original Message----- > From: Baltz, Kenneth [mailto:Kbaltz@firstam.com] > Sent: Friday, January 24, 2003 1:00 PM > To: Jakarta Commons Users List > Subject: RE: [Digester] How to specify a parameter > from top-of-stack > > > Looks like that's a new feature, "fromStack". I don't see it in the 1.3 > Javadoc. Perhaps it will come to the XML soon. I'm surprised a > developer hasn't chimed in yet. > > K.C. > > > -----Original Message----- > > From: Naresh Bhatia [mailto:NBhatia@sapient.com] > > Sent: Friday, January 24, 2003 9:25 AM > > To: Jakarta Commons Users List > > Subject: RE: [Digester] How to specify a parameter > > from top-of-stack > > > > > > Yep, that would work - neat trick! Although, I agree with you that the > > > ability to address the object on the stack as an argument would be > > nicer. I thought that this could be done programatically using > > Digester.addCallParam(java.lang.String pattern, int paramIndex, > > boolean > > fromStack) - just that I could not find a way to do this via XML. > > > > Thanks again. > > Naresh > > > > -----Original Message----- > > From: Baltz, Kenneth [mailto:Kbaltz@firstam.com] > > Sent: Friday, January 24, 2003 11:51 AM > > To: Jakarta Commons Users List > > Subject: RE: [Digester] How to specify a parameter > > from top-of-stack > > > > > > Here's the solution I was given. I think it would be easier > > if we could > > reference the item on the stack as an argument. > > > > The trick is to create a new object that takes care of populating the > > HashMap for you. > > > > E.g. > > > > // Has to be public, although an anonymous inner class would be great > > public class HashMapProxy { > > HashMap _map; > > public Hashmap Proxy() { > > _map = new HashMap(); > > } > > > > public void addProduct( Product p ) { > > _map.put( p.getPartNumber(), p ); > > } > > > > public HashMap getMap() { > > return _map; > > } > > } > > > > Use the following Digester code: > > > > > > digester.addObjectCreate( "products", HashMapProxy.class ); > > digester.addObjectCreate( "products/product", Product.class ); > > ... initialize your Product object > > digester.addSetNext( "products/product", "addProduct" ); > > > > HashMapProxy proxy = (HashMapProxy)digester.parse( XML ); > > > > return proxy.getMap(); > > > > > > Hope that helps, hope they find a better way. > > > > K.C. > > > > > -----Original Message----- > > > From: Naresh Bhatia [mailto:NBhatia@sapient.com] > > > Sent: Thursday, January 23, 2003 9:44 PM > > > To: commons-user@jakarta.apache.org > > > Subject: [Digester] How to specify a > > parameter from > > > top-of-stack > > > > > > > > > I am trying to parse an XML file similar to the one shown below: > > > > > > > > > > > > ... > > > > > > > > > ... > > > > > > > > > > > > I want Digester to return a HashMap with partNumber as the key and > > > product as the value. How do I put the product on to the HashMap? I > > > guess I don't know how can specify the > > object from > > > top of the stack as a parameter. Here's my unsuccessful attempt at > > > this: > > > > > > > > > > > classname="java.util.HashMap"/> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > paramTypes="java.lang.String,Product"/> > > > > > > <--- what to do here? > > > > > > > > > > > > > > > Thanks. > > > Naresh Bhatia > > > > > > > -- > > To unsubscribe, e-mail: > > For additional commands, e-mail: > > > > -- > To unsubscribe, e-mail: > For additional commands, e-mail: > >