xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joseph_Kessel...@lotus.com
Subject XML-Commons and JDK 1.1 compatability
Date Fri, 19 Oct 2001 20:54:07 GMT
We've got a little problem in org.apache.xalan.xslt.FactoryFinder.

As currently checked in, the code won't compile under JDK 1.1.8; there's a
hard dependency on the getContextClassLoader() method, which isn't present
before JDK 1.2. We've seen that problem before, and in the past our
solution was to use reflection to move the dependency from compile time  to
run time. Here's a quick-and-dirty version of that:

  static class ClassLoaderFinderConcrete extends ClassLoaderFinder {

    static final Class[] noparms=new Class[0];
    static final Object[] noargs=new Object[0];

    ClassLoader getContextClassLoader() {
      // The following line will not compile under JDK 1.1,
      // due to the hard dependency on a 1.2-and-later method:
      //     return Thread.currentThread().getContextClassLoader();
      // Hence we use reflection to move the dependency from
      // compile-time to run-time.

      Thread ct=Thread.currentThread();
      ClassLoader cl=null;
      try
      {
     java.lang.reflect.Method gccl
       =ct.getClass().getMethod("getContextClassLoader",noparms);
     cl=(ClassLoader)(gccl.invoke(ct,noargs));
      }
      catch(Exception e)
      {
     throw new LinkageError();
      }

      return cl;
    }
  }

Unfortunately, we then run into a second problem. The fallback in the
caller, if the context classloader can't be resolved, is to return the same
classloader that loaded the FactoryFinder object. But in JDK 1.1.x that
method is documented as potentially returning null for any class brought in
through the default loader... which isn't exactly a useful response for
those who actually want to load classes.

I seem to remember dealing with this last tim around and finding a fallback
for the fallback -- some way to retrieve the default classloader object --
but I honestly don't remember what it was. Does anyone out there have a
clue?


Until both issues are fixed, I don't think we'll either compile or run
reliably under JDK1.1. And I don't believe we've yet reached consensus that
the JDK1.1 users can be abandoned.


-------------------------------------------

Related problem: org\xml\sax\helpers\parserAdapter wass using the JDK 1.2
Collections methods add() and get() on a Vector. That too won't compile
under JDK 1.1.x; it must be changed (trivially) to use addElement() and
elementAt(). I'm going to just go ahead and check that one in, since it
should be harmless. If this glitch is something we acquired from the SAX
team, we should feed this back to them as a suggestion.


---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Mime
View raw message