public class BookFactory extends AbstractObjectCreationFactory<Book>
To resolve this issue, the FactoryCreateRule can be used in conjunction with an appropriate factory class, like this one. The "createObject" method of the factory is invoked to generate object instances when required.
The factory object can access any xml attributes, plus of course any values set up within it before digester parsing starts (like JNDI references, database connections, etc) that it may in the process of generating an appropriate object.
Note that it is not possible for any data to be extracted from the body or subelements of the xml element that caused the createObject method on this factory to be invoked. For example:
[book isdn="12345"]is fine; the isdn value can be accessed during the createObject method. However, given the xml:
[book] [isdn]12345[/isdn] ...it is not possible to access the isdn number until after the Book instance has been created.
Note that even if the class to be created does have a default constructor, you may wish to use a factory class, in order to initialise the created object in specific ways, or insert created objects into a central register, etc.
And don't forget, either, that factories may be implemented as inner classes or anonymous classes if appropriate, reducing the overhead of using this functionality in many cases.
|Constructor and Description|
|Modifier and Type||Method and Description|
Factory method called by
public Book createObject(Attributes attributes) throws Exception
FactoryCreateRuleto supply an object based on the element's attributes.
Copyright © 2001-2013 The Apache Software Foundation. All Rights Reserved.