[jdom-interest] SAXBuilder again
donaldp at mad.scientist.com
donaldp at mad.scientist.com
Fri Aug 18 23:54:03 PDT 2000
Hi,
I didn't notice if the issue of how to use SAXBuilder in
particular circumstances was resolved. (Namely how to use it
without copy-paste coding when you need to set specific
properties/features of parser).
Three suggestions I can have that would not brake the
current approach but allow subclassing or reuse.
* Make SAXHandler public
* Put in empty template method in build(InputSource
...) that a subclass can implement.
for instance it may be useful to place a method call like
setupParser( parser );
some where in the build. This method would be empty in
SAXBuilder but a class could extend SAXBuilder and set any
required features/properties.
* Also replace "new Blah" pattern with "createBlah" pattern
in SAXHandler. So everywhere where you have some creation
occuring instead you call create method. The create method
then will in turn just call new Blah(...params...). ie
instead of
Element element =
new Element(name, prefix, getNamespaceURI(prefix));
you would have
Element element =
createElement(name, prefix, getNamespaceURI(prefix));
and then a protected member function createElement like
protected Element createElement( String name,
String prefix,
Namespace namespace )
throws JDOMException
{
return new Element( name, prefix, namespace );
}
The reason for this is that a user of JDOM may wish to use
sub-classes of Element in a particular case. For instance I
have recently come across the need for read-only
configuration trees. To work with JDOM it would mean I would
have to sub-class all elements and make them throw
exceptions on mutate efforst. I would also have to
completely rewrite the handler and SAXBuilder (assuming I
wanted to uses schema validation).
Opinions ?
--
Cheers,
Pete
*--------------------------------------------------*
| Latrobe University, | Does the name 'Pavlov' |
| Bundoora, Australia | ring a bell ? |
*--------------------------------------------------*
More information about the jdom-interest
mailing list