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/09/30 22:45:18 UTC

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

rsitze      2002/09/30 13:45:18

  Modified:    java/src/org/apache/axis/configuration
                        EngineConfigurationFactoryFinder.java
  Added:       java/src/org/apache/axis/discovery DiscoverConstNames.java
  Log:
  Bugzilla #13149 : fix using discovery.  Let discovery handle
  errors & retries as it is designed to do internally..
  Cleans up flow in general.
  
  Revision  Changes    Path
  1.16      +14 -31    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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- EngineConfigurationFactoryFinder.java	30 Sep 2002 18:33:04 -0000	1.15
  +++ EngineConfigurationFactoryFinder.java	30 Sep 2002 20:45:18 -0000	1.16
  @@ -61,6 +61,7 @@
   
   import org.apache.axis.EngineConfigurationFactory;
   import org.apache.axis.components.logger.LogFactory;
  +import org.apache.axis.discovery.DiscoverConstNames;
   import org.apache.axis.discovery.DiscoverOldNamesInManagedProperties;
   import org.apache.axis.utils.Messages;
   import org.apache.commons.discovery.ResourceClassIterator;
  @@ -153,6 +154,12 @@
                           nameDiscoverers.addResourceNameDiscover(new DiscoverOldNamesInManagedProperties());
                           nameDiscoverers.addResourceNameDiscover(new DiscoverNamesInManagedProperties());
                           nameDiscoverers.addResourceNameDiscover(new DiscoverServiceNames(loaders));
  +                        nameDiscoverers.addResourceNameDiscover(new DiscoverConstNames(
  +                            new String[] {
  +                                "org.apache.axis.configuration.EngineConfigurationFactoryServlet",
  +                                "org.apache.axis.configuration.EngineConfigurationFactoryDefault",
  +                                })
  +                            );
                               
                           ResourceNameIterator it = nameDiscoverers.findResourceNames(mySpi.getName());
                   
  @@ -164,42 +171,18 @@
                           while (factory == null  &&  services.hasNext()) {
                               Class service = services.nextResourceClass().loadClass();
                   
  -                            factory = newFactory(service, newFactoryParamTypes, params);
  -                        }
  -                
  -                        if (factory == null) {
  -                            String className = "org.apache.axis.configuration.EngineConfigurationFactoryServlet"; 
  -                            try {
  -                                ClassLoader loader = EngineConfigurationFactory.class.getClassLoader(); 
  -                                Class clazz = loader.loadClass(className);
  -                                Method method =
  -                                    ClassUtils.findPublicStaticMethod(clazz,
  -                                                                      EngineConfigurationFactory.class,
  -                                                                      "newFactory",
  -                                                                      newFactoryParamTypes);
  -                                factory = (EngineConfigurationFactory)method.invoke(null, params);
  -                            } catch (ClassNotFoundException e) {
  -                            } catch (Throwable e) {
  -                                log.warn(Messages.getMessage("engineConfigInvokeNewFactory",
  -                                                              className,
  -                                                              requiredMethod), e);
  -                            }
  -                
  -                            if (factory == null) {
  -                                try {
  -                                    // should NEVER return null.
  -                                    factory = EngineConfigurationFactoryDefault.newFactory(obj);
  -                                } catch (Throwable e) {
  -                                    log.warn(Messages.getMessage("engineConfigInvokeNewFactory",
  -                                                                  EngineConfigurationFactoryDefault.class.getName(),
  -                                                                  requiredMethod), e);
  -                                }
  +                            /* service == null
  +                             * if class resource wasn't loadable
  +                             */
  +                            if (service != null) {
  +                                factory = newFactory(service, newFactoryParamTypes, params);
                               }
                           }
                   
                           if (factory != null) {
  -                            if(log.isDebugEnabled())
  +                            if(log.isDebugEnabled()) {
                                   log.debug(Messages.getMessage("engineFactory", factory.getClass().getName()));
  +                            }
                           } else {
                               log.error(Messages.getMessage("engineConfigFactoryMissing"));
                               // we should be throwing an exception here,
  
  
  
  1.1                  xml-axis/java/src/org/apache/axis/discovery/DiscoverConstNames.java
  
  Index: DiscoverConstNames.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  package org.apache.axis.discovery;
  
  import java.util.HashMap;
  
  import org.apache.axis.EngineConfigurationFactory;
  import org.apache.commons.discovery.ResourceNameDiscover;
  import org.apache.commons.discovery.ResourceNameIterator;
  import org.apache.commons.discovery.log.DiscoveryLogFactory;
  import org.apache.commons.discovery.resource.names.ResourceNameDiscoverImpl;
  import org.apache.commons.discovery.tools.ManagedProperties;
  import org.apache.commons.logging.Log;
  
  
  /**
   * Recover resource name from Managed Properties,
   * using OLD property names.
   * 
   * This class maintains a mapping between old names and
   * (new) the class names they represent.  The discovery
   * mechanism uses the class names as property names.
   * 
   * @see org.apache.commons.discovery.tools.ManagedProperties
   * 
   * @author Richard A. Sitze
   */
  public class DiscoverConstNames
      extends ResourceNameDiscoverImpl
      implements ResourceNameDiscover
  {
      private static Log log = DiscoveryLogFactory.newLog(DiscoverConstNames.class);
      public static void setLog(Log _log) {
          log = _log;
      }
      
      private final String[] names;
      
      /** Construct a new resource discoverer
       */
      public DiscoverConstNames(String name) {
          this.names = new String[] { name };
      }
  
      public DiscoverConstNames(String [] names) {
          this.names = names;
      }
  
      /**
       * @return Enumeration of ResourceInfo
       */
      public ResourceNameIterator findResourceNames(final String resourceName) {
          if (log.isDebugEnabled()) {
              log.debug("find: resourceName='" + resourceName + "'");
          }
  
          return new ResourceNameIterator() {
              private int idx = 0;
              
              public boolean hasNext() {
                  return idx < names.length;
              }
              
              public String nextResourceName() {
                  return hasNext() ? names[idx++] : null;
              }
          };
      }
  }