You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/10/04 22:14:59 UTC

svn commit: r1004389 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces: config/ spi/impl/ view/facelets/

Author: lu4242
Date: Mon Oct  4 20:14:59 2010
New Revision: 1004389

URL: http://svn.apache.org/viewvc?rev=1004389&view=rev
Log:
MYFACES-2937 Change getApplicationObject function name to buildApplicationObject and move it to shared ClassUtils

Added:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/SpiUtils.java
Modified:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultAnnotationProviderFactory.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFaceletConfigResourceProviderFactory.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesConfigResourceProviderFactory.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java?rev=1004389&r1=1004388&r2=1004389&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/config/FacesConfigurator.java Mon Oct  4 20:14:59 2010
@@ -1926,7 +1926,7 @@ public class FacesConfigurator
         Application application = ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
 
         FacesConfigDispenser<FacesConfig> dispenser = getDispenser();
-        application.setActionListener(getApplicationObject(ActionListener.class,
+        application.setActionListener(ClassUtils.buildApplicationObject(ActionListener.class,
                                                            dispenser.getActionListenerIterator(), null));
 
         if (dispenser.getDefaultLocale() != null)
@@ -1944,17 +1944,17 @@ public class FacesConfigurator
             application.setMessageBundle(dispenser.getMessageBundle());
         }
 
-        application.setNavigationHandler(getApplicationObject(NavigationHandler.class,
+        application.setNavigationHandler(ClassUtils.buildApplicationObject(NavigationHandler.class,
                                                               ConfigurableNavigationHandler.class,
                                                               BackwardsCompatibleNavigationHandlerWrapper.class,
                                                               dispenser.getNavigationHandlerIterator(),
                                                               application.getNavigationHandler()));
 
-        application.setStateManager(getApplicationObject(StateManager.class,
+        application.setStateManager(ClassUtils.buildApplicationObject(StateManager.class,
                                                          dispenser.getStateManagerIterator(),
                                                          application.getStateManager()));
 
-        application.setResourceHandler(getApplicationObject(ResourceHandler.class,
+        application.setResourceHandler(ClassUtils.buildApplicationObject(ResourceHandler.class,
                                                             dispenser.getResourceHandlerIterator(),
                                                             application.getResourceHandler()));
 
@@ -1966,7 +1966,7 @@ public class FacesConfigurator
 
         application.setSupportedLocales(locales);
 
-        application.setViewHandler(getApplicationObject(ViewHandler.class,
+        application.setViewHandler(ClassUtils.buildApplicationObject(ViewHandler.class,
                                                         dispenser.getViewHandlerIterator(),
                                                         application.getViewHandler()));
         for (SystemEventListener systemEventListener : dispenser.getSystemEventListeners())
@@ -2073,11 +2073,11 @@ public class FacesConfigurator
         
         RuntimeConfig runtimeConfig = getRuntimeConfig();
 
-        runtimeConfig.setPropertyResolverChainHead(getApplicationObject(PropertyResolver.class,
+        runtimeConfig.setPropertyResolverChainHead(ClassUtils.buildApplicationObject(PropertyResolver.class,
                                                                         dispenser.getPropertyResolverIterator(),
                                                                         new DefaultPropertyResolver()));
 
-        runtimeConfig.setVariableResolverChainHead(getApplicationObject(VariableResolver.class,
+        runtimeConfig.setVariableResolverChainHead(ClassUtils.buildApplicationObject(VariableResolver.class,
                                                                         dispenser.getVariableResolverIterator(),
                                                                         new VariableResolverImpl()));
     }
@@ -2121,148 +2121,6 @@ public class FacesConfigurator
     {
         _runtimeConfig = runtimeConfig;
     }
-    
-    private <T> T getApplicationObject(Class<T> interfaceClass, Collection<String> classNamesIterator, T defaultObject)
-    {
-        return getApplicationObject(interfaceClass, null, null, classNamesIterator, defaultObject);
-    }
-
-    /**
-     * Creates ApplicationObjects like NavigationHandler or StateManager and creates 
-     * the right wrapping chain of the ApplicationObjects known as the decorator pattern. 
-     * @param <T>
-     * @param interfaceClass The class from which the implementation has to inherit from.
-     * @param extendedInterfaceClass A subclass of interfaceClass which specifies a more
-     *                               detailed implementation.
-     * @param extendedInterfaceWrapperClass A wrapper class for the case that you have an ApplicationObject
-     *                                      which only implements the interfaceClass but not the 
-     *                                      extendedInterfaceClass.
-     * @param classNamesIterator All the class names of the actual ApplicationObject implementations
-     *                           from the faces-config.xml.
-     * @param defaultObject The default implementation for the given ApplicationObject.
-     * @return
-     */
-    @SuppressWarnings("unchecked")
-    private <T> T getApplicationObject(Class<T> interfaceClass, Class<? extends T> extendedInterfaceClass,
-            Class<? extends T> extendedInterfaceWrapperClass,
-            Collection<String> classNamesIterator, T defaultObject)
-    {
-        T current = defaultObject;
-        
-
-        for (String implClassName : classNamesIterator)
-        {
-            Class<? extends T> implClass = ClassUtils.simpleClassForName(implClassName);
-
-            // check, if class is of expected interface type
-            if (!interfaceClass.isAssignableFrom(implClass))
-            {
-                throw new IllegalArgumentException("Class " + implClassName + " is no " + interfaceClass.getName());
-            }
-
-            if (current == null)
-            {
-                // nothing to decorate
-                current = (T) ClassUtils.newInstance(implClass);
-            }
-            else
-            {
-                // let's check if class supports the decorator pattern
-                T newCurrent = null;
-                try
-                {
-                    Constructor<? extends T> delegationConstructor = null;
-                    
-                    // first, if there is a extendedInterfaceClass,
-                    // try to find a constructor that uses that
-                    if (extendedInterfaceClass != null 
-                            && extendedInterfaceClass.isAssignableFrom(current.getClass()))
-                    {
-                        try
-                        {
-                            delegationConstructor = 
-                                    implClass.getConstructor(new Class[] {extendedInterfaceClass});
-                        }
-                        catch (NoSuchMethodException mnfe)
-                        {
-                            // just eat it
-                        }
-                    }
-                    if (delegationConstructor == null)
-                    {
-                        // try to find the constructor with the "normal" interfaceClass
-                        delegationConstructor = 
-                                implClass.getConstructor(new Class[] {interfaceClass});
-                    }
-                    // impl class supports decorator pattern at this point
-                    try
-                    {
-                        // create new decorator wrapping current
-                        newCurrent = delegationConstructor.newInstance(new Object[] { current });
-                    }
-                    catch (InstantiationException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (IllegalAccessException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InvocationTargetException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                }
-                catch (NoSuchMethodException e)
-                {
-                    // no decorator pattern support
-                    newCurrent = (T) ClassUtils.newInstance(implClass);
-                }
-                
-                // now we have a new current object (newCurrent)
-                // --> find out if it is assignable from extendedInterfaceClass
-                // and if not, wrap it in a backwards compatible wrapper (if available)
-                if (extendedInterfaceWrapperClass != null
-                        && !extendedInterfaceClass.isAssignableFrom(newCurrent.getClass()))
-                {
-                    try
-                    {
-                        Constructor<? extends T> wrapperConstructor
-                                = extendedInterfaceWrapperClass.getConstructor(
-                                        new Class[] {interfaceClass, extendedInterfaceClass});
-                        newCurrent = wrapperConstructor.newInstance(new Object[] {newCurrent, current});
-                    }
-                    catch (NoSuchMethodException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InstantiationException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (IllegalAccessException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InvocationTargetException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                }
-                
-                current = newCurrent;
-            }
-        }
-
-        return current;
-    }
 
     private void configureRuntimeConfig()
     {
@@ -2348,7 +2206,7 @@ public class FacesConfigurator
             }
 
             //RenderKit renderKit = (RenderKit) ClassUtils.newInstance(renderKitClass);
-            RenderKit renderKit = (RenderKit) getApplicationObject(RenderKit.class, renderKitClass, null);
+            RenderKit renderKit = (RenderKit) ClassUtils.buildApplicationObject(RenderKit.class, renderKitClass, null);
 
             for (Renderer element : dispenser.getRenderers(renderKitId))
             {

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultAnnotationProviderFactory.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultAnnotationProviderFactory.java?rev=1004389&r1=1004388&r2=1004389&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultAnnotationProviderFactory.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultAnnotationProviderFactory.java Mon Oct  4 20:14:59 2010
@@ -18,7 +18,6 @@
  */
 package org.apache.myfaces.spi.impl;
 
-import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
@@ -32,7 +31,6 @@ import org.apache.commons.discovery.Reso
 import org.apache.commons.discovery.resource.ClassLoaders;
 import org.apache.commons.discovery.resource.names.DiscoverServiceNames;
 import org.apache.myfaces.config.annotation.DefaultAnnotationProvider;
-import org.apache.myfaces.shared_impl.util.ClassUtils;
 import org.apache.myfaces.spi.AnnotationProvider;
 import org.apache.myfaces.spi.AnnotationProviderFactory;
 
@@ -43,10 +41,13 @@ import org.apache.myfaces.spi.Annotation
  */
 public class DefaultAnnotationProviderFactory extends AnnotationProviderFactory
 {
-    private static Logger log = Logger.getLogger(DefaultAnnotationProviderFactory.class.getName());
-
     public static final String ANNOTATION_PROVIDER = AnnotationProvider.class.getName();
     
+    private Logger getLogger()
+    {
+        return Logger.getLogger(DefaultAnnotationProviderFactory.class.getName());
+    }
+    
     @Override
     public AnnotationProvider createAnnotationProvider(
             ExternalContext externalContext)
@@ -85,15 +86,15 @@ public class DefaultAnnotationProviderFa
         }
         catch (InstantiationException e)
         {
-            log.log(Level.SEVERE, "", e);
+            getLogger().log(Level.SEVERE, "", e);
         }
         catch (IllegalAccessException e)
         {
-            log.log(Level.SEVERE, "", e);
+            getLogger().log(Level.SEVERE, "", e);
         }
         catch (InvocationTargetException e)
         {
-            log.log(Level.SEVERE, "", e);
+            getLogger().log(Level.SEVERE, "", e);
         }
         catch (PrivilegedActionException e)
         {
@@ -119,148 +120,6 @@ public class DefaultAnnotationProviderFa
         loaders.put(classLoader);
         DiscoverServiceNames dsn = new DiscoverServiceNames(loaders);
         ResourceNameIterator iter = dsn.findResourceNames(ANNOTATION_PROVIDER);
-        return getApplicationObject(AnnotationProvider.class, iter, new DefaultAnnotationProvider());
-    }
-
-    private <T> T getApplicationObject(Class<T> interfaceClass, ResourceNameIterator classNamesIterator, T defaultObject)
-    {
-        return getApplicationObject(interfaceClass, null, null, classNamesIterator, defaultObject);
+        return SpiUtils.buildApplicationObject(AnnotationProvider.class, iter, new DefaultAnnotationProvider());
     }
-
-    /**
-     * Creates ApplicationObjects like NavigationHandler or StateManager and creates 
-     * the right wrapping chain of the ApplicationObjects known as the decorator pattern. 
-     * @param <T>
-     * @param interfaceClass The class from which the implementation has to inherit from.
-     * @param extendedInterfaceClass A subclass of interfaceClass which specifies a more
-     *                               detailed implementation.
-     * @param extendedInterfaceWrapperClass A wrapper class for the case that you have an ApplicationObject
-     *                                      which only implements the interfaceClass but not the 
-     *                                      extendedInterfaceClass.
-     * @param classNamesIterator All the class names of the actual ApplicationObject implementations
-     *                           from the faces-config.xml.
-     * @param defaultObject The default implementation for the given ApplicationObject.
-     * @return
-     */
-    @SuppressWarnings("unchecked")
-    private <T> T getApplicationObject(Class<T> interfaceClass, Class<? extends T> extendedInterfaceClass,
-            Class<? extends T> extendedInterfaceWrapperClass,
-            ResourceNameIterator classNamesIterator, T defaultObject)
-    {
-        T current = defaultObject;
-
-        while (classNamesIterator.hasNext())
-        {
-            String implClassName = classNamesIterator.nextResourceName();
-            Class<? extends T> implClass = ClassUtils.simpleClassForName(implClassName);
-
-            // check, if class is of expected interface type
-            if (!interfaceClass.isAssignableFrom(implClass))
-            {
-                throw new IllegalArgumentException("Class " + implClassName + " is no " + interfaceClass.getName());
-            }
-
-            if (current == null)
-            {
-                // nothing to decorate
-                current = (T) ClassUtils.newInstance(implClass);
-            }
-            else
-            {
-                // let's check if class supports the decorator pattern
-                T newCurrent = null;
-                try
-                {
-                    Constructor<? extends T> delegationConstructor = null;
-                    
-                    // first, if there is a extendedInterfaceClass,
-                    // try to find a constructor that uses that
-                    if (extendedInterfaceClass != null 
-                            && extendedInterfaceClass.isAssignableFrom(current.getClass()))
-                    {
-                        try
-                        {
-                            delegationConstructor = 
-                                    implClass.getConstructor(new Class[] {extendedInterfaceClass});
-                        }
-                        catch (NoSuchMethodException mnfe)
-                        {
-                            // just eat it
-                        }
-                    }
-                    if (delegationConstructor == null)
-                    {
-                        // try to find the constructor with the "normal" interfaceClass
-                        delegationConstructor = 
-                                implClass.getConstructor(new Class[] {interfaceClass});
-                    }
-                    // impl class supports decorator pattern at this point
-                    try
-                    {
-                        // create new decorator wrapping current
-                        newCurrent = delegationConstructor.newInstance(new Object[] { current });
-                    }
-                    catch (InstantiationException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (IllegalAccessException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InvocationTargetException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                }
-                catch (NoSuchMethodException e)
-                {
-                    // no decorator pattern support
-                    newCurrent = (T) ClassUtils.newInstance(implClass);
-                }
-                
-                // now we have a new current object (newCurrent)
-                // --> find out if it is assignable from extendedInterfaceClass
-                // and if not, wrap it in a backwards compatible wrapper (if available)
-                if (extendedInterfaceWrapperClass != null
-                        && !extendedInterfaceClass.isAssignableFrom(newCurrent.getClass()))
-                {
-                    try
-                    {
-                        Constructor<? extends T> wrapperConstructor
-                                = extendedInterfaceWrapperClass.getConstructor(
-                                        new Class[] {interfaceClass, extendedInterfaceClass});
-                        newCurrent = wrapperConstructor.newInstance(new Object[] {newCurrent, current});
-                    }
-                    catch (NoSuchMethodException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InstantiationException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (IllegalAccessException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InvocationTargetException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                }
-                
-                current = newCurrent;
-            }
-        }
-
-        return current;
-    }    
 }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFaceletConfigResourceProviderFactory.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFaceletConfigResourceProviderFactory.java?rev=1004389&r1=1004388&r2=1004389&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFaceletConfigResourceProviderFactory.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFaceletConfigResourceProviderFactory.java Mon Oct  4 20:14:59 2010
@@ -43,9 +43,12 @@ import org.apache.myfaces.view.facelets.
  */
 public class DefaultFaceletConfigResourceProviderFactory extends FaceletConfigResourceProviderFactory
 {
-    private static Logger log = Logger.getLogger(DefaultFaceletConfigResourceProviderFactory.class.getName());
-
     public static final String ANNOTATION_PROVIDER = FaceletConfigResourceProvider.class.getName();
+
+    private Logger getLogger()
+    {
+        return Logger.getLogger(DefaultFaceletConfigResourceProviderFactory.class.getName());
+    }
     
     @Override
     public FaceletConfigResourceProvider createFaceletConfigResourceProvider(
@@ -85,15 +88,15 @@ public class DefaultFaceletConfigResourc
         }
         catch (InstantiationException e)
         {
-            log.log(Level.SEVERE, "", e);
+            getLogger().log(Level.SEVERE, "", e);
         }
         catch (IllegalAccessException e)
         {
-            log.log(Level.SEVERE, "", e);
+            getLogger().log(Level.SEVERE, "", e);
         }
         catch (InvocationTargetException e)
         {
-            log.log(Level.SEVERE, "", e);
+            getLogger().log(Level.SEVERE, "", e);
         }
         catch (PrivilegedActionException e)
         {
@@ -119,148 +122,7 @@ public class DefaultFaceletConfigResourc
         loaders.put(classLoader);
         DiscoverServiceNames dsn = new DiscoverServiceNames(loaders);
         ResourceNameIterator iter = dsn.findResourceNames(ANNOTATION_PROVIDER);
-        return getApplicationObject(FaceletConfigResourceProvider.class, iter, new DefaultFaceletConfigResourceProvider());
-    }
-
-    private <T> T getApplicationObject(Class<T> interfaceClass, ResourceNameIterator classNamesIterator, T defaultObject)
-    {
-        return getApplicationObject(interfaceClass, null, null, classNamesIterator, defaultObject);
+        return SpiUtils.buildApplicationObject(FaceletConfigResourceProvider.class, iter, new DefaultFaceletConfigResourceProvider());
     }
 
-    /**
-     * Creates ApplicationObjects like NavigationHandler or StateManager and creates 
-     * the right wrapping chain of the ApplicationObjects known as the decorator pattern. 
-     * @param <T>
-     * @param interfaceClass The class from which the implementation has to inherit from.
-     * @param extendedInterfaceClass A subclass of interfaceClass which specifies a more
-     *                               detailed implementation.
-     * @param extendedInterfaceWrapperClass A wrapper class for the case that you have an ApplicationObject
-     *                                      which only implements the interfaceClass but not the 
-     *                                      extendedInterfaceClass.
-     * @param classNamesIterator All the class names of the actual ApplicationObject implementations
-     *                           from the faces-config.xml.
-     * @param defaultObject The default implementation for the given ApplicationObject.
-     * @return
-     */
-    @SuppressWarnings("unchecked")
-    private <T> T getApplicationObject(Class<T> interfaceClass, Class<? extends T> extendedInterfaceClass,
-            Class<? extends T> extendedInterfaceWrapperClass,
-            ResourceNameIterator classNamesIterator, T defaultObject)
-    {
-        T current = defaultObject;
-
-        while (classNamesIterator.hasNext())
-        {
-            String implClassName = classNamesIterator.nextResourceName();
-            Class<? extends T> implClass = ClassUtils.simpleClassForName(implClassName);
-
-            // check, if class is of expected interface type
-            if (!interfaceClass.isAssignableFrom(implClass))
-            {
-                throw new IllegalArgumentException("Class " + implClassName + " is no " + interfaceClass.getName());
-            }
-
-            if (current == null)
-            {
-                // nothing to decorate
-                current = (T) ClassUtils.newInstance(implClass);
-            }
-            else
-            {
-                // let's check if class supports the decorator pattern
-                T newCurrent = null;
-                try
-                {
-                    Constructor<? extends T> delegationConstructor = null;
-                    
-                    // first, if there is a extendedInterfaceClass,
-                    // try to find a constructor that uses that
-                    if (extendedInterfaceClass != null 
-                            && extendedInterfaceClass.isAssignableFrom(current.getClass()))
-                    {
-                        try
-                        {
-                            delegationConstructor = 
-                                    implClass.getConstructor(new Class[] {extendedInterfaceClass});
-                        }
-                        catch (NoSuchMethodException mnfe)
-                        {
-                            // just eat it
-                        }
-                    }
-                    if (delegationConstructor == null)
-                    {
-                        // try to find the constructor with the "normal" interfaceClass
-                        delegationConstructor = 
-                                implClass.getConstructor(new Class[] {interfaceClass});
-                    }
-                    // impl class supports decorator pattern at this point
-                    try
-                    {
-                        // create new decorator wrapping current
-                        newCurrent = delegationConstructor.newInstance(new Object[] { current });
-                    }
-                    catch (InstantiationException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (IllegalAccessException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InvocationTargetException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                }
-                catch (NoSuchMethodException e)
-                {
-                    // no decorator pattern support
-                    newCurrent = (T) ClassUtils.newInstance(implClass);
-                }
-                
-                // now we have a new current object (newCurrent)
-                // --> find out if it is assignable from extendedInterfaceClass
-                // and if not, wrap it in a backwards compatible wrapper (if available)
-                if (extendedInterfaceWrapperClass != null
-                        && !extendedInterfaceClass.isAssignableFrom(newCurrent.getClass()))
-                {
-                    try
-                    {
-                        Constructor<? extends T> wrapperConstructor
-                                = extendedInterfaceWrapperClass.getConstructor(
-                                        new Class[] {interfaceClass, extendedInterfaceClass});
-                        newCurrent = wrapperConstructor.newInstance(new Object[] {newCurrent, current});
-                    }
-                    catch (NoSuchMethodException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InstantiationException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (IllegalAccessException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InvocationTargetException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                }
-                
-                current = newCurrent;
-            }
-        }
-
-        return current;
-    }    
 }

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesConfigResourceProviderFactory.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesConfigResourceProviderFactory.java?rev=1004389&r1=1004388&r2=1004389&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesConfigResourceProviderFactory.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultFacesConfigResourceProviderFactory.java Mon Oct  4 20:14:59 2010
@@ -43,10 +43,13 @@ import org.apache.myfaces.spi.FacesConfi
  */
 public class DefaultFacesConfigResourceProviderFactory extends FacesConfigResourceProviderFactory
 {
-    private static Logger log = Logger.getLogger(DefaultFacesConfigResourceProviderFactory.class.getName());
-
     public static final String ANNOTATION_PROVIDER = FacesConfigResourceProvider.class.getName();
     
+    private Logger getLogger()
+    {
+        return Logger.getLogger(DefaultFacesConfigResourceProviderFactory.class.getName());
+    }    
+    
     @Override
     public FacesConfigResourceProvider createFacesConfigResourceProvider(
             ExternalContext externalContext)
@@ -85,15 +88,15 @@ public class DefaultFacesConfigResourceP
         }
         catch (InstantiationException e)
         {
-            log.log(Level.SEVERE, "", e);
+            getLogger().log(Level.SEVERE, "", e);
         }
         catch (IllegalAccessException e)
         {
-            log.log(Level.SEVERE, "", e);
+            getLogger().log(Level.SEVERE, "", e);
         }
         catch (InvocationTargetException e)
         {
-            log.log(Level.SEVERE, "", e);
+            getLogger().log(Level.SEVERE, "", e);
         }
         catch (PrivilegedActionException e)
         {
@@ -119,148 +122,7 @@ public class DefaultFacesConfigResourceP
         loaders.put(classLoader);
         DiscoverServiceNames dsn = new DiscoverServiceNames(loaders);
         ResourceNameIterator iter = dsn.findResourceNames(ANNOTATION_PROVIDER);
-        return getApplicationObject(FacesConfigResourceProvider.class, iter, new DefaultFacesConfigResourceProvider());
-    }
-
-    private <T> T getApplicationObject(Class<T> interfaceClass, ResourceNameIterator classNamesIterator, T defaultObject)
-    {
-        return getApplicationObject(interfaceClass, null, null, classNamesIterator, defaultObject);
+        return SpiUtils.buildApplicationObject(FacesConfigResourceProvider.class, iter, new DefaultFacesConfigResourceProvider());
     }
 
-    /**
-     * Creates ApplicationObjects like NavigationHandler or StateManager and creates 
-     * the right wrapping chain of the ApplicationObjects known as the decorator pattern. 
-     * @param <T>
-     * @param interfaceClass The class from which the implementation has to inherit from.
-     * @param extendedInterfaceClass A subclass of interfaceClass which specifies a more
-     *                               detailed implementation.
-     * @param extendedInterfaceWrapperClass A wrapper class for the case that you have an ApplicationObject
-     *                                      which only implements the interfaceClass but not the 
-     *                                      extendedInterfaceClass.
-     * @param classNamesIterator All the class names of the actual ApplicationObject implementations
-     *                           from the faces-config.xml.
-     * @param defaultObject The default implementation for the given ApplicationObject.
-     * @return
-     */
-    @SuppressWarnings("unchecked")
-    private <T> T getApplicationObject(Class<T> interfaceClass, Class<? extends T> extendedInterfaceClass,
-            Class<? extends T> extendedInterfaceWrapperClass,
-            ResourceNameIterator classNamesIterator, T defaultObject)
-    {
-        T current = defaultObject;
-
-        while (classNamesIterator.hasNext())
-        {
-            String implClassName = classNamesIterator.nextResourceName();
-            Class<? extends T> implClass = ClassUtils.simpleClassForName(implClassName);
-
-            // check, if class is of expected interface type
-            if (!interfaceClass.isAssignableFrom(implClass))
-            {
-                throw new IllegalArgumentException("Class " + implClassName + " is no " + interfaceClass.getName());
-            }
-
-            if (current == null)
-            {
-                // nothing to decorate
-                current = (T) ClassUtils.newInstance(implClass);
-            }
-            else
-            {
-                // let's check if class supports the decorator pattern
-                T newCurrent = null;
-                try
-                {
-                    Constructor<? extends T> delegationConstructor = null;
-                    
-                    // first, if there is a extendedInterfaceClass,
-                    // try to find a constructor that uses that
-                    if (extendedInterfaceClass != null 
-                            && extendedInterfaceClass.isAssignableFrom(current.getClass()))
-                    {
-                        try
-                        {
-                            delegationConstructor = 
-                                    implClass.getConstructor(new Class[] {extendedInterfaceClass});
-                        }
-                        catch (NoSuchMethodException mnfe)
-                        {
-                            // just eat it
-                        }
-                    }
-                    if (delegationConstructor == null)
-                    {
-                        // try to find the constructor with the "normal" interfaceClass
-                        delegationConstructor = 
-                                implClass.getConstructor(new Class[] {interfaceClass});
-                    }
-                    // impl class supports decorator pattern at this point
-                    try
-                    {
-                        // create new decorator wrapping current
-                        newCurrent = delegationConstructor.newInstance(new Object[] { current });
-                    }
-                    catch (InstantiationException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (IllegalAccessException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InvocationTargetException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                }
-                catch (NoSuchMethodException e)
-                {
-                    // no decorator pattern support
-                    newCurrent = (T) ClassUtils.newInstance(implClass);
-                }
-                
-                // now we have a new current object (newCurrent)
-                // --> find out if it is assignable from extendedInterfaceClass
-                // and if not, wrap it in a backwards compatible wrapper (if available)
-                if (extendedInterfaceWrapperClass != null
-                        && !extendedInterfaceClass.isAssignableFrom(newCurrent.getClass()))
-                {
-                    try
-                    {
-                        Constructor<? extends T> wrapperConstructor
-                                = extendedInterfaceWrapperClass.getConstructor(
-                                        new Class[] {interfaceClass, extendedInterfaceClass});
-                        newCurrent = wrapperConstructor.newInstance(new Object[] {newCurrent, current});
-                    }
-                    catch (NoSuchMethodException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InstantiationException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (IllegalAccessException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InvocationTargetException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                }
-                
-                current = newCurrent;
-            }
-        }
-
-        return current;
-    }    
 }

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/SpiUtils.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/SpiUtils.java?rev=1004389&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/SpiUtils.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/SpiUtils.java Mon Oct  4 20:14:59 2010
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.spi.impl;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.FacesException;
+
+import org.apache.commons.discovery.ResourceNameIterator;
+import org.apache.myfaces.shared_impl.util.ClassUtils;
+
+/**
+ * 
+ * @since 2.0.3
+ * @author Leonardo Uribe
+ */
+public final class SpiUtils
+{
+
+    public static <T> T buildApplicationObject(Class<T> interfaceClass, ResourceNameIterator classNamesIterator, T defaultObject)
+    {
+        return buildApplicationObject(interfaceClass, null, null, classNamesIterator, defaultObject);
+    }
+
+    /**
+     * Creates ApplicationObjects like NavigationHandler or StateManager and creates 
+     * the right wrapping chain of the ApplicationObjects known as the decorator pattern. 
+     * @param <T>
+     * @param interfaceClass The class from which the implementation has to inherit from.
+     * @param extendedInterfaceClass A subclass of interfaceClass which specifies a more
+     *                               detailed implementation.
+     * @param extendedInterfaceWrapperClass A wrapper class for the case that you have an ApplicationObject
+     *                                      which only implements the interfaceClass but not the 
+     *                                      extendedInterfaceClass.
+     * @param classNamesIterator All the class names of the actual ApplicationObject implementations
+     *                           from the faces-config.xml.
+     * @param defaultObject The default implementation for the given ApplicationObject.
+     * @return
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> T buildApplicationObject(Class<T> interfaceClass, Class<? extends T> extendedInterfaceClass,
+            Class<? extends T> extendedInterfaceWrapperClass,
+            ResourceNameIterator classNamesIterator, T defaultObject)
+    {
+        T current = defaultObject;
+
+        while (classNamesIterator.hasNext())
+        {
+            String implClassName = classNamesIterator.nextResourceName();
+            Class<? extends T> implClass = ClassUtils.simpleClassForName(implClassName);
+
+            // check, if class is of expected interface type
+            if (!interfaceClass.isAssignableFrom(implClass))
+            {
+                throw new IllegalArgumentException("Class " + implClassName + " is no " + interfaceClass.getName());
+            }
+
+            if (current == null)
+            {
+                // nothing to decorate
+                current = (T) ClassUtils.newInstance(implClass);
+            }
+            else
+            {
+                // let's check if class supports the decorator pattern
+                T newCurrent = null;
+                try
+                {
+                    Constructor<? extends T> delegationConstructor = null;
+                    
+                    // first, if there is a extendedInterfaceClass,
+                    // try to find a constructor that uses that
+                    if (extendedInterfaceClass != null 
+                            && extendedInterfaceClass.isAssignableFrom(current.getClass()))
+                    {
+                        try
+                        {
+                            delegationConstructor = 
+                                    implClass.getConstructor(new Class[] {extendedInterfaceClass});
+                        }
+                        catch (NoSuchMethodException mnfe)
+                        {
+                            // just eat it
+                        }
+                    }
+                    if (delegationConstructor == null)
+                    {
+                        // try to find the constructor with the "normal" interfaceClass
+                        delegationConstructor = 
+                                implClass.getConstructor(new Class[] {interfaceClass});
+                    }
+                    // impl class supports decorator pattern at this point
+                    try
+                    {
+                        // create new decorator wrapping current
+                        newCurrent = delegationConstructor.newInstance(new Object[] { current });
+                    }
+                    catch (InstantiationException e)
+                    {
+                        getLogger().log(Level.SEVERE, e.getMessage(), e);
+                        throw new FacesException(e);
+                    }
+                    catch (IllegalAccessException e)
+                    {
+                        getLogger().log(Level.SEVERE, e.getMessage(), e);
+                        throw new FacesException(e);
+                    }
+                    catch (InvocationTargetException e)
+                    {
+                        getLogger().log(Level.SEVERE, e.getMessage(), e);
+                        throw new FacesException(e);
+                    }
+                }
+                catch (NoSuchMethodException e)
+                {
+                    // no decorator pattern support
+                    newCurrent = (T) ClassUtils.newInstance(implClass);
+                }
+                
+                // now we have a new current object (newCurrent)
+                // --> find out if it is assignable from extendedInterfaceClass
+                // and if not, wrap it in a backwards compatible wrapper (if available)
+                if (extendedInterfaceWrapperClass != null
+                        && !extendedInterfaceClass.isAssignableFrom(newCurrent.getClass()))
+                {
+                    try
+                    {
+                        Constructor<? extends T> wrapperConstructor
+                                = extendedInterfaceWrapperClass.getConstructor(
+                                        new Class[] {interfaceClass, extendedInterfaceClass});
+                        newCurrent = wrapperConstructor.newInstance(new Object[] {newCurrent, current});
+                    }
+                    catch (NoSuchMethodException e)
+                    {
+                        getLogger().log(Level.SEVERE, e.getMessage(), e);
+                        throw new FacesException(e);
+                    }
+                    catch (InstantiationException e)
+                    {
+                        getLogger().log(Level.SEVERE, e.getMessage(), e);
+                        throw new FacesException(e);
+                    }
+                    catch (IllegalAccessException e)
+                    {
+                        getLogger().log(Level.SEVERE, e.getMessage(), e);
+                        throw new FacesException(e);
+                    }
+                    catch (InvocationTargetException e)
+                    {
+                        getLogger().log(Level.SEVERE, e.getMessage(), e);
+                        throw new FacesException(e);
+                    }
+                }
+                
+                current = newCurrent;
+            }
+        }
+
+        return current;
+    }
+    
+    private static Logger getLogger()
+    {
+        return Logger.getLogger(SpiUtils.class.getName());
+    }
+}

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java?rev=1004389&r1=1004388&r2=1004389&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/FaceletViewDeclarationLanguage.java Mon Oct  4 20:14:59 2010
@@ -25,11 +25,8 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.Writer;
 import java.lang.reflect.Array;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -1392,69 +1389,12 @@ public class FaceletViewDeclarationLangu
         {
             ArrayList<String> classNames = new ArrayList<String>(1);
             classNames.add(faceletsResourceResolverClassName);
-            resolver = getApplicationObject(ResourceResolver.class, classNames, resolver);
+            resolver = ClassUtils.buildApplicationObject(ResourceResolver.class, classNames, resolver);
         }
 
         return new DefaultFaceletFactory(compiler, resolver, refreshPeriod);
     }
     
-    private <T> T getApplicationObject(Class<T> interfaceClass, Collection<String> classNamesIterator, T defaultObject)
-    {
-        T current = defaultObject;
-
-        for (String implClassName : classNamesIterator)
-        {
-            Class<? extends T> implClass = ClassUtils.simpleClassForName(implClassName);
-
-            // check, if class is of expected interface type
-            if (!interfaceClass.isAssignableFrom(implClass))
-            {
-                throw new IllegalArgumentException("Class " + implClassName + " is no " + interfaceClass.getName());
-            }
-
-            if (current == null)
-            {
-                // nothing to decorate
-                current = (T) ClassUtils.newInstance(implClass);
-            }
-            else
-            {
-                // let's check if class supports the decorator pattern
-                try
-                {
-                    Constructor<? extends T> delegationConstructor = 
-                        implClass.getConstructor(new Class[] {interfaceClass});
-                    // impl class supports decorator pattern,
-                    try
-                    {
-                        // create new decorator wrapping current
-                        current = delegationConstructor.newInstance(new Object[] { current });
-                    }
-                    catch (InstantiationException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (IllegalAccessException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                    catch (InvocationTargetException e)
-                    {
-                        log.log(Level.SEVERE, e.getMessage(), e);
-                        throw new FacesException(e);
-                    }
-                }
-                catch (NoSuchMethodException e)
-                {
-                    // no decorator pattern support
-                    current = (T) ClassUtils.newInstance(implClass);
-                }
-            }
-        }
-        return current;
-    }
 
     protected ResponseWriter createResponseWriter(FacesContext context) throws IOException, FacesException
     {