OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: SAX2: Handler Interfaces

[ Lists Home | Date Index | Thread Index ]
  • From: "Ean R . Schuessler" <ean@novare.net>
  • To: xml-dev@xml.org
  • Date: Thu, 16 Mar 2000 21:03:20 -0600

Not that I agree with this arguement, but you could almost carry this to the
point of just making all the Handlers a type of Property. Then you could get
and set them by their URIs. Again, not that I advocate that necessarily.

On Wed, Mar 15, 2000 at 10:30:54AM -0800, Box, Don wrote:
> I don't think I made myself clear. I wasn't advocating a change to any of
> the XXXHandler interfaces nor to DefaultHandler. Rather, I was questioning
> why XMLReader needs a separate "setter" for both ContentHandler and
> LexicalHandler (and arguably DTDHandler and EntityResolver). The only reason
> to use separate "setters" is to allow someone to use a separate object per
> interface. However, it is hard to imagine someone calling setLexicalHandler
> without also calling setContentHandler. Similar (but somewhat less
> compelling) arguments could be made for DTDHandler and EntityResolver.
> 
> Imagine an implementation of XMLReader that looked like this:
> 
> class MyReader implements XMLReader {
>   ContentHandler ch;
>   DTDHandler     dh;
>   EntityResolver er;
>   LexicalHandler lh;
> 
>   public void setHandler(ContentHandler h) {
>     dh = null;
>     er = null;
>     lh = null;
>     ch = h;
>     if (h instanceof DTDHandler)
>       dh = (DTDHandler)h;
>     if (h instanceof LexicalHandler)
>       lh = (LexicalHandler)h;
>     if (h instanceof EntityResolver)
>       er = (EntityResolver)h;
>   }
> }
> 
> If you don't like the casts (which are a cornerstone of interface-based
> programming in Java, COM and CORBA), one could add a specific "getter"
> method to content handler:
> 
>   public abstract Object getHandler(String interfaceName);
> 
> which would change the method above to look like this:
> 
>   public void setHandler(ContentHandler h) {
>     ch = h;
>     dh = (DTDHandler)h.getHandler("org.xml.sax.DTDHandler");
>     lh = (LexicalHandler)h.getHandler("org.xml.sax.LexicalHandler");
>     er = (EntityResolver)h.getHandler("org.xml.sax.EntityResolver");
>   }
> 
> One of my main motivations for proposing this change is that I would like to
> see the role of XMLReader reduced. Ideally, passing around a ContentHandler
> reference should allow me to have sufficient information to "transmit" an
> entire XML Document. The way SAX2 sits now, I must pass around an XMLReader
> in order to give you a way to "discover" the four required interfaces. THis
> also means I'm passing around an object reference with methods like
> "setXXXHandler" and "parse", neither of which make sence. 
> 
> In summary, my request is that we refactor in order to have a single object
> reference from which I can discover all four handler/resolver interfaces. 

-- 
__________________________________________________________________
Ean Schuessler                                 A guy running Linux
Novare International Inc.                  A company running Linux
*** WARNING: This signature may contain jokes.

***************************************************************************
This is xml-dev, the mailing list for XML developers.
To unsubscribe, mailto:majordomo@xml.org&BODY=unsubscribe%20xml-dev
List archives are available at http://xml.org/archives/xml-dev/
***************************************************************************




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS