Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 71679 invoked from network); 24 Nov 2003 22:23:15 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 24 Nov 2003 22:23:15 -0000 Received: (qmail 99030 invoked by uid 500); 24 Nov 2003 22:22:57 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 99003 invoked by uid 500); 24 Nov 2003 22:22:56 -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 98989 invoked from network); 24 Nov 2003 22:22:56 -0000 Received: from unknown (HELO unxcoms01.ecnetwork.co.nz) (202.135.116.201) by daedalus.apache.org with SMTP; 24 Nov 2003 22:22:56 -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 hAOMN1Ix007130 for ; Tue, 25 Nov 2003 11:23:01 +1300 Received: from pcjohns.ecnnz.ecnetwork.co.nz (pcjohns.ecnnz.ecnetwork.co.nz [202.135.190.30]) by serpent.ecnetwork.co.nz (Postfix) with ESMTP id E9F0B1035 for ; Tue, 25 Nov 2003 10:26:03 +1200 (NZST) Subject: Re: [digester] accessing parent data and matching dynamic elements From: Simon Kitching Reply-To: simon@ecnetwork.co.nz To: Jakarta Commons Users List In-Reply-To: <3FC2403E.2000407@phreaker.net> References: <3FC2403E.2000407@phreaker.net> Content-Type: text/plain Organization: The Electronic Commerce Network Ltd. Message-Id: <1069712578.3217.284.camel@pcjohns.ecnnz.ecnetwork.co.nz> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.4-8mdk Date: Tue, 25 Nov 2003 11:23:00 +1300 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 On Tue, 2003-11-25 at 06:30, __matthewHawthorne wrote: > I finally have found the chance to use Digester, and it's pretty > impressive. However, there are a few issues that I'm confused about, > and would appreciate the help. > > Here's my XML: > > > > > >
> > > > ... >
> > > I'm using Digester to define my data to bulk load using commons-sql. > > for each , I want to do: > > DynaBean bean = DynaSql.newInstance(../@name) > > and then set the record's attributes into the corresponding DynaBean. > > > 1) How can I do this? It seems that I can't access the parent element > to use it's "name" attribute. Hi Matthew, You can use a factory class to create your record objects (I think you are already?]. This factory can access the Digester object stack to get the object which represents the Table. [nb: assuming your table tags are actually under a top-level element called "root"] digester.addObjectCreate("root/table", Table.class); digester.addSetProperties("root/table"); # name->table.setName() ObjectCreationFactory recordFactory = new RecordFactory(); digester.addFactoryCreate("root/table/record", recordFactory); ... where the factory does Table table = (Table) digester.peek(0); return DynaSql.newInstance(table.getName()); This *does* require that there is some object to represent the Table. If you try to "skip" an element in Digester, then try to reference the data that it represents, things can get nasty. In your case, I think it makes sense to have *something* represent the anyway, right? Otherwise, what holds the collection of records you are building? Note that the FactoryCreateRule can take either an ObjectCreationFactory Class or an object of type ObjectCreationFactory. The former just creates an instance of the class then calls it. I prefer using the latter form myself, but either works. > 2) Originally, I tried doing it in this way: > > > > > > But I couldn't find a pattern to match each element. In looking at the > examples, I'm thinking I could maybe do: > > Digester.addFactoryCreate("?", MyFactory.class) using ExtendedRulesBase > > or > > Digester.addFactoryCreate("*", MyFactory.class) using the RegexRules? I presume your xml is actually like: ... ExtendedBaseRules can be used for "trailing wildcard matches", like "root/*". I don't know personally whether that matches all elements under root (including the record tags, which would be bad) or just direct children. I think RegexRules may help too, but I haven't used that myself. > Sorry for the abundance of questions. In the meanwhile, I'll keep > looking at the examples and doing experiments to try and figure this out. If you find some stuff isn't sufficiently documented, please feel free to either submit javadoc patches, or even better some new examples for the examples dir in CVS! Or just post the list of stuff you had problems with later & I will try to work up some new examples later. I presume the "examples" you are referring to are the ones in CVS (but not yet in an official release). [By the way, no code above has been tested; reader beware :-] Regards, Simon > > Thanks! > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: commons-user-help@jakarta.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org