commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frank W. Zammetti" <>
Subject Re: Digester wildcard question
Date Tue, 21 Jun 2005 02:13:52 GMT
Hey Simon, or anyone else... I'm hoping you can help me over another 
hump I'm encountering (man, that sounds *awful*, but I digress...)

I have the following code:

String configClass = "";
String configFile = "/WEB-INF/config.xml";
Digester digester = new Digester();
digester.setRules(new ExtendedBaseRules());
digester.addObjectCreate("config", configClass);
InputStream isConfigFile = servletContext.getResourceAsStream(configFile);

The idea, ultimately, is that I would be getting the value of 
configClass from a context init param.  So I want Digester to create an 
instance of the named class, and then for each element encountered in 
the XML file, call the appropriate setter.

Now, I'm using essentially the same XML as before...


...and here is that class I'm trying to populate...

public class SampleAppConfigBean {
   private static String item1;
   private static String item2;
   private static String item3;
   public static void setItem1(String val) {
     item1 = val;
   public static String getItem1() {
     return item1;
   public static void setItem2(String val) {
     item2 = val;
   public static String getItem2() {
     return item2;
   public static void setItem3(String val) {
     item3 = val;
   public static String getItem3() {
     return item3;

Pretty straight-forward, or so I thought :)  When I try it, I get the 
following exception...

Jun 20, 2005 9:58:22 PM org.apache.commons.digester.Digester endElement
SEVERE: End event threw exception
java.lang.NoSuchMethodException: Bean has no property named item1

Now, it sure looks to me like that bean has an item1 property :)  I 
tried making it public, just on a whim, but that made no difference (and 
I'm kind of glad it didn't because that would have confused the hell out 
of me!)

So, I'm sure it's something simple that I don't know, hoping someone can 
point it out.  Thanks again!


Frank W. Zammetti wrote:
> Thank you *very* much Simon, that was exactly what I needed!  I wound up 
> using "config/?" as the pattern, and that did the trick perfectly, 
> everything else worked as-is.
> You know, Digester has always struck me as one of those things that is a 
>  bit overwhelming for a while, but it really is one of the more powerful 
> and useful Commons projects out there.
> Thank again!
> Frank
> Simon Kitching wrote:
>> On Mon, 2005-06-20 at 14:01 -0400, Frank W. Zammetti wrote:
>>> Hi... I went through the Digester docs, but couldn't find the answer 
>>> to my
>>> specific question (although the answer seemed to be hinted at)... is it
>>> possible to have a matching pattern of simply "*" so that every 
>>> element in
>>> the document being parsed fires the corresponding rule?
>>> What I'm trying to do is have a simple XML format with a list of 
>>> elements:
>>> <myDoc>
>>> <item1>11</item1>
>>> <item2>22</item2>
>>> <item3>33</item3>
>>> </myDoc>
>>> ... and I want to have a rule fire to take each of those and insert them
>>> in to a map (just a call to a generic setter), but without knowing
>>> before-hand that item1, item2 and item3 will be present (i.e., maybe 
>>> it's
>>> item4, item5 and item6 instead).  So I figured just match "*" would 
>>> do it,
>>> but am looking for verification.  TIA!
>> The standard rule-matching engine (RulesBase) doesn't support this. It
>> allows leading wildcards (eg "*/item1"), but doesn't support a wildcard
>> on its own.
>> The ExtendedBaseRules class allows trailing wildcards, so "myDoc/*" will
>> match any direct child element of myDoc which is what you want I
>> believe. It also allows completely-wild expressions "*" and "!*". It
>> doesn't have any expression to specify "any descendant of myDoc". See
>> the javadoc for class ExtendedBaseRules for more info.
>> The RegExRules class is even more powerful (but slower).
>> There is a sneaky way of effectively supporting trailing-wildcard with
>> the standard RulesBase matching engine if you are writing your own rule;
>> the SetNestedElementRule class has an example of this. But
>> ExtendedBaseRules is probably what you are looking for.
>> Regards,
>> Simon
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> For additional commands, e-mail:

Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message