Make jaxp code compile under JDK 1.1 (it used to only just run on 1.1)

git-svn-id: https://svn.apache.org/repos/asf/xml/commons/trunk@225927 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
edwingo 2001-10-22 22:10:30 +00:00
parent 38a2b89e48
commit 23ce6ff1d8
2 changed files with 74 additions and 91 deletions

View File

@ -64,16 +64,18 @@ import java.util.Properties;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
/** /**
* This class is duplicated for each JAXP subpackage so keep it in * This class is duplicated for each JAXP subpackage so keep it in sync.
* sync. It is package private. * It is package private and therefore is not exposed as part of the JAXP
* API.
* *
* This code is designed to implement the JAXP 1.1 spec pluggability * This code is designed to implement the JAXP 1.1 spec pluggability
* feature and is designed to run on JDK version 1.1 and later including * feature and is designed to both compile and run on JDK version 1.1 and
* JVMs that perform early linking like the Microsoft JVM in IE 5. Note * later. The code also runs both as part of an unbundled jar file and
* however that it must be compiled on a JDK version 1.2 or later system * when bundled as part of the JDK.
* since it calls Thread#getContextClassLoader(). The code also runs both
* as part of an unbundled jar file and when bundled as part of the JDK.
*/ */
class FactoryFinder { class FactoryFinder {
/** Temp debug code - this will be removed after we test everything /** Temp debug code - this will be removed after we test everything
@ -94,35 +96,37 @@ class FactoryFinder {
} }
/** /**
* Figure out which ClassLoader to use. For JDK 1.2 and later use the * Figure out which ClassLoader to use. For JDK 1.2 and later use
* context ClassLoader if possible. Note: we defer linking the class * the context ClassLoader.
* that calls an API only in JDK 1.2 until runtime so that we can catch */
* LinkageError so that this code will run in older non-Sun JVMs such
* as the Microsoft JVM in IE.
*/
private static ClassLoader findClassLoader() private static ClassLoader findClassLoader()
throws ConfigurationError throws ConfigurationError
{ {
ClassLoader classLoader; ClassLoader classLoader;
Method m = null;
try { try {
// Construct the name of the concrete class to instantiate m = Thread.class.getMethod("getContextClassLoader", null);
Class clazz = Class.forName(FactoryFinder.class.getName() } catch (NoSuchMethodException e) {
+ "$ClassLoaderFinderConcrete");
ClassLoaderFinder clf = (ClassLoaderFinder) clazz.newInstance();
classLoader = clf.getContextClassLoader();
} catch (LinkageError le) {
// Assume that we are running JDK 1.1, use the current ClassLoader // Assume that we are running JDK 1.1, use the current ClassLoader
if (debug) {
debugPrintln("assuming JDK 1.1");
}
classLoader = FactoryFinder.class.getClassLoader(); classLoader = FactoryFinder.class.getClassLoader();
} catch (ClassNotFoundException x) {
// This case should not normally happen. MS IE can throw this
// instead of a LinkageError the second time Class.forName() is
// called so assume that we are running JDK 1.1 and use the
// current ClassLoader
classLoader = FactoryFinder.class.getClassLoader();
} catch (Exception x) {
// Something abnormal happened so throw an error
throw new ConfigurationError(x.toString(), x);
} }
try {
classLoader = (ClassLoader) m.invoke(Thread.currentThread(), null);
} catch (IllegalAccessException e) {
// assert(false)
throw new ConfigurationError("Unexpected IllegalAccessException",
e);
} catch (InvocationTargetException e) {
// assert(e.getTargetException() instanceof SecurityException)
throw new ConfigurationError("Unexpected InvocationTargetException",
e);
}
return classLoader; return classLoader;
} }
@ -161,6 +165,8 @@ class FactoryFinder {
* @param fallbackClassName Implementation class name, if nothing else * @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback. * is found. Use null to mean no fallback.
* *
* @exception FactoryFinder.ConfigurationError
*
* Package private so this code can be shared. * Package private so this code can be shared.
*/ */
static Object find(String factoryId, String fallbackClassName) static Object find(String factoryId, String fallbackClassName)
@ -173,7 +179,7 @@ class FactoryFinder {
String systemProp = String systemProp =
System.getProperty( factoryId ); System.getProperty( factoryId );
if( systemProp!=null) { if( systemProp!=null) {
debugPrintln("found system property" + systemProp); debugPrintln("found system property " + systemProp);
return newInstance(systemProp, classLoader); return newInstance(systemProp, classLoader);
} }
} catch (SecurityException se) { } catch (SecurityException se) {
@ -249,19 +255,4 @@ class FactoryFinder {
return exception; return exception;
} }
} }
/*
* The following nested classes allow getContextClassLoader() to be
* called only on JDK 1.2 and yet run in older JDK 1.1 JVMs
*/
private static abstract class ClassLoaderFinder {
abstract ClassLoader getContextClassLoader();
}
static class ClassLoaderFinderConcrete extends ClassLoaderFinder {
ClassLoader getContextClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
}
} }

View File

