You are viewing a plain text version of this content. The canonical link for it is here.
Posted to crimson-cvs@xml.apache.org by ed...@apache.org on 2001/04/20 02:52:22 UTC

cvs commit: xml-crimson/src/org/apache/crimson/tree SimpleElementFactory.java

edwingo     01/04/19 17:52:21

  Modified:    src/org/apache/crimson/tree SimpleElementFactory.java
  Log:
  Fix SimpleElementFactory fails when JAXP is installed as an extension
  
  Revision  Changes    Path
  1.2       +62 -2     xml-crimson/src/org/apache/crimson/tree/SimpleElementFactory.java
  
  Index: SimpleElementFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-crimson/src/org/apache/crimson/tree/SimpleElementFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SimpleElementFactory.java	2000/11/23 01:53:35	1.1
  +++ SimpleElementFactory.java	2001/04/20 00:52:21	1.2
  @@ -1,5 +1,5 @@
   /*
  - * $Id: SimpleElementFactory.java,v 1.1 2000/11/23 01:53:35 edwingo Exp $
  + * $Id: SimpleElementFactory.java,v 1.2 2001/04/20 00:52:21 edwingo Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -110,7 +110,7 @@
    * URL will similarly need to use a network class loader.
    *
    * @author David Brownell
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class SimpleElementFactory implements ElementFactory
   {
  @@ -206,6 +206,12 @@
   	    Class	retval;
   
   	    try {
  +                if (loader == null) {
  +                    // Find the appropriate ClassLoader to use depending on
  +                    // if we are part of the JDK or not and taking JDK
  +                    // version into account.
  +                    loader = findClassLoader();
  +                }
   		if (loader == null)
   		    retval = Class.forName (className);
   		else
  @@ -316,5 +322,59 @@
       //XXX use the default locale only at this point.
       String getMessage (String messageId, Object[] parameters) {
   	return XmlDocument.catalog.getMessage (locale, messageId, parameters);
  +    }
  +
  +
  +    /*
  +     * The following section of code tries to get our ContextClassLoader,
  +     * if we are running in Java 2.  This code is derived from
  +     * javax.xml.parsers.FactoryFinder.
  +     */
  +
  +    /**
  +     * Figure out which ClassLoader to use.  For JDK 1.2 and later use the
  +     * context ClassLoader if possible.  Note: we defer linking the class
  +     * 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()
  +    {
  +        ClassLoader classLoader;
  +        try {
  +            // Construct the name of the concrete class to instantiate
  +            Class clazz = Class.forName(SimpleElementFactory.class.getName()
  +                                        + "$ClassLoaderFinderConcrete");
  +            ClassLoaderFinder clf = (ClassLoaderFinder) clazz.newInstance();
  +            classLoader = clf.getContextClassLoader();
  +        } catch (LinkageError le) {
  +            // Assume that we are running JDK 1.1, use the current ClassLoader
  +            classLoader = SimpleElementFactory.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 = SimpleElementFactory.class.getClassLoader();
  +        } catch (Exception x) {
  +            // Something abnormal happened so just use current ClassLoader
  +            classLoader = SimpleElementFactory.class.getClassLoader();
  +        }
  +        return classLoader;
  +    }
  +
  +    /*
  +     * 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();
  +        }
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: crimson-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: crimson-cvs-help@xml.apache.org