[jdom-interest] Custom XML outputter
guru at stinky.com
guru at stinky.com
Sun Jun 17 12:44:51 PDT 2001
On Fri, Jun 15, 2001 at 06:48:45PM -0700, Jason Hunter wrote:
> Krishnan Anantheswaran wrote:
> >
> > For obvious reasons I don't want to perform such
> > hacks. Is there any possibility that the
> > NamespaceStack class can be made public in a future
> > release? Is it the intent of the JDOM designers to let
> > developers subclass the XMLOutputter?
>
> One goal is to make XMLOutputter something that can be subclassed.
> Another goal is to not have a proliferation of public classes. Here the
> goals are at odds, and we've been wondering what to do about it. Note
> it's in the TODO.
I believe this can be fixed by making a protected inner class of
XMLOutputter called XMLOutputter.NamespaceStack. This will be a null
subclass of the regular NamespaceStack, except that, due to
inheritance access rules, subclasses of XMLOutputter outside the
package will be able to declare and access it.
We can then do the same for SAXOutputter and DOMOutputter.
This only works because the different outputters don't need to share
individual stacks -- the stacks are just passed around internally to a
single instance (created and destroyed during its output method).
It's a little fishy, but perfectly legal, and doesn't actually bypass
Java access rules (like you can do in C++) -- a different class, even
one in the same package as the outputter subclass, can not access it,
even if the subclass declares it public. At least that's what my
tests say, and I'm pretty sure the language spec and VM
implementations support this.
There, I just did it for XMLOutputter. Thanks to compiler magic, I
didn't even have to change any code (other than declaring the inner
class).
public class XMLOutputter {
...
protected class NamespaceStack extends org.jdom.output.NamespaceStack
{
}
}
Got any more bugs for me? :-)
- A
P.S. If I ever get my network card working again, I'll post a full diff.
--
Alex Chaffee mailto:alex at jguru.com
jGuru - Java News and FAQs http://www.jguru.com/alex/
Creator of Gamelan http://www.gamelan.com/
Founder of Purple Technology http://www.purpletech.com/
Curator of Stinky Art Collective http://www.stinky.com/
More information about the jdom-interest
mailing list