Robert, That'll get me on my way ...
Many thanks. Greg. -----Original Message----- From: robert burrell donkin [mailto:[EMAIL PROTECTED]] Sent: 21 March 2002 20:59 To: Jakarta Commons Developers List Subject: Re: FactoryCreateRule Example? On Thursday, March 21, 2002, at 04:16 PM, Greg McCreath wrote: hi greg > Can anyone point me to where I might might find one of the above. you can find what documentation there is in the org.apache.commons.digester package java doc comments. (documentation patches will be gratefully received.) > I want to have an object created using Digester, but the object will have > two non no-argument constructors, and I want both of them to be recognised > from the XML. As an example of what I want ... > > < commsMessageFormatter class="MyClass" /> > > or > > < commsMessageFormatter class="MyClass" protocolType="ISOxxxx" /> > > or > > < commsMessageFormatter class="MyClass" protocolType="ISOxxxx" > protocolVersion="1.0" /> (i'm going to assume that you're happy(/ier) with the pattern matching rules and talk about using FactoryCreateRule only.) in order to use a FactoryCreateRule you need to make a ObjectCreationFactory implementation. you'll probably want to extend AbstractObjectCreationFactory and just override the createObject method. createObject has the element's attributes passed in. use these to decide which constructor to call. i quite often do is use an anonymous class so it'd probably go something like: digester.addFactoryCreate( "/root/alpha", new AbstractObjectCreationFactory() { public Object createObject(Attributes attributes) { if (attributes.getLength() == 1) { // return object created with single parameter constructor ... } if (attributes.getLength() == 2) { // return object created with double parameter constructor ... } ... } } } hope that's enough to get you started. - robert -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
