[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Java-Specific Question
On Friday, April 03, 1998 5:44 PM, David Megginson [SMTP:ak117@f...] wrote: > Here's a Java question. Let's say that I have a class with a method > > public void parse (String publicId, String systemId, Reader reader) > throws java.lang.Exception; > > What will happen if the "java.io.Reader" class is not available on my > system (perhaps because I'm using a 1.0.2 browser), but I never invoke > this method (I'm assuming that I compiled my code under JDK 1.1 or JDK > 1.2)? The JavaVM will throw a ClassNotFoundException because it will try to preload the class in case you do use the method. > I'm becoming convinced that we need to support character streams in > SAX, and I'm trying to figure out how to handle it in the Java > version -- I think that I've worked out pretty much everything else > now, except for a few minor details. I'm dealing with a similar problem on an applet at work where I need to be able to support the Java Media Framework for sound if available. My solution is to abstract everything that references the possibly missing classes into a second class, then in build an initialization routine like the following: Class parserClass; // used if creating several Parser objects Parser parser = null; // Parser is an abstract class or interface // Used if only need one parser void init() { try { Class.forName( "java.io.Reader" ); // checks if supported parserClass = Class.forName( "MyParserFor11" ); } catch( ClassNotFoundException err ) { parserClass = Class.forName( "MyParserFor10" ); } try { parser = (Parser) parserClass.newInstance(); } catch( InstantiationException err ) { // Constructor requires argument } catch( IllegalAccessException err ) { // Constructor isn't public } } NOTE: Apparently my understandings reflected Don Park's >>original<< message which is apparently wrong. But even so, the above will still work. Andrew n marshall student - artist - programmer http://www.media-electronica.com/anm-bin/anm "Everyone a mentor, Everyone a pupil" |
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|