[jdom-interest] Abstracting interface to JDOM nodes.

Trebor A. Rude trebor at bwn.net
Sat Aug 26 09:08:54 PDT 2000


On Sat, 26 Aug 2000, Elliotte Rusty Harold wrote:
>At 4:50 PM -0600 8/25/00, Trebor A. Rude wrote:
>>	I want to write getSerializedForm() for Element.  However, to
>>do this, it
>>needs to be able to call getSerializedForm() on its children. This can
>> not easily be done since the children vary in their type, and don't
>> implement a common interface. I propose such a common interface be
>> created, an equivelent of Node in the org.w3c.dom package. I'm willing
>> to do the work, but I'd like comments from the crowd as to whether or
>> not this is a good idea, and if so, what should and shouldn't go in
>> such an interface.
>
>1. getSerializedForm() is going away to be replaced by the
>XMLOutputter class. Don't use it or waste your time on it.

	Strange, the more recent versions in the CVS have been getting closer to 
completing the getSerializedForm() functionality. It certainly would have 
been easier for what I wanted to use it for (getting the minimalistic XML 
representation for passing across CORBA). What's the proper usage of the 
XMLOutputter for that use case, something like this:

XMLOutputter xmlWriter = new XMLOutputter("", false);
ByteArrayOutputStream byteRep = new ByteArrayOutputStream();
xmlWriter.output(someDocument, byteRep);
String stringRep = byteRep.toString();

	That seems like an incredible pain, but I'm probably missing something 
since I'm not terribly familiar with the java io libraries (most of my 
work has been in my project's wrappers around CORBA, almost no direct io 
stuff). By my understanding, getting the XML representation of just an 
Element would be even worse, since there would have to be a PrintWriter 
involved. Seems like an awful lot of objects for what could have been 
accomplished by a single method call with getSerialzedForm().

>2. You don't need a common interface. instanceof works just fine for
>this use case.

	So I'd have to have a separate instanceof test for all the different 
types of nodes? That seems terribly inelegant to me. Interfaces were 
designed to prevent just that kind of thing.

-- 
Trebor A. Rude
trebor at bwn.net
Registered Linux User #89308
http://counter.li.org/



More information about the jdom-interest mailing list