Hi all,
I'm fairly new to this Component Oriented Programming stuff, and I tend to overuse
design principles when I first become aware of them.
I am taking on the task of building a messaging server using the java.nio.*
non-blocking API and XML as the underlying communications protocol. I thought that it
would be cool to use SAX since it is an event-driven interface. However, although SAX
is an event driven API, XMLReader and InputSource define only synchronous operations.
This is unfortunate because it means that I will have to use a pool of multiple
threads for my SAX parsing (unless I build my own parser implementation). I would
like to hide this implementation detail, however, behind a component interface.
This is where I get back to my relevant question. Although I am familiar with
interface/implementation programming practices, I am unfamiliar with "best-practice"
approaches for defining COP component interfaces. I have included my attempt below.
Please comment.
import java.nio.channels.Pipe;
import org.apache.excalibur.xml.sax.XMLConsumer;
public interface AsynchXMLProcessor {
String ROLE = AsynchXMLProcessor.class.getName();
Pipe.Sink getByteSink();
void setSourceConsumer(XMLConsumer consumer);
void setSourceErrorHandler(XMLErrorHandler errorHandler);
}
public interface XMLErrorHandler extends org.xml.sax.ErrorHandler {
public void fatality(Throwable t);
}
One criticism I have for the AsynchXMLProcessor is that is not thread-safe and it does
not pool well. I would probably need a factory interface instead of looking up the
processor directly from the ServiceManager. Another thought is that I could change
the interface as below. However, this seems less flexible to me in terms of adding
future features (eg. a DTDHandler).
public interface AsynchXMLProcessor {
String ROLE = AsynchXMLProcessor.class.getName();
Pipe.Sink getByteSink(XMLConsumer consumer, XMLErrorHandler errorHandler);
}
Thanks all!
Jonathan Hawkes