@ -47,9 +47,10 @@
* ==================================================================== * ====================================================================
* *
* This software consists of voluntary contributions made by many * This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more * individuals on behalf of the Apache Software Foundation and was
* information on the Apache Software Foundation, please see * originally based on software copyright (c) 1999-2001, Sun Microsystems,
* <http://www.apache.org/>. * Inc., http://www.sun.com. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/ */
package javax.xml.transform; package javax.xml.transform;
@ -63,16 +64,18 @@ import java.util.Properties;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
/** /**
* This class is duplicated for each JAXP subpackage so keep it in * This class is duplicated for each JAXP subpackage so keep it in sync.
* sync. It is package private. * It is package private and therefore is not exposed as part of the JAXP
* API.
* *
* This code is designed to implement the JAXP 1.1 spec pluggability * This code is designed to implement the JAXP 1.1 spec pluggability
* feature and is designed to run on JDK version 1.1 and later including * feature and is designed to both compile and run on JDK version 1.1 and
* JVMs that perform early linking like the Microsoft JVM in IE 5. Note * later. The code also runs both as part of an unbundled jar file and
* however that it must be compiled on a JDK version 1.2 or later system * when bundled as part of the JDK.
* since it calls Thread#getContextClassLoader(). The code also runs both
* as part of an unbundled jar file and when bundled as part of the JDK.
*/ */
class FactoryFinder { class FactoryFinder {
/** Temp debug code - this will be removed after we test everything /** Temp debug code - this will be removed after we test everything
@ -93,35 +96,37 @@ class FactoryFinder {
} }
/** /**
* Figure out which ClassLoader to use. For JDK 1.2 and later use the * Figure out which ClassLoader to use. For JDK 1.2 and later use
* context ClassLoader if possible. Note: we defer linking the class * the context ClassLoader.
* that calls an API only in JDK 1.2 until runtime so that we can catch */
* LinkageError so that this code will run in older non-Sun JVMs such
* as the Microsoft JVM in IE.
*/
private static ClassLoader findClassLoader() private static ClassLoader findClassLoader()
throws ConfigurationError throws ConfigurationError
{ {
ClassLoader classLoader; ClassLoader classLoader;
Method m = null;
try { try {
// Construct the name of the concrete class to instantiate m = Thread.class.getMethod("getContextClassLoader", null);
Class clazz = Class.forName(FactoryFinder.class.getName() } catch (NoSuchMethodException e) {
+ "$ClassLoaderFinderConcrete");
ClassLoaderFinder clf = (ClassLoaderFinder) clazz.newInstance();
classLoader = clf.getContextClassLoader();
} catch (LinkageError le) {
// Assume that we are running JDK 1.1, use the current ClassLoader // Assume that we are running JDK 1.1, use the current ClassLoader
if (debug) {
debugPrintln("assuming JDK 1.1");
}
classLoader = FactoryFinder.class.getClassLoader(); classLoader = FactoryFinder.class.getClassLoader();
} catch (ClassNotFoundException x) {
// This case should not normally happen. MS IE can throw this
// instead of a LinkageError the second time Class.forName() is
// called so assume that we are running JDK 1.1 and use the
// current ClassLoader
classLoader = FactoryFinder.class.getClassLoader();
} catch (Exception x) {
// Something abnormal happened so throw an error
throw new ConfigurationError(x.toString(), x);
} }
try {
classLoader = (ClassLoader) m.invoke(Thread.currentThread(), null);
} catch (IllegalAccessException e) {
// assert(false)
throw new ConfigurationError("Unexpected IllegalAccessException",
e);
} catch (InvocationTargetException e) {
// assert(e.getTargetException() instanceof SecurityException)
throw new ConfigurationError("Unexpected InvocationTargetException",
e);
}
return classLoader; return classLoader;
} }
@ -160,6 +165,8 @@ class FactoryFinder {
* @param fallbackClassName Implementation class name, if nothing else * @param fallbackClassName Implementation class name, if nothing else
* is found. Use null to mean no fallback. * is found. Use null to mean no fallback.
* *
* @exception FactoryFinder.ConfigurationError
*
* Package private so this code can be shared. * Package private so this code can be shared.
*/ */
static Object find(String factoryId, String fallbackClassName) static Object find(String factoryId, String fallbackClassName)
@ -172,7 +179,7 @@ class FactoryFinder {
String systemProp = String systemProp =
System.getProperty( factoryId ); System.getProperty( factoryId );
if( systemProp!=null) { if( systemProp!=null) {
debugPrintln("found system property" + systemProp); debugPrintln("found system property " + systemProp);
return newInstance(systemProp, classLoader); return newInstance(systemProp, classLoader);
} }
} catch (SecurityException se) { } catch (SecurityException se) {
@ -248,19 +255,4 @@ class FactoryFinder {
return exception; return exception;
} }
} }
/*
* The following nested classes allow getContextClassLoader() to be
* called only on JDK 1.2 and yet run in older JDK 1.1 JVMs
*/
private static abstract class ClassLoaderFinder {
abstract ClassLoader getContextClassLoader();
}
static class ClassLoaderFinderConcrete extends ClassLoaderFinder {
ClassLoader getContextClassLoader() {
return Thread.currentThread().getContextClassLoader();
}
}
} }