private Object getImplGivenPreviousImpl(ClassLoader classLoader,
                                                   String factoryName,
                                                   String implName,
                                                   Object previousImpl) {
        Class clazz;
        Class factoryClass = null;
        Class[] getCtorArg;
        Object[] newInstanceArgs = new Object[1];
        Constructor ctor;
        Object result = null;

        // if we have a previousImpl and the appropriate one arg ctor.
        if ((null != previousImpl) &&
             (null != (factoryClass = getFactoryClass(factoryName)))) {
            try {
                clazz = Class.forName(implName, false, classLoader);
                getCtorArg = new Class[1];
                getCtorArg[0] = factoryClass;
                ctor = clazz.getConstructor(getCtorArg);
                newInstanceArgs[0] = previousImpl;
                result = ctor.newInstance(newInstanceArgs);
            }
            catch (NoSuchMethodException nsme) {
                // fall through to "zero-arg-ctor" case
                factoryClass = null;
            }
            catch (Exception e) {
                throw new FacesException(implName, e);
            }
        }
        if (null == previousImpl || null == factoryClass) {
            // we have either no previousImpl or no appropriate one arg
            // ctor.
            try {
                clazz = Class.forName(implName, false, classLoader);
                // since this is the hard coded implementation default,
                // there is no preceding implementation, so don't bother
                // with a non-zero-arg ctor.
                result = clazz.newInstance();
            } catch (Exception e) {
                throw new FacesException(implName, e);
            }
        }
        
        if (null != result) {
            InjectionProvider provider = getInjectionProvider();
            if (null != provider) {
                try {
                    provider.inject(result);
                    provider.invokePostConstruct(result);
                }
                catch (Exception e) {
                    throw new FacesException(implName, e);
                }
            } else {
                if (LOGGER.isLoggable(Level.SEVERE)) {
                    LOGGER.log(Level.SEVERE, "Unable to inject {0} because no InjectionProvider can be found. Does this container implement the Mojarra Injection SPI?", result);
                }
            }
        }            

        return result;

    }
private Object getImplGivenPreviousImpl ( ClassLoader classLoader , String factoryName , String implName , Object previousImpl ) { Class clazz ; Class factoryClass = null ; Class [ ] getCtorArg ; Object [ ] newInstanceArgs = new Object [ 1 ] ; Constructor ctor ; Object result = null ; if ( ( null != previousImpl ) && ( null != ( factoryClass = getFactoryClass ( factoryName ) ) ) ) { try { clazz = Class . forName ( implName , false , classLoader ) ; getCtorArg = new Class [ 1 ] ; getCtorArg [ 0 ] = factoryClass ; ctor = clazz . getConstructor ( getCtorArg ) ; newInstanceArgs [ 0 ] = previousImpl ; result = ctor . newInstance ( newInstanceArgs ) ; } catch ( NoSuchMethodException nsme ) { factoryClass = null ; } catch ( Exception e ) { throw new FacesException ( implName , e ) ; } } if ( null == previousImpl || null == factoryClass ) { try { clazz = Class . forName ( implName , false , classLoader ) ; result = clazz . newInstance ( ) ; } catch ( Exception e ) { throw new FacesException ( implName , e ) ; } } if ( null != result ) { InjectionProvider provider = getInjectionProvider ( ) ; if ( null != provider ) { try { provider . inject ( result ) ; provider . invokePostConstruct ( result ) ; } catch ( Exception e ) { throw new FacesException ( implName , e ) ; } } else { if ( LOGGER . isLoggable ( Level . SEVERE ) ) { LOGGER . log ( Level . SEVERE , "Unable to inject {0} because no InjectionProvider can be found. Does this container implement the Mojarra Injection SPI?" , result ) ; } } } return result ; }
<p>Implement the decorator pattern for the factory
implementation.</p>
<p/>
<p>If <code>previousImpl</code> is non-<code>null</code> and the
class named by the argument <code>implName</code> has a one arg
contstructor of type <code>factoryName</code>, instantiate it,
passing previousImpl to the constructor.</p>
<p/>
<p>Otherwise, we just instantiate and return
<code>implName</code>.</p>

@param classLoader  the ClassLoader from which to load the class
@param factoryName  the fully qualified class name of the factory.
@param implName     the fully qualified class name of a class that
implements the factory.
@param previousImpl if non-<code>null</code>, the factory
instance to be passed to the constructor of the new factory.