Digester: Problem with CallMethodRule

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Digester: Problem with CallMethodRule

Mikko Nylén
Hi!,

I'm having a little problem with Digester's CallMethodRule: it doesn't
call the method.

The XML file I try to parse is:

---
<configuration>
  <pages>
    <page path="/index.htm" class="test.TestPage" />
    <page path="/hello.htm" class="test.HelloPage" />
  </pages>
</configuration>
---

The Java code I'm trying to use for parsing the configuration:

---
...
Digester digester = new Digester();
digester.addObjectCreate("configuration", "test.Configuration");
digester.addObjectCreate("configuration/pages/page",
"test.PageConfiguration");
digester.addSetProperties("configuration/pages/page", new
String[]{"path", "class"}, new String[]{"path", "className"});
digester.addCallMethod("configuration/pages/page", "freeze");
digester.addSetNext("configuration/pages/page", "addPageConfiguration",
"test.PageConfiguration");

Configuration configuration = (Configuration)digester.parse(reader);
---

The problem is that the freeze() method of instantiated
PageConfiguration objects isn't ever called (which results to that the
Configuration's addPageConfiguration(PageConfiguration) throws an
IllegalStateException). How I should fix this? I'm using the version 1.7
of Digester.

- Mikko Nyl?n

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Digester: Problem with CallMethodRule

Simon Kitching
On Mon, 2005-09-05 at 07:18 +0300, Mikko Nyl?n wrote:

> Hi!,
>
> I'm having a little problem with Digester's CallMethodRule: it doesn't
> call the method.
>
> The XML file I try to parse is:
>
> ---
> <configuration>
>   <pages>
>     <page path="/index.htm" class="test.TestPage" />
>     <page path="/hello.htm" class="test.HelloPage" />
>   </pages>
> </configuration>
> ---
>
> The Java code I'm trying to use for parsing the configuration:
>
> ---
> ...
> Digester digester = new Digester();
> digester.addObjectCreate("configuration", "test.Configuration");
> digester.addObjectCreate("configuration/pages/page",
> "test.PageConfiguration");
> digester.addSetProperties("configuration/pages/page", new
> String[]{"path", "class"}, new String[]{"path", "className"});
> digester.addCallMethod("configuration/pages/page", "freeze");
> digester.addSetNext("configuration/pages/page", "addPageConfiguration",
> "test.PageConfiguration");
>
> Configuration configuration = (Configuration)digester.parse(reader);
> ---
>
> The problem is that the freeze() method of instantiated
> PageConfiguration objects isn't ever called (which results to that the
> Configuration's addPageConfiguration(PageConfiguration) throws an
> IllegalStateException). How I should fix this? I'm using the version 1.7
> of Digester.

Are you sure the problem isn't the *order* that methods get called for
element "configuration/pages/page" rather than that the freeze method
doesn't get called at all?

I suggest reading the FAQ entry titled "How do I get CallMethodRule to
fire before SetNextRule?" here:
  http://wiki.apache.org/jakarta-commons/Digester/FAQ

Regards,

Simon



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Digester: Problem with CallMethodRule

Mikko Nylén
Simon Kitching wrote:

>On Mon, 2005-09-05 at 07:18 +0300, Mikko Nyl?n wrote:
>  
>
>>Hi!,
>>
>>I'm having a little problem with Digester's CallMethodRule: it doesn't
>>call the method.
>>
>>The XML file I try to parse is:
>>
>>---
>><configuration>
>>  <pages>
>>    <page path="/index.htm" class="test.TestPage" />
>>    <page path="/hello.htm" class="test.HelloPage" />
>>  </pages>
>></configuration>
>>---
>>
>>The Java code I'm trying to use for parsing the configuration:
>>
>>---
>>...
>>Digester digester = new Digester();
>>digester.addObjectCreate("configuration", "test.Configuration");
>>digester.addObjectCreate("configuration/pages/page",
>>"test.PageConfiguration");
>>digester.addSetProperties("configuration/pages/page", new
>>String[]{"path", "class"}, new String[]{"path", "className"});
>>digester.addCallMethod("configuration/pages/page", "freeze");
>>digester.addSetNext("configuration/pages/page", "addPageConfiguration",
>>"test.PageConfiguration");
>>
>>Configuration configuration = (Configuration)digester.parse(reader);
>>---
>>
>>The problem is that the freeze() method of instantiated
>>PageConfiguration objects isn't ever called (which results to that the
>>Configuration's addPageConfiguration(PageConfiguration) throws an
>>IllegalStateException). How I should fix this? I'm using the version 1.7
>>of Digester.
>>    
>>
>
>Are you sure the problem isn't the *order* that methods get called for
>element "configuration/pages/page" rather than that the freeze method
>doesn't get called at all?
>
>I suggest reading the FAQ entry titled "How do I get CallMethodRule to
>fire before SetNextRule?" here:
>  http://wiki.apache.org/jakarta-commons/Digester/FAQ
>
>Regards,
>
>Simon
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [hidden email]
>For additional commands, e-mail: [hidden email]
>
>
>  
>
Thanks! That FAQ entry solved the problem.

- Mikko Nyl?n

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]