If the "type" attribute in your XML were the fully qualified class name of
the implementation class, you could use a standard ObjectCreateRule for
this.  If it's not (and that sounds like the case here), then a
FactoryCreateRule is what you'd want to use, passing in an appropriate
instance of an ObjectCreationFactory that will do the appropriate object
instantiation for you.

I don't use the XML syntax much, but it looks like you should be able to
say:

  <factory-create-rule classname="com.mypackage.MyFactory"/>

where the "MyFactory" class must implement ObjectCreationFactory and do
the appropriate object creation in its createObject() method based on the
"type" attribute that is passed in.

Craig


On Fri, 7 Feb 2003, Maher Martin wrote:

> Date: Fri, 7 Feb 2003 11:17:02 +0100
> From: Maher Martin <[EMAIL PROTECTED]>
> Reply-To: Jakarta Commons Users List <[EMAIL PROTECTED]>
> To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
> Subject: Digester Creational Rule Question
>
> Hi,
>
> I've looked through all the examples I could find on using the Digester and
> till now I haven't come across any way or instantiating a specific Bean
> class depending on an attribute within the pattern of the element I'm
> matching against. To explain what I'm trying to do consider the scenario
> below:
>
> --------------
>
> I've the following class structure
>
> class BaseInput {}
>
> class InputTypeX extends BaseInput {}
>
> class InputTypeY extends BaseInput {}
>
> --------------
>
> and the following XML structure
>
> <root>
>       <input type="X">
>               ...
>       </input>
>
>       <input type="Y">
>               ...
>       </input>
>
>       <input type="X">
>               ...
>       </input>
> </root>
>
> --------------
>
> What I would like to do is during pattern matching, instantiate the correct
> bean class depending on the input type. If the input contains the type="X"
> then I want to instantiate the bean class "InputTypeX" and so on. Is this
> possible with digester when specifying rules within an XML file? I know one
> way of doing this would be to rename the <input> element to <input-x> or
> <input-y> and instantiate the class based on the element name, but I want to
> try and avoid this if possible.
>
> tia,
>
> Martin Maher
>
> ___________________________________________________________
> Webasto Informationssysteme GmbH
> Department TTI
> Gautinger Sta�e 23
> D-82131 Stockdorf
>
> Phone: (+49) (0)89 85794 1851
> Fax: (+49) (0)89 899214 1851
> mailto:[EMAIL PROTECTED]
> http://www.webasto.de
> ___________________________________________________________
>
>  <<Maher Martin.vcf>>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to