Overhead of creating a new XML serializer is totally insignificant compared to the cost of I/O for just one element. But still, you want to think generic and reuse stuff, and I'm not sure PDF or PNG serializers would be so simple.
So it's really a matter of reset vs. close, application pooling vs. serializer factory pooling. arkin Keith Visco wrote: > > Ahh ok...Well personally I like #reset() better than #close(). Close > seems to final to me. > > Currently I just create a new Serializer all the time...if the overhead > for creating a Serializer is minimal then it doesn't really matter to me > how it's done...#reset(), or new instance. > > --Keith > > Assaf Arkin wrote: > > > > When the depth tree drops back to 0, the serializer assumes you're done > > for the day and flushes the output. > > > > But, it doesn't assume you're starting a new document, which is nice if > > you print multiple nodes in the same document (i.e. not single root > > element). Why would you want to do that? To serialize an external > > entity. > > > > There's also a question of who gets to pool the serializer. Is it the > > application, by hanging on to it and just resetting it (in which case > > reset() should be made public), or is it the SerializerFactory by > > maintaining an internal pool of serializers, in which case you have to > > call close() on the serializer. > > > > Either one will work with the current implementation, but the jury is > > still out on which method it should be. Comments are more than welcome. > > > > arkin > > > > Keith Visco wrote: > > > > > > My thoughts.... > > > > > > When the depth of the tree drops back to 0 (ie. the root element is > > > finished printing) The serializer should reinitialize itself. I don't > > > like to rely on a call to #endDocument, though there is nothing wrong > > > with forcing a user to do so if necessary. > > > > > > I don't think a Serializer needs to be thread safe since that won't make > > > much sense in the event world of SAX, but I see nothing wrong with > > > making a serializer reusable. > > > > > > --Keith > > > > > > Arnaud Le Hors wrote: > > > > > > > > Assaf Arkin wrote: > > > > > > > > > > By definition a serializer is good for printing just one document, and > > > > > it prints just one document. > > > > > > > > "By definition"? Sorry, I don't understand. Do you actually simply mean > > > > that you didn't design/implement the serializer to print more than one > > > > document? It that's it, I can understand (even though I think it's > > > > unfortunate ;-). > > > > > > > > > Although it's possible to print two documents with domSerializer, I'm > > > > > not sure if it makes sense with a DocumentHandler/ContentHandler, so I > > > > > would advise against it. > > > > > > > > Could you expand on this a bit and tell us why? For one thing, people > > > > expect to be able to reuse the parser, so why would it be unreasonable > > > > to expect the same from the serializer? > > > > Thanks. > > > > -- > > > > Arnaud Le Hors - IBM Cupertino, XML Technology Group > > > > -- > > ---------------------------------------------------------------------- > > Assaf Arkin www.exoffice.com > > CTO, Exoffice Technologies, Inc. www.exolab.org -- ---------------------------------------------------------------------- Assaf Arkin www.exoffice.com CTO, Exoffice Technologies, Inc. www.exolab.org
