protected void checkSAXVersion ( Hashtable h ) { if ( null == h ) h = new Hashtable ( ) ; final String SAX_VERSION1_CLASS = "org.xml.sax.Parser" ; final String SAX_VERSION1_METHOD = "parse" ; // String final String SAX_VERSION2_CLASS = "org.xml.sax.XMLReader" ; final String SAX_VERSION2_METHOD = "parse" ; // String final String SAX_VERSION2BETA_CLASSNF = "org.xml.sax.helpers.AttributesImpl" ; final String SAX_VERSION2BETA_METHODNF = "setAttributes" ; // Attributes final Class oneStringArg [ ] = { java . lang . String . class } ; // Note this introduces a minor compile dependency on SAX... final Class attributesArg [ ] = { org . xml . sax . Attributes . class } ; try { // This method was only added in the final SAX 2.0 release; // see changes.html "Changes from SAX 2.0beta2 to SAX 2.0prerelease" Class clazz = ObjectFactory . findProviderClass ( SAX_VERSION2BETA_CLASSNF , ObjectFactory . findClassLoader ( ) , true ) ; Method method = clazz . getMethod ( SAX_VERSION2BETA_METHODNF , attributesArg ) ; // If we succeeded, we have loaded interfaces from a // real, final SAX version 2.0 somewhere h . put ( VERSION + "SAX" , "2.0" ) ; } catch ( Exception e ) { // If we didn't find the SAX 2.0 class, look for a 2.0beta2 h . put ( ERROR + VERSION + "SAX" , "ERROR attempting to load SAX version 2 class: " + e . toString ( ) ) ; h . put ( ERROR , ERROR_FOUND ) ; try { Class clazz = ObjectFactory . findProviderClass ( SAX_VERSION2_CLASS , ObjectFactory . findClassLoader ( ) , true ) ; Method method = clazz . getMethod ( SAX_VERSION2_METHOD , oneStringArg ) ; // If we succeeded, we have loaded interfaces from a // SAX version 2.0beta2 or earlier; these might work but // you should really have the final SAX 2.0 h . put ( VERSION + "SAX-backlevel" , "2.0beta2-or-earlier" ) ; } catch ( Exception e2 ) { // If we didn't find the SAX 2.0beta2 class, look for a 1.0 one h . put ( ERROR + VERSION + "SAX" , "ERROR attempting to load SAX version 2 class: " + e . toString ( ) ) ; h . put ( ERROR , ERROR_FOUND ) ; try { Class clazz = ObjectFactory . findProviderClass ( SAX_VERSION1_CLASS , ObjectFactory . findClassLoader ( ) , true ) ; Method method = clazz . getMethod ( SAX_VERSION1_METHOD , oneStringArg ) ; // If we succeeded, we have loaded interfaces from a // SAX version 1.0 somewhere; which won't work very // well for JAXP 1.1 or beyond! h . put ( VERSION + "SAX-backlevel" , "1.0" ) ; } catch ( Exception e3 ) { // If we didn't find the SAX 2.0 class, look for a 1.0 one // Note that either 1.0 or no SAX are both errors h . put ( ERROR + VERSION + "SAX-backlevel" , "ERROR attempting to load SAX version 1 class: " + e3 . toString ( ) ) ; } } } }
Report version info from SAX interfaces .