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 63809 invoked from network); 27 May 2003 21:33:06 -0000 Received: from icarus.apache.org (208.185.179.13) by daedalus.apache.org with SMTP; 27 May 2003 21:33:06 -0000 Received: (qmail 92624 invoked by uid 1059); 27 May 2003 21:33:06 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 27 May 2003 21:33:06 -0000 Date: Tue, 27 May 2003 14:33:05 -0700 (PDT) From: "Craig R. McClanahan" To: Jakarta Commons Users List Subject: Re: Help with digester In-Reply-To: <20030527203116.83921.qmail@web20419.mail.yahoo.com> Message-ID: <20030527142114.C65484@icarus.apache.org> References: <20030527203116.83921.qmail@web20419.mail.yahoo.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Rating: localhost 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N On Tue, 27 May 2003, C F wrote: > Date: Tue, 27 May 2003 13:31:16 -0700 (PDT) > From: C F > Reply-To: Jakarta Commons Users List > To: commons-user@jakarta.apache.org > Subject: Help with digester > > Hello, > Could somebody please give me an example of how I might try to accomlish the following with Digester (I'm coding, not using the XML config)? > Assume the following APIs on your bean classes (among other public methods): package mypackage; public class MyDepartment { public void setName(String name); // Call this "add" instead of "set" because departments // normally have more than one employee ;-) public void addEmployee(MyEmployee employee); } package mypackage; public class MyEmployee { public void setName(String name); } > Suppose, in my XML file, the following two nodes are valid.... > > example 1 > -------------------- > > > Buddy Hackett > > > digester.addObjectCreate("department", "mypackage.MyDepartment"); digester.addSetProperties("department"); // Works for all properties // passed as attributes digester.addObjectCreate("department/employee", "mypackage.MyEmployee"); digester.addCallMethod("department/employee", "setName", 0); // 0 == use body content digester.addSetNext("department/employee", "addEmployee", "mypackage.MyEmployee"); > example 2 > -------------------- > > Buddy Hackett > I've never actually tried this, but in *theory* this should work the same as the above logic: digester.addObjectCreate("department", "mypackage.MyDepartment"); digester.addSetProperties("department"); // Works for all properties // passed as attributes digester.addObjectCreate("department", "mypackage.MyEmployee"); digester.addCallMethod("department", "setName", 0); // 0 == use body content digester.addSetNext("department", "addEmployee", "mypackage.MyEmployee"); However, you're probably going to have problems with the property settings, which are going to both get fired off on the Employee object instead of being interleaved the way that "example 1" works.