You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by rs...@apache.org on 2002/08/28 05:15:11 UTC

cvs commit: xml-axis/java/src/org/apache/axis EngineConfigurationFactory.java

rsitze      2002/08/27 20:15:11

  Modified:    java/src/org/apache/axis/transport/http AxisServletBase.java
               java/src/org/apache/axis/configuration
                        EngineConfigurationFactoryFinder.java
                        ServletEngineConfigurationFactory.java
                        EngineConfigurationFactoryDefault.java
                        DefaultEngineConfigurationFactory.java
                        EngineConfigurationFactoryServlet.java
               java/lib commons-discovery.jar
               java/src simplelog.properties
               java/src/org/apache/axis/utils axisNLS.properties
               java/src/org/apache/axis EngineConfigurationFactory.java
  Log:
  1.  All EngineConfigurationFactories are now required to implement
       'public static EngineConfigurationFactory newFactory(Object)'
       [for non-static methods, I can use an interface to ensure
       that a class implements a specific method.  Any best-practices
       for same with 'static methods?]
  
  2. constructors for EngineConfigurationFactories are now private..
  
  3. newFactory is required to check it's parameter (Object) and
      it's environment, and ONLY return a factory if it understands..
      i.e.  EngineConfigurationFactoryDefault verifies that param is null,
      [and someday.. will verify that it can find the wsdd files?]
      EngineConfigurationFactoryServlet veries that param is a
      ServletContext.
      Others may verify param & or elements of the runtime environment.
  
  4. EngineConfigurationFactoryFinder locates all factories (may be
      more than just the two packaged with AXIS), and returns the
      results of the first successfull factory, trying the built-in defaults last.
  
  Considering making the 'newFactory' a two-step process:
  a) isValidEnvironment (or something)
  b) new ...
  
  Revision  Changes    Path
  1.15      +1 -1      xml-axis/java/src/org/apache/axis/transport/http/AxisServletBase.java
  
  Index: AxisServletBase.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/transport/http/AxisServletBase.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- AxisServletBase.java	23 Aug 2002 15:05:14 -0000	1.14
  +++ AxisServletBase.java	28 Aug 2002 03:15:11 -0000	1.15
  @@ -277,7 +277,7 @@
                               webInfPath + File.separator + "attachments");
   
           EngineConfiguration config =
  -            EngineConfigurationFactoryFinder.newServletFactory(context)
  +            EngineConfigurationFactoryFinder.newFactory(context)
                       .getServerEngineConfig();
   
           if (config != null) {
  
  
  
  1.3       +133 -15   xml-axis/java/src/org/apache/axis/configuration/EngineConfigurationFactoryFinder.java
  
  Index: EngineConfigurationFactoryFinder.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/configuration/EngineConfigurationFactoryFinder.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EngineConfigurationFactoryFinder.java	23 Aug 2002 22:22:30 -0000	1.2
  +++ EngineConfigurationFactoryFinder.java	28 Aug 2002 03:15:11 -0000	1.3
  @@ -55,11 +55,16 @@
   
   package org.apache.axis.configuration;
   
  -import javax.servlet.ServletContext;
  -import org.apache.axis.AxisProperties;
  +import java.lang.reflect.Method;
  +import java.util.Enumeration;
  +
   import org.apache.axis.EngineConfigurationFactory;
   import org.apache.axis.components.logger.LogFactory;
  -import org.apache.commons.discovery.tools.SPInterface;
  +import org.apache.axis.utils.JavaUtils;
  +import org.apache.commons.discovery.ClassInfo;
  +import org.apache.commons.discovery.ClassLoaders;
  +import org.apache.commons.discovery.ServiceDiscovery;
  +import org.apache.commons.discovery.tools.ClassUtils;
   import org.apache.commons.logging.Log;
   
   
  @@ -81,26 +86,139 @@
       protected static Log log =
           LogFactory.getLog(EngineConfigurationFactoryFinder.class.getName());
   
  +    private static final Class mySpi = EngineConfigurationFactory.class;
  +    private static final Class myFactory = EngineConfigurationFactoryFinder.class;
  +
  +    private static final Class[] newFactoryParamTypes =
  +        new Class[] { Object.class };
  +        
  +    private static final String requiredMethod =
  +        "public static EngineConfigurationFactory newFactory(Object)";
  +
  +    private EngineConfigurationFactoryFinder() {
  +    }
  +
  +
       /**
        * Create the default engine configuration and detect whether the user
        * has overridden this with their own.
  +     * 
  +     * The discovery mechanism will use the following logic:
  +     * 
  +     * - discover all available EngineConfigurationFactories
  +     *   - find all META-INF/services/org.apache.axis.EngineConfigurationFactory
  +     *     files available through class loaders.
  +     *   - read files (see Discovery) to obtain implementation(s) of that
  +     *     interface
  +     * - For each impl, call 'newFactory(Object param)'
  +     * - Each impl should examine the 'param' and return a new factory ONLY
  +     *   - if it knows what to do with it
  +     *     (i.e. it knows what to do with the 'real' type)
  +     *   - it can find it's configuration information
  +     * - Return first non-null factory found.
  +     * - Try EngineConfigurationFactoryServlet.newFactory(obj)
  +     * - Try EngineConfigurationFactoryDefault.newFactory(obj)
  +     * - If zero found (all return null), throw exception
  +     * 
  +     * ***
  +     * This needs more work: System.properties, etc.
  +     * Discovery will have more tools to help with that
  +     * (in the manner of use below) in the near future.
  +     * ***
  +     * 
        */
  -    private EngineConfigurationFactoryFinder() {
  +    public static EngineConfigurationFactory newFactory(Object obj) {
  +        /**
  +         * recreate on each call is critical to gaining
  +         * the right class loaders.  Do not cache.
  +         */
  +        ServiceDiscovery sd =
  +            new ServiceDiscovery(ClassLoaders.getAppLoaders(mySpi, myFactory, true));
  +
  +        Object[] params = new Object[] { obj };
  +
  +        /**
  +         * Find and examine each service
  +         */
  +        EngineConfigurationFactory factory = null;
  +        
  +        Enumeration services = sd.find(mySpi.getName());
  +        while (factory == null  &&  services.hasMoreElements()) {
  +            Class service = ((ClassInfo)services.nextElement()).getResourceClass();
  +            
  +            factory = newFactory(service, newFactoryParamTypes, params);
  +        }
  +        
  +        if (factory == null) {
  +            try {
  +                factory = EngineConfigurationFactoryServlet.newFactory(obj);
  +            } catch (Exception e) {
  +                log.warn(JavaUtils.getMessage("engineConfigInvokeNewFactory",
  +                                              EngineConfigurationFactoryServlet.class.getName(),
  +                                              requiredMethod), e);
  +            }
  +            
  +            if (factory == null) {
  +                try {
  +                    // should NEVER return null.
  +                    factory = EngineConfigurationFactoryDefault.newFactory(obj);
  +                } catch (Exception e) {
  +                    log.warn(JavaUtils.getMessage("engineConfigInvokeNewFactory",
  +                                                  EngineConfigurationFactoryDefault.class.getName(),
  +                                                  requiredMethod), e);
  +                }
  +            }
  +        }
  +        
  +        if (factory != null) {
  +            log.debug("Got EngineFactory: " + factory.getClass().getName());
  +        } else {
  +            String msg = JavaUtils.getMessage("engineConfigFactoryMissing");
  +            log.error(msg);
  +            // we should be throwing an exception here,
  +            //
  +            // but again, requires more refactoring than we want to swallow
  +            // at this point in time.  Ifthis DOES occur, it's a coding error:
  +            // factory should NEVER be null.
  +            // Testing will find this, as NullPointerExceptions will be generated
  +            // elsewhere.
  +        }
  +        
  +        return factory;
       }
   
       public static EngineConfigurationFactory newFactory() {
  -        return (EngineConfigurationFactory)AxisProperties.newInstance(
  -                new SPInterface(EngineConfigurationFactory.class,
  -                                EngineConfigurationFactory.SYSTEM_PROPERTY_NAME),
  -                EngineConfigurationFactoryDefault.class);
  +        return newFactory(null);
       }
   
  -    public static EngineConfigurationFactoryServlet newServletFactory(ServletContext ctx) {
  -        return (EngineConfigurationFactoryServlet)AxisProperties.newInstance(
  -                new SPInterface(EngineConfigurationFactory.class,
  -                                EngineConfigurationFactory.SYSTEM_PROPERTY_NAME,
  -                                new Class[] { ServletContext.class },
  -                                new Object[] { ctx }),
  -                EngineConfigurationFactoryServlet.class);
  +    private static EngineConfigurationFactory newFactory(Class service,
  +                                                         Class[] paramTypes,
  +                                                         Object[] param) {
  +        /**
  +         * Verify that service implements:
  +         *  public static EngineConfigurationFactory newFactory(Object);
  +         */
  +        Method method =
  +            ClassUtils.findPublicStaticMethod(service,
  +                                              EngineConfigurationFactory.class,
  +                                              "newFactory",
  +                                              paramTypes);
  +
  +        
  +        if (method == null) {
  +            log.warn(JavaUtils.getMessage("engineConfigMissingNewFactory",
  +                                          service.getName(),
  +                                          requiredMethod));
  +        } else {
  +            try {
  +                return (EngineConfigurationFactory)method.invoke(null, param);
  +            } catch (Exception e) {
  +                log.warn(JavaUtils.getMessage("engineConfigInvokeNewFactory",
  +                                              service.getName(),
  +                                              requiredMethod), e);
  +            }
  +        }
  +        
  +        return null;
       }
   }
  
  
  
  1.14      +1 -1      xml-axis/java/src/org/apache/axis/configuration/ServletEngineConfigurationFactory.java
  
  Index: ServletEngineConfigurationFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/configuration/ServletEngineConfigurationFactory.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ServletEngineConfigurationFactory.java	23 Aug 2002 15:05:14 -0000	1.13
  +++ ServletEngineConfigurationFactory.java	28 Aug 2002 03:15:11 -0000	1.14
  @@ -70,6 +70,6 @@
       extends DefaultEngineConfigurationFactory
   {
       public ServletEngineConfigurationFactory(ServletContext ctx) {
  -        super(EngineConfigurationFactoryFinder.newServletFactory(ctx));
  +        super(EngineConfigurationFactoryFinder.newFactory(ctx));
       }
   }
  
  
  
  1.2       +45 -12    xml-axis/java/src/org/apache/axis/configuration/EngineConfigurationFactoryDefault.java
  
  Index: EngineConfigurationFactoryDefault.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/configuration/EngineConfigurationFactoryDefault.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EngineConfigurationFactoryDefault.java	23 Aug 2002 00:33:41 -0000	1.1
  +++ EngineConfigurationFactoryDefault.java	28 Aug 2002 03:15:11 -0000	1.2
  @@ -55,6 +55,8 @@
   
   package org.apache.axis.configuration;
   
  +import java.io.File;
  +
   import org.apache.axis.AxisProperties;
   import org.apache.axis.EngineConfiguration;
   import org.apache.axis.EngineConfigurationFactory;
  @@ -82,8 +84,8 @@
       protected static Log log =
           LogFactory.getLog(EngineConfigurationFactoryDefault.class.getName());
   
  -    public final String OPTION_CLIENT_CONFIG_FILE = "axis.ClientConfigFile";
  -    public final String OPTION_SERVER_CONFIG_FILE = "axis.ServerConfigFile";
  +    public static final String OPTION_CLIENT_CONFIG_FILE = "axis.ClientConfigFile";
  +    public static final String OPTION_SERVER_CONFIG_FILE = "axis.ServerConfigFile";
   
       protected static final String CLIENT_CONFIG_FILE = "client-config.wsdd";
       protected static final String SERVER_CONFIG_FILE = "server-config.wsdd";
  @@ -93,22 +95,53 @@
       private String serverConfigFile;
   
       /**
  +     * Creates and returns a new EngineConfigurationFactory.
  +     * If a factory cannot be created, return 'null'.
  +     * 
  +     * The factory may return non-NULL only if:
  +     *   - it knows what to do with the param (param == null)
  +     *   - it can find it's configuration information
  +     * 
  +     * @see org.apache.axis.configuration.EngineConfigurationFactoryFinder
  +     */
  +    public static EngineConfigurationFactory newFactory(Object param) {
  +        if (param != null)
  +            return null;  // not for us.
  +
  +        /**
  +         * Default, let this one go through.
  +         * 
  +         * The REAL reason we are not trying to make any
  +         * decision here is because it's impossible
  +         * (without refactoring FileProvider) to determine
  +         * if a *.wsdd file is present or not until the configuration
  +         * is bound to an engine.
  +         * 
  +         * FileProvider/EngineConfiguration pretend to be independent,
  +         * but they are tightly bound to an engine instance...
  +         */
  +        return new EngineConfigurationFactoryDefault();
  +    }
  +
  +    /**
        * Create the default engine configuration and detect whether the user
        * has overridden this with their own.
        */
  -    public EngineConfigurationFactoryDefault() {
  -        clientConfigFile = AxisProperties.getProperty(OPTION_CLIENT_CONFIG_FILE,
  -                                                      CLIENT_CONFIG_FILE);
  -
  -        serverConfigFile = AxisProperties.getProperty(OPTION_SERVER_CONFIG_FILE,
  -                                                      SERVER_CONFIG_FILE);
  +    protected EngineConfigurationFactoryDefault() {
  +        clientConfigFile =
  +            AxisProperties.getProperty(OPTION_CLIENT_CONFIG_FILE,
  +                                       CLIENT_CONFIG_FILE);
  +
  +        serverConfigFile =
  +            AxisProperties.getProperty(OPTION_SERVER_CONFIG_FILE,
  +                                       SERVER_CONFIG_FILE);
       }
   
        /**
  -     * Get a default client engine configuration.
  -     *
  -     * @return a client EngineConfiguration
  -     */
  +      * Get a default client engine configuration.
  +      *
  +      * @return a client EngineConfiguration
  +      */
       public EngineConfiguration getClientEngineConfig() {
           return new FileProvider(clientConfigFile);
       }
  
  
  
  1.20      +2 -2      xml-axis/java/src/org/apache/axis/configuration/DefaultEngineConfigurationFactory.java
  
  Index: DefaultEngineConfigurationFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/configuration/DefaultEngineConfigurationFactory.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- DefaultEngineConfigurationFactory.java	23 Aug 2002 15:05:14 -0000	1.19
  +++ DefaultEngineConfigurationFactory.java	28 Aug 2002 03:15:11 -0000	1.20
  @@ -91,7 +91,7 @@
        * @return a client EngineConfiguration
        */
       public EngineConfiguration getClientEngineConfig() {
  -        return factory.getClientEngineConfig();
  +        return factory == null ? null : factory.getClientEngineConfig();
       }
   
       /**
  @@ -100,6 +100,6 @@
        * @return a server EngineConfiguration
        */
       public EngineConfiguration getServerEngineConfig() {
  -        return factory.getServerEngineConfig();
  +        return factory == null ? null : factory.getServerEngineConfig();
       }
   }
  
  
  
  1.2       +31 -1     xml-axis/java/src/org/apache/axis/configuration/EngineConfigurationFactoryServlet.java
  
  Index: EngineConfigurationFactoryServlet.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/configuration/EngineConfigurationFactoryServlet.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- EngineConfigurationFactoryServlet.java	23 Aug 2002 00:33:41 -0000	1.1
  +++ EngineConfigurationFactoryServlet.java	28 Aug 2002 03:15:11 -0000	1.2
  @@ -59,8 +59,10 @@
   import java.io.InputStream;
   
   import javax.servlet.ServletContext;
  +import org.apache.axis.AxisProperties;
   import org.apache.axis.ConfigurationException;
   import org.apache.axis.EngineConfiguration;
  +import org.apache.axis.EngineConfigurationFactory;
   import org.apache.axis.components.logger.LogFactory;
   import org.apache.axis.utils.JavaUtils;
   import org.apache.commons.logging.Log;
  @@ -88,10 +90,38 @@
       private ServletContext ctx;
       
       /**
  +     * Creates and returns a new EngineConfigurationFactory.
  +     * If a factory cannot be created, return 'null'.
  +     * 
  +     * The factory may return non-NULL only if:
  +     *   - it knows what to do with the param (param instanceof ServletContext)
  +     *   - it can find it's configuration information
  +     * 
  +     * @see org.apache.axis.configuration.EngineConfigurationFactoryFinder
  +     */
  +    public static EngineConfigurationFactory newFactory(Object param) {
  +        /**
  +         * Default, let this one go through if we find a ServletContext.
  +         * 
  +         * The REAL reason we are not trying to make any
  +         * decision here is because it's impossible
  +         * (without refactoring FileProvider) to determine
  +         * if a *.wsdd file is present or not until the configuration
  +         * is bound to an engine.
  +         * 
  +         * FileProvider/EngineConfiguration pretend to be independent,
  +         * but they are tightly bound to an engine instance...
  +         */
  +        return (param instanceof ServletContext)
  +               ? new EngineConfigurationFactoryServlet((ServletContext)param)
  +               : null;
  +    }
  +
  +    /**
        * Create the default engine configuration and detect whether the user
        * has overridden this with their own.
        */
  -    public EngineConfigurationFactoryServlet(ServletContext ctx) {
  +    protected EngineConfigurationFactoryServlet(ServletContext ctx) {
           super();
           this.ctx = ctx;
       }
  
  
  
  1.9       +131 -95   xml-axis/java/lib/commons-discovery.jar
  
  	<<Binary file>>
  
  
  1.4       +1 -1      xml-axis/java/src/simplelog.properties
  
  Index: simplelog.properties
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/simplelog.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- simplelog.properties	21 Aug 2002 19:17:56 -0000	1.3
  +++ simplelog.properties	28 Aug 2002 03:15:11 -0000	1.4
  @@ -1,2 +1,2 @@
  -org.apache.commons.logging.simplelog.defaultlog=warn
  +org.apache.commons.logging.simplelog.defaultlog=info
   
  
  
  
  1.54      +4 -0      xml-axis/java/src/org/apache/axis/utils/axisNLS.properties
  
  Index: axisNLS.properties
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/axisNLS.properties,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- axisNLS.properties	26 Aug 2002 20:03:18 -0000	1.53
  +++ axisNLS.properties	28 Aug 2002 03:15:11 -0000	1.54
  @@ -999,3 +999,7 @@
   
   noServiceClass=No service class was found!  Are you missing a className option?
   jpegOnly=Cannot handle {0}, can only handle JPEG image types.
  +
  +engineConfigMissingNewFactory=Factory {0} Ignored: missing required method: {1}.
  +engineConfigInvokeNewFactory=Factory {0} Ignored: invoke method failed: {1}.
  +engineConfigFactoryMissing=Unable to locate a valid EngineConfigurationFactory
  
  
  
  1.9       +23 -5     xml-axis/java/src/org/apache/axis/EngineConfigurationFactory.java
  
  Index: EngineConfigurationFactory.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/EngineConfigurationFactory.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- EngineConfigurationFactory.java	30 May 2002 23:46:00 -0000	1.8
  +++ EngineConfigurationFactory.java	28 Aug 2002 03:15:11 -0000	1.9
  @@ -58,7 +58,25 @@
   /**
    * EngineConfigurationFactory is an interface used to construct
    * concrete EngineConfiguration instances.
  + * 
  + * Each EngineConfigurationFactory must also (directly) implement
  + * the following static method:
    *
  + *     //Creates and returns a new EngineConfigurationFactory.
  + *     //If a factory cannot be created, return 'null'.
  + *     //
  + *     //The factory may return non-NULL only if:
  + *     //  - it knows what to do with the param (check type & process value)
  + *     //  - it can find it's configuration information
  + *     //
  + *     //@see org.apache.axis.configuration.EngineConfigurationFactoryFinder
  + * 
  + *     public static EngineConfigurationFactory newFactory(Object param);
  + *
  + * This is checked at runtime and a warning generated for
  + * factories found that do NOT implement this.
  + *
  + * @author Richard A. Sitze
    * @author Glyn Normington (glyn@apache.org)
    */
   public interface EngineConfigurationFactory {
  @@ -67,12 +85,12 @@
        * in creating engines.
        */
       public static final String SYSTEM_PROPERTY_NAME = "axis.EngineConfigFactory";
  -
  +    
        /**
  -     * Get a default client engine configuration.
  -     *
  -     * @return a client EngineConfiguration
  -     */
  +      * Get a default client engine configuration.
  +      *
  +      * @return a client EngineConfiguration
  +      */
       public EngineConfiguration getClientEngineConfig();
   
       /**