Java-Specific Question
Andrew n marshall
amarshal at usc.edu
Sat Apr 4 11:11:19 BST 1998
On Friday, April 03, 1998 5:44 PM, David Megginson
[SMTP:ak117 at freenet.carleton.ca] 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"
xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)
More information about the Xml-dev
mailing list