[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: ModSAX (SAX 1.1) Proposal

  • From: David Megginson <david@m...>
  • To: "XML Developers' List" <xml-dev@i...>
  • Date: Tue, 23 Feb 1999 10:41:19 -0500 (EST)

change sax handler
James Clark writes:

 > My point is it doesn't stop you doing:
 > 
 > public class PingHandler implements ModHandler { }
 > 
 > ModParser parser;
 > 
 > parser.setHandler("org.xml.sax.namespace", new PingHandler());
 > 
 > Declaring the second argument to be of type ModHandler doesn't ensure
 > that it is of the correct type.  It's not type-safe.

Precisely, and this is really the critical design decision for the
basic architecture of ModSAX.  To put the problem succinctly, we are
forced to trade-off type safety and flexibility/modularity to some
degree:

1. Using inheritance allows strict typing but breaks
   chain-of-reponsibility, since every driver has to know about every
   interface, and breaks maintainability, since everything has to fall 
   into a single inheritance tree.

2. Using runtime discovery (handlerID, etc.) breaks strict typing but
   allows chain-of-responsibility and greatly simplifies
   maintainability (we probably won't need another major SAX release
   when the schema group finishes datatyping, for example).

The arguments for both are good; my proposal is that we use an empty
interface (ModHandler) to allow at least *some* type checking, but
that we require the drivers to do some of the type-checking themselves
(or simply try to cast and let the exceptions bubble up).  This isn't
too big a burdon, since it falls on the drivers (few) rather than the
applications (many).  For example, here's how a typical filter might
deal with a handler (assuming a helper class ModFilterImpl):

  public class PingFilter extends ModFilterImpl
  {
    public void setHandler (String handlerID, ModHandler handler)
      throws SAXNotSupportedException
    {
      if (handlerId.equals("http://www.megginson.com/sax/handlers/ping")) {
        this.handler = (PingHandler)handler;
      } else {
        getParentParser().setHandler(handlerID, handler);
      }
    }
  }

The casting will throw a runtime exception if handler is not actually
of type PingHandler; a clever driver could trap that and do something
informative with it, but it is still not as good as catching the
problem at compile time; on the other hand, people will be able to
invent many new, interesting filters and drivers for SAX without
waiting for me to change the core distribution.


All the best,


David

-- 
David Megginson                 david@m...
           http://www.megginson.com/

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev@i...
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo@i... the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo@i... the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa@i...)


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.