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

SAX2: Migration strategies for option (2)

  • From: Miles Sabin <msabin@c...>
  • To: 'XML Developers' List' <xml-dev@i...>
  • Date: Fri, 21 May 1999 13:47:09 +0100

sax2.jar download
I've been giving some thought to how we could go about
making the transition from SAX1 to SAX2 as painless as
possible if we were to take David's option (2): adding
new methods to existing interfaces.

As far as I can make out the following might be the
best bet. We'll need to use a marker interface, but
it's not used in _quite_ the same way as in some of the
other proposals that have been made over the last few
days. It's defined as follows,

  public interface SAX2
  {
  }

All SAX2 parser implementations should implement this
interface, ie.,

  public class MySAX2Parser
    implements Parser, SAX2
  {
    // etc.
  }

Now, we migrate in one of two ways, depending on what
guarantees we can make about which Java platform we're
working with.

1. Where a SAX2 client application can *guarantee* that 
   it's running on the Java 2 platform it uses a 
   version of SAX2 implemented along the lines I 
   discussed in,

   http://www.lists.ic.ac.uk/hypermail/xml-dev/9905/0425.html

   This allows those fortunate enough to be able to
   specify Java 2 to have perfect forwards and backwards
   compatibility between SAX1 and SAX2.

   Invoking such an application would be done something
   like this,

     java \        (a)          (b)              (c)
       -classpath SAX2.jar:SAX2ClientApp.jar:SAXParser.jar \
       SAXClientMain

   Where,
     (a) SAX2.jar contains the SAX2 classes and 
         interfaces, incorporating the adapter mechanism 
         I outlined.

     (b) SAX2ClientApp is the SAX2 client.

     (c) SAXParser.jar is a SAX parser. This could be 
         either a SAX1 or a SAX2 parser, and it makes no 
         difference whether or not the SAX1/2 classes 
         and interfaces are bundled in with it in the 
         same jar.

   References to the SAX classes and interfaces will 
   resolve to the versions present in SAX2.jar, even 
   those made from a SAX1 parser, because SAX2.jar 
   apprears on the classpath first.

2. Where a SAX2 client application can *not* guarantee
   that it is running on the Java 2 platform *and*
   it desires compatibility with SAX1, it should use
   whatever SAX classes and interfaces come bundled
   with the parser it is run against, and should
   itself be bundled with the SAX2 marker interface
   *only*.

   When creating a Parser SAX2 client apps can test
   for the presence of the marker interface and act
   accordingly, ie.

   Parser p = ParserFactory.makeParser(); (*)
   if(p instanceof SAX2) // (**)
   {
     // do SAX2 stuff
   }
   else
   {
     // do SAX1 stuff
   }

   The use of the SAX classes and interfaces bundled
   with the parser (whichever SAX version it conforms 
   to) ensures that at (*) it will be possible to 
   instantiate a Parser irrespective of JDK version.

   The presence of the marker interface on the classpath 
   ensures that the line marked (**) will not fail with
   a ClassNotFoundException.

   The use of the marker interface is preferable to
   catching NoSuchMethodErrors, both from the
   maintainability/comprehensibility, and from the
   efficiency points of view.

Note that both (1) and (2) are transitional strategies.
We should encourage parser developers to move to SAX2
as soon as possible so that these shenanigans can be
dropped and the SAX2 interface can be deprecated (in
fact we might consider deprecating it from the outset).

Note that there is no comparable problem with 
combinations of SAX1 *clients* with SAX2 parsers: the 
only SAX2 interface which is being modified is Parser
and that will not (normally? ever?) be implemented in
the client. Consequently the IncompatibleClassChange
problem that I highlighted in,

  http://www.lists.ic.ac.uk/hypermail/xml-dev/9905/0465.html

will not occur.

Cheers,


Miles

-- 
Miles Sabin                          Cromwell Media
Internet Systems Architect           5/6 Glenthorne Mews
+44 (0)181 410 2230                  London, W6 0LJ
msabin@c...           England

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.