Leszek Gawron wrote:
I have still some questions though:

1. Can somebody tell me why do we need all these:

protected static final ContentHandler EMPTY_CONTENT_HANDLER = new DefaultHandler();

/** The <code>XMLConsumer</code> receiving SAX events. */
protected XMLConsumer xmlConsumer;

/** The <code>ContentHandler</code> receiving SAX events. */
protected ContentHandler contentHandler = EMPTY_CONTENT_HANDLER;

/** The <code>LexicalHandler</code> receiving SAX events. */
protected LexicalHandler lexicalHandler = DefaultLexicalHandler.NULL_HANDLER;

in AbstractXMLProducer?

I might understand why the need for separate lexicalHandler and contentHandler.

Generally speaking content handler and lexical handler can be different objects. Coincidentally, these interfaces are implemented by single class in both Xalan and Saxon - but it is not guaranteed. In such case xml consumer would be null.


Still why the need for the default value? Why aren't they simply null?

Because we do have at least 224 usages in core of cocoon and none of these usages have a check for null. I'm certain there are usages in blocks as well. It is better to make sure that content handler is initialized once than propagate if (contentHandler != null) all over the place - I think that's the reason.


/**
 * Set the <code>XMLConsumer</code> that will receive XML data.
 * <br>
 * This method will simply call <code>setContentHandler(consumer)</code>
 * and <code>setLexicalHandler(consumer)</code>.
 */
public void setConsumer(XMLConsumer consumer) {
    this.xmlConsumer = consumer;
    setContentHandler(consumer);
    setLexicalHandler(consumer);
}

It looks like we are fulfilling some really old dependencies here...

This method looks fine to me. Consumer does implement both interfaces.


Vadim

Reply via email to