neilg       2002/09/10 06:42:07

  Modified:    java/src/org/apache/xerces/util ObjectFactory.java
  Log:
  refactored Object instantiation code lsightly so that this class can now be used in 
the DOM implementation.
  
  Revision  Changes    Path
  1.7       +38 -28    xml-xerces/java/src/org/apache/xerces/util/ObjectFactory.java
  
  Index: ObjectFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/util/ObjectFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ObjectFactory.java        26 Aug 2002 23:57:10 -0000      1.6
  +++ ObjectFactory.java        10 Sep 2002 13:42:07 -0000      1.7
  @@ -236,33 +236,8 @@
           throws ConfigurationError
       {
           // assert(className != null);
  -
  -        try {
  -            Class providerClass;
  -            if (cl == null) {
  -                // XXX Use the bootstrap ClassLoader.  There is no way to
  -                // load a class using the bootstrap ClassLoader that works
  -                // in both JDK 1.1 and Java 2.  However, this should still
  -                // work b/c the following should be true:
  -                //
  -                // (cl == null) iff current ClassLoader == null
  -                //
  -                // Thus Class.forName(String) will use the current
  -                // ClassLoader which will be the bootstrap ClassLoader.
  -                providerClass = Class.forName(className);
  -            } else {
  -                try {
  -                    providerClass = cl.loadClass(className);
  -                } catch (ClassNotFoundException x) {
  -                    if (doFallback) {
  -                        // Fall back to current classloader
  -                        cl = ObjectFactory.class.getClassLoader();
  -                        providerClass = cl.loadClass(className);
  -                    } else {
  -                        throw x;
  -                    }
  -                }
  -            }
  +        try{
  +            Class providerClass = findProviderClass(className, cl, doFallback);
               Object instance = providerClass.newInstance();
               debugPrintln("created new instance of " + providerClass +
                      " using ClassLoader: " + cl);
  @@ -275,6 +250,41 @@
                   "Provider " + className + " could not be instantiated: " + x,
                   x);
           }
  +    }
  +
  +    /**
  +     * Find a Class using the specified ClassLoader
  +     */ 
  +    public static Class findProviderClass(String className, ClassLoader cl,
  +                                      boolean doFallback)
  +        throws ClassNotFoundException, ConfigurationError
  +    {
  +        Class providerClass;
  +        if (cl == null) {
  +            // XXX Use the bootstrap ClassLoader.  There is no way to
  +            // load a class using the bootstrap ClassLoader that works
  +            // in both JDK 1.1 and Java 2.  However, this should still
  +            // work b/c the following should be true:
  +            //
  +            // (cl == null) iff current ClassLoader == null
  +            //
  +            // Thus Class.forName(String) will use the current
  +            // ClassLoader which will be the bootstrap ClassLoader.
  +            providerClass = Class.forName(className);
  +        } else {
  +            try {
  +                providerClass = cl.loadClass(className);
  +            } catch (ClassNotFoundException x) {
  +                if (doFallback) {
  +                    // Fall back to current classloader
  +                    cl = ObjectFactory.class.getClassLoader();
  +                    providerClass = cl.loadClass(className);
  +                } else {
  +                    throw x;
  +                }
  +            }
  +        }
  +        return providerClass;
       }
   
       /*
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to