commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <si...@ecnetwork.co.nz>
Subject RE: Digester Examples
Date Thu, 23 Jan 2003 00:46:45 GMT
Hi Jay,

Just to expand a bit on Scott's reply.

Your question is a fairly common one. I'm not aware of any documentation
that shows how to do this, and there probably should be some. Maybe when
you get this working you could contribute some docs and an example?

Regarding *how* to do it, 
(a) write a class that extends
org.apache.commons.Digester.AbstractObjectCreationFactory and implements
the abstract "createObject" method. The prototype for that method should
tell you all you need to know.
(b) pass your custom factory class name to the
Digester.addFactoryCreate(String pattern, String className) method.

Note that this approach allows you to pass either constants (hard-wired
into your factory class) or attributes on the matched tag to the object
constructor.

If you want to pass arbitrary values known to your program into the
constructor (eg a reference to some object created before the config
file parsing starts) then you need to look at the method
 addFactoryCreate(String pattern, ObjectCreationFactory factory)
which allows you to create the factory yourself (with any desired
params) before starting the digester.

If you want to use *child* elements when constructing an object, I
believe this is not possible with the Digester. Because the Digester is
based upon SAX, not DOM, the child elements haven't even been parsed at
the time the start-tag triggers the rule which creates the object
associated with the "parent" tag.

Regards,

Simon


On Thu, 2003-01-23 at 13:19, Scott Sanders wrote:
> To do anything other than a default no args constructor, you need to
> create an ObjectFactoryRule, where your factory can create the object by
> pulling all of the information from the stack.
> 
> Scott
> 
> > -----Original Message-----
> > From: Jay Wright [mailto:jwright@once.com] 
> > Sent: Wednesday, January 22, 2003 3:28 PM
> > To: 'commons-user@jakarta.apache.org'
> > Subject: Digester Examples
> > 
> > 
> > 
> > I'm trying to get an understanding of the Digester and have 
> > found a few articles on-line with good examples, but of 
> > course, they are all basic implementations.
> > 
> > Is there a good example someone could post or point me to for 
> > creating an object whose constructor takes a couple 
> > parameters?  Perferably, one that is an attribute of the 
> > element itself, the other a  child object of the element.
> > 
> > This seems to be a common question, yet there are no 
> > demonstrable examples to reference.
> > 
> > Thanks,
> > Jay
> > 
> > 
> > --
> > To unsubscribe, e-mail:   
> > <mailto:commons-user-> unsubscribe@jakarta.apache.org>
> > For 
> > additional commands, 
> > e-mail: <mailto:commons-user-help@jakarta.apache.org>
> > 
> > 
> 
> --
> To unsubscribe, e-mail:   <mailto:commons-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:commons-user-help@jakarta.apache.org>
> 
> 


Mime
View raw message