FileDocCategorySizeDatePackage
EngineConfigurationFactoryFinder.javaAPI DocApache Axis 1.49115Sat Apr 22 18:57:28 BST 2006org.apache.axis.configuration

EngineConfigurationFactoryFinder

public class EngineConfigurationFactoryFinder extends Object
This is a default implementation of EngineConfigurationFactory. It is user-overrideable by a system property without affecting the caller. If you decide to override it, use delegation if you want to inherit the behaviour of this class as using class extension will result in tight loops. That is, your class should implement EngineConfigurationFactory and keep an instance of this class in a member field and delegate methods to that instance when the default behaviour is required.
author
Richard A. Sitze

Fields Summary
protected static Log
log
private static final Class
mySpi
private static final Class[]
newFactoryParamTypes
private static final String
requiredMethod
Constructors Summary
private EngineConfigurationFactoryFinder()


     
        AxisProperties.setClassOverrideProperty(
                EngineConfigurationFactory.class,
                EngineConfigurationFactory.SYSTEM_PROPERTY_NAME);

        AxisProperties.setClassDefaults(EngineConfigurationFactory.class,
                            new String[] {
                                "org.apache.axis.configuration.EngineConfigurationFactoryServlet",
                                "org.apache.axis.configuration.EngineConfigurationFactoryDefault",
                                });
    
    
Methods Summary
public static org.apache.axis.EngineConfigurationFactorynewFactory(java.lang.Object obj)
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. ***

        /**
         * recreate on each call is critical to gaining
         * the right class loaders.  Do not cache.
         */
        final Object[] params = new Object[] { obj };

        /**
         * Find and examine each service
         */
        return (EngineConfigurationFactory)AccessController.doPrivileged(
                new PrivilegedAction() {
                    public Object run() {
                        ResourceClassIterator services = AxisProperties.getResourceClassIterator(mySpi);

                        EngineConfigurationFactory factory = null;

                        while (factory == null  &&  services.hasNext()) {
                          try {
                            Class service = services.nextResourceClass().loadClass();
                
                            /* service == null
                             * if class resource wasn't loadable
                             */
                            if (service != null) {
                                factory = newFactory(service, newFactoryParamTypes, params);
                            }
                          } catch (Exception e) {
                            // there was an exception creating the factory
                            // the most likely cause was the JDK 1.4 problem
                            // in the discovery code that requires servlet.jar
                            // to be in the client classpath.  For now, fall
                            // through to the next factory
                          }
                        }
                
                        if (factory != null) {
                            if(log.isDebugEnabled()) {
                                log.debug(Messages.getMessage("engineFactory", factory.getClass().getName()));
                            }
                        } else {
                            log.error(Messages.getMessage("engineConfigFactoryMissing"));
                            // 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 org.apache.axis.EngineConfigurationFactorynewFactory()

        return newFactory(null);
    
private static org.apache.axis.EngineConfigurationFactorynewFactory(java.lang.Class service, java.lang.Class[] paramTypes, java.lang.Object[] param)

        /**
         * Some JDK's may link on method resolution (findPublicStaticMethod)
         * and others on method call (method.invoke).
         * 
         * Either way, catch class load/resolve problems and return null.
         */
        
        try {
            /**
             * Verify that service implements:
             *  public static EngineConfigurationFactory newFactory(Object);
             */
            Method method = ClassUtils.findPublicStaticMethod(service,
                                                  EngineConfigurationFactory.class,
                                                  "newFactory",
                                                  paramTypes);
    
            if (method == null) {
                log.warn(Messages.getMessage("engineConfigMissingNewFactory",
                                              service.getName(),
                                              requiredMethod));
            } else {
                try {
                    return (EngineConfigurationFactory)method.invoke(null, param);
                } catch (InvocationTargetException e) {
                    if (e.getTargetException() instanceof NoClassDefFoundError) {
                        log.debug(Messages.getMessage("engineConfigLoadFactory",
                                                      service.getName()));
                    } else {
                        log.warn(Messages.getMessage("engineConfigInvokeNewFactory",
                                                      service.getName(),
                                                      requiredMethod), e);
                    }
                } catch (Exception e) {
                    log.warn(Messages.getMessage("engineConfigInvokeNewFactory",
                                                  service.getName(),
                                                  requiredMethod), e);
                }
            }
        } catch (NoClassDefFoundError e) {
            log.debug(Messages.getMessage("engineConfigLoadFactory",
                                          service.getName()));
        }

        return null;