Hello everyone,
I am trying to use Digester to load a Properties object from an XML file. When
I run the parse method off of the Digester object, the Object that is returned
doesn't have anything in it. I am not sure if this is a bug or that I am
missing something in the implementation. Here is my code:
//create digester based on the rules
digester = DigesterLoader.createDigester(rulesUrl);
//add properties to object stack --
//this is so you can get the properties object that was created
digester.push(result);
//parse xml files against rules
result = (Stack)digester.parse(propertiesXml);
//get properties object
props = (Properties)result.pop();
-----------------------
My rules xml files looks like this:
<digester-rules>
<pattern value="NamingResources">
<!--create a Stack object to hold a reference to the Properties object
created
in the 'ResourceParams' pattern -->
<object-create-rule classname="java.util.Stack"/>
<pattern value="ResourceParams">
<!-- instantiate a Properties object -->
<object-create-rule classname="java.util.Properties"/>
<!-- each parameter node is a key-value pair in the Properties
object -->
<pattern value="parameter">
<!-- call the 'setProperty' method -->
<call-method-rule methodname="setProperty"
paramcount="2"/>
<call-param-rule pattern="name" paramnumber="0"/>
<call-param-rule pattern="value" paramnumber="1"/>
</pattern>
<!-- push the Properties object created onto the Stack object
-->
<set-next-rule methodname="push" />
</pattern>
</pattern>
</digester-rules>
-----------------------
The following excepts from the log generated so that all the pieces seem to be
functioning:
2004/08/31 17:48:01 DEBUG org.apache.commons.digester.Digester - Popping params
2004/08/31 17:48:01 DEBUG org.apache.commons.digester.Digester -
[CallMethodRule](0)testWhileIdle
2004/08/31 17:48:01 DEBUG org.apache.commons.digester.Digester -
[CallMethodRule](1)false
2004/08/31 17:48:01 DEBUG org.apache.commons.digester.Digester -
[CallMethodRule]{NamingResources/ResourceParams/parameter} Call
java.util.Properties.setProperty(testWhileIdle/java.lang.String,false/java.lang.String)
2004/08/31 17:48:01 DEBUG org.apache.commons.beanutils.MethodUtils - Matching
name=setProperty on class java.util.Properties
2004/08/31 17:48:01 DEBUG org.apache.commons.beanutils.MethodUtils - Found
straight match: public synchronized java.lang.Object
java.util.Properties.setProperty(java.lang.String,java.lang.String)
2004/08/31 17:48:01 DEBUG org.apache.commons.beanutils.MethodUtils -
isPublic:true
...
2004/09/01 09:07:19 DEBUG org.apache.commons.beanutils.MethodUtils - Matching
name=push on class java.util.Stack
2004/09/01 09:07:19 DEBUG org.apache.commons.beanutils.MethodUtils - Found
matching name:
2004/09/01 09:07:19 DEBUG org.apache.commons.beanutils.MethodUtils - public
java.lang.Object java.util.Stack.push(java.lang.Object)
2004/09/01 09:07:19 DEBUG org.apache.commons.beanutils.MethodUtils -
Param=java.util.Properties
2004/09/01 09:07:19 DEBUG org.apache.commons.beanutils.MethodUtils -
Method=java.lang.Object
2004/09/01 09:07:19 DEBUG org.apache.commons.beanutils.MethodUtils - public
java.lang.Object java.util.Stack.push(java.lang.Object) accessible version of
public java.lang.Object java.util.Stack.push(java.lang.Object)
...
2004/09/01 09:07:19 DEBUG org.apache.commons.digester.Digester -
[ObjectCreateRule]{NamingResources} Pop java.util.Stack
-----------------------
Any help would be greatly appreciated.
Thanks,
Andrew.
--
Andrew Steiger
EMail: [EMAIL PROTECTED]
Web: http://www.andrewsteiger.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]