Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 20523 invoked from network); 20 Jun 2006 11:39:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 20 Jun 2006 11:39:56 -0000 Received: (qmail 46964 invoked by uid 500); 20 Jun 2006 11:39:53 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 46913 invoked by uid 500); 20 Jun 2006 11:39:52 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: 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 46892 invoked by uid 99); 20 Jun 2006 11:39:52 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Jun 2006 04:39:52 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [210.54.141.245] (HELO fep01.xtra.co.nz) (210.54.141.245) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Jun 2006 04:39:51 -0700 Received: from [10.1.1.8] (really [222.152.246.60]) by fep01.xtra.co.nz with ESMTP id <20060620113929.XREP9780.fep01.xtra.co.nz@[10.1.1.8]> for ; Tue, 20 Jun 2006 23:39:29 +1200 Subject: Re: Using Digester to store info into a Map From: Simon Kitching To: Jakarta Commons Users List In-Reply-To: <20060615144309.51724.qmail@web30102.mail.mud.yahoo.com> References: <20060615144309.51724.qmail@web30102.mail.mud.yahoo.com> Content-Type: text/plain Date: Tue, 20 Jun 2006 23:39:30 +1200 Message-Id: <1150803570.5263.63.camel@blackbox> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N On Thu, 2006-06-15 at 07:43 -0700, Jeff Marendo wrote: > Simon, > > Thanks for the reply and helpful information. > > >>If user is the root level, then you've not got a lot of object in the > >>map :-) > > Yeah, actually, I did have a single file with multiple users listed within it as you had suggested, > but I later changed the design so that each user would have his own XML file. Part of the reason for > that is because I'm also using Betwixt to save objects as XML. Just seemed a bit easier to split the > users apart into separate files. Ok, that's a somewhat different problem. I was assuming you'd just trimmed down your input file to a single user element for the purposes of this email, and that you really had multiple user elements in a single input xml file. But instead you're trying to process a set of xml input files one by one, each file including one user definition? Digester doesn't provide any support for processing batches of files, so I presume you're doing: for each file to be processed { Digester d = new Digester(); setUpRules(d); // add your custom rules for parsing a user d.parse(aUserFile); User u = (User) d.getRoot(); // store your user somewhere, eg in a Map } In this case, what's the question about getting *digester* to insert user objects into maps about? > > >>The best solution would be to simply *not* use a map. > [snip] > >> private Map userMap = new HashMap(); > Can you clarify that for me? The "" notation next to the Map and HashMap classnames is throwing me off > , although I think it just means that they would be storing User instances. > That's java 1.5 generics notation. It just means that the userMap instance is a map that only permits Users objects to be inserted into it (just as you assumed). Actually, I got that syntax wrong (careless!). A map has key and value, so I should have written: private Map userMap = new HashMap(); which is a map whose keys can only be of type String, and whose values can only be of type User. The old-fashioned non-typed maps are technically the same as: Map ie accept any Object as key or value. > >>Unfortunately, invoking a custom rule when using the xmlrules module > >>isn't easy. > > Yeah, I was afraid of that. Actually, I was reading the xmlrules docs to try to answer another question today and invoking custom rules doesn't seem to be as hard as I remember. According to the javadoc for the xmlrules *package*, you can write a special class that instantiates a batch of rules and adds them to a digester. You then reference that class via: Good luck. Regards, Simon --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org