Of course, I am still willing to provide source code to anyone that is interested...
Matthijs.
Matthijs Wensveen wrote:
Hello,
My company uses xml documents and digester to configure their application at start-up. Usually we want a Map of configured objects at the end of application initialization.
A problem we encounter often, is that the xml used in one application differs to the xml used in another application. Sometimes we want to configure DAO's, other times only Property objects, and even other times, MailBeans and some application-specific object. We want to be able to write different pieces of xml that configure the objects without having to modify the digester that parses them.
We would like to contribute our code to the Digester project if possible as we think it might be useful for other developers as well.
A short explanation of how it works follows.
We have written a set of RuleSets that can be plugged into a digester object when needed, so that we can have a repository of often used RuleSets and per-application custom RuleSets. Plugging a RuleSet into the digester is also done in the xml document parsed by Digester, for example:
<?xml version="1.0"?>
<config>
<digester-ruleset class="config.PropertiesRuleSet" pattern="config/properties" />
<digester-ruleset class="config.MailBeanRuleSet" pattern="config/mailbean" />
<!-- Example properties -->
<properties name="example1">
<property key="key1" value="value1" />
<property key="key2" value="value2" />
</properties>
<properties name="example2"> <property key="key1" value="value1" /> <property key="key2" value="value2" /> </properties>
<mailbean name="contactForm" class="ContactFormMail"> <to email="[EMAIL PROTECTED]" name="Its Me" /> </mailbean> </config>
Of course, the definition of the digester-ruleset classes can be done in another xml document.
From the code you would do:
//Get the singleton instance of the ConfigDigester that is used througout the application
ConfigDigester.getInstance().getDigester().parse("config.xml");
//Get the object from the Map of configured objects
Properties exampleProps = (Properties)ConfigDigester.getInstance().getConfigObject("example1");
MailBean contactFormMailBean = (MailBean)ConfigDigester.getInstance().getConfigObject("contactForm");
As you can see, an important aspect is that the MailBean object is kept in the configObject Map, even after being popped of the stack by digester.
Let me know if this is useful for the Digester project, so I can provide the source.
Best regards, Matthijs Wensveen Func. Internet Integration.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
