You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Williams, Trevor" <tw...@netperceptions.com> on 2000/12/07 18:14:19 UTC

RE: [C2][Xalan2J] Extension Handler Error with Fix (waz Re: [C2] : Namespace bug in XalanTransformer)

Correct me if I'm wrong, but doesn't this accomplish the same thing, with
fewer lines of code & simpler control flow?

- Trevor Williams

============================================================================
======================
  /**
   * Replacement for Class.forName.  This method loads a class using the
context class loader
   * if we're running under Java2 or higher.  If we're running under Java1,
this
   * method just uses Class.forName to load the class.
   */
  static Class getClassForName(String className)
      throws ClassNotFoundException
  {
    Class result = null;
    try {
        if (getCCL != null)
        {
            ClassLoader contextClassLoader =
                              (ClassLoader)
getCCL.invoke(Thread.currentThread(), NO_OBJS);
            result = contextClassLoader.loadClass(className);
        }
    }
    catch (ClassNotFoundException cnfe)
    {
        // Don't clear the CCL; let the finally clause
        // try to load the class.
        // i.e. do nothing here.
    }
    catch (Exception e)
    {
        // If we get any exception other than ClassNotFound, stop
        // trying to use the context loader:
        getCCL = null;
    }
    finally {
        if (result == null) {
            result = Class.forName(className);
        }
    }

    return result;
 }

Re: [C2][Xalan2J] Extension Handler Error with Fix (waz Re: [C2]: Namespace bug in XalanTransformer)

Posted by Gary L Peskin <ga...@firstech.com>.
"Williams, Trevor" wrote:
> 
> Correct me if I'm wrong, but doesn't this accomplish the same thing, with
> fewer lines of code & simpler control flow?

Yes, although it does require an extra test if the loadClass worked
since loadClass will never return null (is my assembler background
showing through here?).

We implemented a similar solution that just eliminates the inner try and
catch.

Thanks for your input.

Gary