views:

268

answers:

4

I am new to java and I came across a statement in a java project which says:

Digester digester = DigesterLoader.createDigester(getClass() .getClassLoader().getResource("rules.xml"));

rules.xml file contains various patterns and every pattern has different attributes like classname ,methodname and some another properties.

i googled about digester but couldn't found anything useful that could help me with the statement above. can anyone just tell me what are the steps followed in executing above statement ? In fact what is the advantage of this XML stuff ?

+1  A: 

This is the method that's getting called here. Xml is used commonly in Java for configurations, since xml files do not need to be compiled. Having the same configuration in a java file would mean you have to compile the file.

soulmerge
+1  A: 

I assume you understand how the rules file is being loaded using the class loader? It's basically looking in the same package as the class itself and creating a URL that gives the file's absolute location.

As for the Digester, I've not used it but a quick read of this (http://commons.apache.org/digester/) should explain all.

Nick Holt
+2  A: 

swapnil, as a user of Digester back in my Struts days I can honestly say it's tricky to learn/debug. It's a tough library to familiarize yourself with, essentially you are setting up event handlers for certain elements kinda like a SAX parser (in fact it's using SAX in behind the scenes). So you feed a rules engine some XPath for nodes you are interested in and setup rules which will instantiate, and set properties on some POJOs with data it finds in the XML file.

Great idea, and once you get used to it it's good, however if you have an xsd for your input xml file I'd sooner recommend you use JAXB.

The one thing that is nice about Digester is it will only do things with elements you are interested in, so memory footprint ends up being nice and low.

ThaDon
A: 

They used it at my last gig and all I remember is that it was extremely slow.

Javamann