You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Martin Cooper <ma...@tumbleweed.com> on 2002/03/03 08:41:01 UTC
[Digester] How can Digester create objects whose class is defined in the XML?
I need to be able to specify the class to be instantiated for an element
from an attribute on its parent element. For example, I need to have
Digester handle the following:
<action-mappings type="com.foo.bar.MyClass">
<action ... />
<action ... />
</action-mappings>
Here, each ObjectCreate for an <action> element needs to create an object of
the class specified by the 'type' attribute of the <action-mappings>
element. After the object has been created, its own attributes would be
populated using addSetProperties(). There is no object created for the
<action-mappings> element.
I have a feeling that this is going to involve a FactoryCreateRule of some
sort. However, I haven't quite got my head around this type of rule yet to
figure this out.
Ideas, anyone?
Thanks!
--
Martin Cooper
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: [Digester] How can Digester create objects whose class is defined in the XML?
Posted by robert burrell donkin <ro...@mac.com>.
hi martin
On Sunday, March 3, 2002, at 07:41 AM, Martin Cooper wrote:
> I need to be able to specify the class to be instantiated for an element
> from an attribute on its parent element. For example, I need to have
> Digester handle the following:
>
> <action-mappings type="com.foo.bar.MyClass">
> <action ... />
> <action ... />
> </action-mappings>
>
> Here, each ObjectCreate for an <action> element needs to create an object
> of
> the class specified by the 'type' attribute of the <action-mappings>
> element. After the object has been created, its own attributes would be
> populated using addSetProperties(). There is no object created for the
> <action-mappings> element.
>
> I have a feeling that this is going to involve a FactoryCreateRule of some
> sort. However, I haven't quite got my head around this type of rule yet to
> figure this out.
>
> Ideas, anyone?
there are at least two ways to be this kind of thing.
probably the easiest is something like
digester.addFactoryCreate("root/action", DefaultObject.class, "type")
(an instance of class DefualtObject will be created whenever the attribute
isn't present).
- robert
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>