axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: xml-axis/java/src/javax/xml/soap FactoryFinder.java
Date Sun, 29 Jun 2003 01:55:20 GMT
dims        2003/06/28 18:55:20

  Modified:    java/src/javax/xml/soap FactoryFinder.java
  Log:
  Fix for Bug 17279 - Axis does not work when installed in WEB-INF/lib
  
  Notes:
  - Added fallback mechanism that uses the class loader that loaded FactoryFinder class.
  
  Revision  Changes    Path
  1.7       +62 -72    xml-axis/java/src/javax/xml/soap/FactoryFinder.java
  
  Index: FactoryFinder.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/javax/xml/soap/FactoryFinder.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FactoryFinder.java	22 Apr 2003 19:33:55 -0000	1.6
  +++ FactoryFinder.java	29 Jun 2003 01:55:20 -0000	1.7
  @@ -57,7 +57,9 @@
   import java.io.BufferedReader;
   import java.io.File;
   import java.io.FileInputStream;
  +import java.io.InputStream;
   import java.io.InputStreamReader;
  +
   import java.util.Properties;
   
   /**
  @@ -66,127 +68,115 @@
    * be accessed from other packages.
    */
   class FactoryFinder {
  -
       /**
  -     * Constructor FactoryFinder
  -     */
  -    FactoryFinder() {}
  -
  -    /**
  -     * Method newInstance
  +     * instantiates an object go the given classname.
        *
        * @param factoryClassName
  -     * @param classloader
  -     *
  -     * @return
  -     *
  +     * @return a factory object
        * @throws SOAPException
        */
  -    private static Object newInstance(
  -            String factoryClassName, ClassLoader classloader)
  -                throws SOAPException {
  -
  +    private static Object newInstance(String factoryClassName) throws SOAPException {
  +        ClassLoader classloader = null;
           try {
  -            Class factory;
  +            classloader = Thread.currentThread().getContextClassLoader();
  +        } catch (Exception exception) {
  +            throw new SOAPException(exception.toString(), exception);
  +        }
   
  +        try {
  +            Class factory = null;
               if (classloader == null) {
                   factory = Class.forName(factoryClassName);
               } else {
  +                try {
  +                    factory = classloader.loadClass(factoryClassName);
  +                } catch (ClassNotFoundException cnfe) {}
  +            }
  +            if (factory == null) {
  +                classloader = FactoryFinder.class.getClassLoader();
                   factory = classloader.loadClass(factoryClassName);
               }
  -
               return factory.newInstance();
           } catch (ClassNotFoundException classnotfoundexception) {
  -            throw new SOAPException("Provider " + factoryClassName
  -                                    + " not found", classnotfoundexception);
  +            throw new SOAPException("Provider " + factoryClassName + " not found", classnotfoundexception);
           } catch (Exception exception) {
  -            throw new SOAPException("Provider " + factoryClassName
  -                                    + " could not be instantiated: "
  -                                    + exception, exception);
  +            throw new SOAPException("Provider " + factoryClassName + " could not be instantiated:
" + exception, exception);
           }
       }
   
       /**
  -     * Method find
  +     * instantiates a factory object given the factory's property name and the default
class name
        *
        * @param factoryPropertyName
        * @param defaultFactoryClassName
  -     *
  -     * @return
  -     *
  +     * @return a factory object
        * @throws SOAPException
        */
  -    static Object find(
  -            String factoryPropertyName, String defaultFactoryClassName)
  -                throws SOAPException {
  -
  -        ClassLoader classloader;
  -
  -        try {
  -            classloader = Thread.currentThread().getContextClassLoader();
  -        } catch (Exception exception) {
  -            throw new SOAPException(exception.toString(), exception);
  -        }
  -
  +    static Object find(String factoryPropertyName, String defaultFactoryClassName) throws
SOAPException {
           try {
               String factoryClassName = System.getProperty(factoryPropertyName);
  -
               if (factoryClassName != null) {
  -                return newInstance(factoryClassName, classloader);
  +                return newInstance(factoryClassName);
               }
           } catch (SecurityException securityexception) {}
   
           try {
  -            String propertiesFileName = System.getProperty("java.home")
  -                                        + File.separator + "lib"
  +            String propertiesFileName = System.getProperty("java.home") 
  +                                        + File.separator + "lib" 
                                           + File.separator + "jaxm.properties";
  -            File   file               = new File(propertiesFileName);
  -
  +            File file = new File(propertiesFileName);
               if (file.exists()) {
  -                FileInputStream fileInput  = new FileInputStream(file);
  -                Properties      properties = new Properties();
  -
  +                FileInputStream fileInput = new FileInputStream(file);
  +                Properties properties = new Properties();
                   properties.load(fileInput);
                   fileInput.close();
  -
  -                String factoryClassName =
  -                    properties.getProperty(factoryPropertyName);
  -
  -                return newInstance(factoryClassName, classloader);
  +                String factoryClassName = properties.getProperty(factoryPropertyName);
  +                return newInstance(factoryClassName);
               }
           } catch (Exception exception1) {}
   
           String factoryResource = "META-INF/services/" + factoryPropertyName;
   
           try {
  -            java.io.InputStream inputstream = null;
  -
  -            if (classloader == null) {
  -                inputstream =
  -                    ClassLoader.getSystemResourceAsStream(factoryResource);
  -            } else {
  -                inputstream = classloader.getResourceAsStream(factoryResource);
  -            }
  -
  +            InputStream inputstream = getResource(factoryResource);
               if (inputstream != null) {
  -                BufferedReader bufferedreader   =
  -                    new BufferedReader(new InputStreamReader(inputstream,
  -                        "UTF-8"));
  -                String         factoryClassName = bufferedreader.readLine();
  -
  +                BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputstream,
"UTF-8"));
  +                String factoryClassName = bufferedreader.readLine();
                   bufferedreader.close();
  -
  -                if ((factoryClassName != null) &&!"".equals(factoryClassName))
{
  -                    return newInstance(factoryClassName, classloader);
  +                if ((factoryClassName != null) && !"".equals(factoryClassName))
{
  +                    return newInstance(factoryClassName);
                   }
               }
           } catch (Exception exception2) {}
   
           if (defaultFactoryClassName == null) {
  -            throw new SOAPException("Provider for " + factoryPropertyName
  -                                    + " cannot be found", null);
  +            throw new SOAPException("Provider for " + factoryPropertyName + " cannot be
found", null);
           } else {
  -            return newInstance(defaultFactoryClassName, classloader);
  +            return newInstance(defaultFactoryClassName);
  +        }
  +    }
  +
  +    /**
  +     * returns an input stream for the specified resource.
  +     * @param factoryResource
  +     * @return
  +     */
  +    private static InputStream getResource(String factoryResource) {
  +        ClassLoader classloader = null;
  +        try {
  +            classloader = Thread.currentThread().getContextClassLoader();
  +        } catch (SecurityException securityexception) {}
  +        
  +        InputStream inputstream;
  +        if (classloader == null) {
  +            inputstream = ClassLoader.getSystemResourceAsStream(factoryResource);
  +        } else {
  +            inputstream = classloader.getResourceAsStream(factoryResource);
  +        }
  +
  +        if (inputstream == null) {
  +            inputstream = FactoryFinder.class.getClassLoader().getResourceAsStream(factoryResource);
           }
  +        return inputstream;
       }
   }
  
  
  

Mime
View raw message