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/11/05 20:15:59 UTC

svn commit: r1031728 - in /myfaces/core/trunk/impl/src/main/java/org/apache/myfaces: renderkit/ spi/ spi/impl/

Author: lu4242
Date: Fri Nov  5 19:15:59 2010
New Revision: 1031728

URL: http://svn.apache.org/viewvc?rev=1031728&view=rev
Log:
MYFACES-2944 Make those add*** methods public in WebXml

Added:
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ServletMapping.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/WebConfigProvider.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/WebConfigProviderFactory.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultWebConfigProvider.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultWebConfigProviderFactory.java
    myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/ServletMappingImpl.java
    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/renderkit/ErrorPageWriter.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

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java?rev=1031728&r1=1031727&r2=1031728&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/renderkit/ErrorPageWriter.java Fri Nov  5 19:15:59 2010
@@ -73,6 +73,8 @@ import org.apache.myfaces.shared_impl.re
 import org.apache.myfaces.shared_impl.util.ClassUtils;
 import org.apache.myfaces.shared_impl.util.StateUtils;
 import org.apache.myfaces.shared_impl.webapp.webxml.WebXml;
+import org.apache.myfaces.spi.WebConfigProvider;
+import org.apache.myfaces.spi.WebConfigProviderFactory;
 import org.apache.myfaces.view.facelets.component.UIRepeat;
 
 /**
@@ -357,8 +359,12 @@ public final class ErrorPageWriter
         
         // check if an error page is present in web.xml
         // if so, do not generate an error page
-        WebXml webXml = WebXml.getWebXml(facesContext.getExternalContext());
-        if (webXml.isErrorPagePresent())
+        //WebXml webXml = WebXml.getWebXml(facesContext.getExternalContext());
+        //if (webXml.isErrorPagePresent())
+        WebConfigProvider webConfigProvider = WebConfigProviderFactory.getWebXmlProviderFactory(
+                facesContext.getExternalContext()).getWebXmlProvider(facesContext.getExternalContext());
+        
+        if(webConfigProvider.isErrorPagePresent(facesContext.getExternalContext()))
         {
             // save current view in the request map to access it on the error page
             facesContext.getExternalContext().getRequestMap().put(VIEW_KEY, facesContext.getViewRoot());

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ServletMapping.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ServletMapping.java?rev=1031728&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ServletMapping.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/ServletMapping.java Fri Nov  5 19:15:59 2010
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+/**
+ * This interface provides a method to indicate a mapping used for
+ * a servlet class.
+ * 
+ * @author Leonardo Uribe
+ * @since 2.0.3
+ */
+public interface ServletMapping
+{
+    public Class getServletClass();
+    
+    public String getUrlPattern();
+    
+    public String getServletName();
+    
+    public String getPrefix();
+    
+    public String getExtension();
+    
+    public boolean isExtensionMapping();
+    
+}

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/WebConfigProvider.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/WebConfigProvider.java?rev=1031728&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/WebConfigProvider.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/WebConfigProvider.java Fri Nov  5 19:15:59 2010
@@ -0,0 +1,58 @@
+/*
+ * 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;
+
+import java.util.List;
+
+import javax.faces.context.ExternalContext;
+
+/**
+ * SPI to provide a custom WebXml implementation.
+ *
+ * @author Leonardo Uribe
+ * @since 2.0.3
+ */
+public abstract class WebConfigProvider
+{
+
+    /**
+     * Return the mappings configured on web.xml related to JSF FacesServlet.
+     * <p>
+     * By default, the algorithm contemplate these three options:
+     * </p>
+     * <ol>
+     *   <li>Mappings related to registered servlet class javax.faces.webapp.FacesServlet.</li>
+     *   <li>Mappings related to registered servlet class implementing org.apache.myfaces.shared_impl.webapp.webxml.DelegatedFacesServlet interface.</li>
+     *   <li>Mappings related to registered servlet class registered using org.apache.myfaces.DELEGATE_FACES_SERVLET web config param.</li>
+     * </ol>
+     * 
+     * @param externalContext
+     * @return
+     */
+    public abstract List<ServletMapping> getFacesServletMappings(ExternalContext externalContext);
+
+    /**
+     * Indicate if an error page is configured on web.xml file
+     * 
+     * @param externalContext
+     * @return
+     */
+    public abstract boolean isErrorPagePresent(ExternalContext externalContext);
+    
+}
\ No newline at end of file

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/WebConfigProviderFactory.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/WebConfigProviderFactory.java?rev=1031728&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/WebConfigProviderFactory.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/WebConfigProviderFactory.java Fri Nov  5 19:15:59 2010
@@ -0,0 +1,97 @@
+/*
+ * 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;
+
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+
+import org.apache.commons.discovery.tools.DiscoverSingleton;
+import org.apache.myfaces.spi.impl.DefaultWebConfigProviderFactory;
+
+/**
+ * SPI to provide a WebConfigProviderFactory implementation and thus
+ * a custom WebConfigProvider instance.
+ *
+ * @author Jakob Korherr
+ * @author Leonardo Uribe
+ * @since 2.0.3
+ */
+public abstract class WebConfigProviderFactory
+{
+
+    protected static final String FACTORY_DEFAULT = DefaultWebConfigProviderFactory.class.getName();
+
+    private static final String FACTORY_KEY = WebConfigProviderFactory.class.getName();
+
+    public static WebConfigProviderFactory getWebXmlProviderFactory(ExternalContext ctx)
+    {
+        WebConfigProviderFactory factory = (WebConfigProviderFactory) ctx.getApplicationMap().get(FACTORY_KEY);
+        if (factory != null)
+        {
+            // use cached instance
+            return factory;
+        }
+
+        // create new instance from service entry
+        try
+        {
+
+            if (System.getSecurityManager() != null)
+            {
+                factory = (WebConfigProviderFactory) AccessController.doPrivileged(
+                        new java.security.PrivilegedExceptionAction<Object>()
+                        {
+                            public Object run() throws PrivilegedActionException
+                            {
+                                return DiscoverSingleton.find(
+                                        WebConfigProviderFactory.class,
+                                        FACTORY_DEFAULT);
+                            }
+                        });
+            }
+            else
+            {
+                factory = (WebConfigProviderFactory) DiscoverSingleton.find(WebConfigProviderFactory.class, FACTORY_DEFAULT);
+            }
+        }
+        catch (PrivilegedActionException pae)
+        {
+            throw new FacesException(pae);
+        }
+
+        if (factory != null)
+        {
+            // cache instance on ApplicationMap
+            setWebXmlProviderFactory(ctx, factory);
+        }
+
+        return factory;
+    }
+
+    public static void setWebXmlProviderFactory(ExternalContext ctx, WebConfigProviderFactory factory)
+    {
+        ctx.getApplicationMap().put(FACTORY_KEY, factory);
+    }
+
+    public abstract WebConfigProvider getWebXmlProvider(ExternalContext externalContext);
+
+}
\ No newline at end of file

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=1031728&r1=1031727&r2=1031728&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 Fri Nov  5 19:15:59 2010
@@ -22,7 +22,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.spi.impl.SpiUtils;
 import org.apache.myfaces.spi.AnnotationProvider;
 import org.apache.myfaces.spi.AnnotationProviderFactory;
 

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=1031728&r1=1031727&r2=1031728&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 Fri Nov  5 19:15:59 2010
@@ -21,7 +21,6 @@ package org.apache.myfaces.spi.impl;
 import org.apache.commons.discovery.ResourceNameIterator;
 import org.apache.commons.discovery.resource.ClassLoaders;
 import org.apache.commons.discovery.resource.names.DiscoverServiceNames;
-import org.apache.myfaces.shared_impl.spi.impl.SpiUtils;
 import org.apache.myfaces.spi.FaceletConfigResourceProvider;
 import org.apache.myfaces.spi.FaceletConfigResourceProviderFactory;
 import org.apache.myfaces.view.facelets.compiler.DefaultFaceletConfigResourceProvider;

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=1031728&r1=1031727&r2=1031728&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 Fri Nov  5 19:15:59 2010
@@ -18,22 +18,22 @@
  */
 package org.apache.myfaces.spi.impl;
 
+import java.lang.reflect.InvocationTargetException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+
 import org.apache.commons.discovery.ResourceNameIterator;
 import org.apache.commons.discovery.resource.ClassLoaders;
 import org.apache.commons.discovery.resource.names.DiscoverServiceNames;
 import org.apache.myfaces.config.DefaultFacesConfigResourceProvider;
-import org.apache.myfaces.shared_impl.spi.impl.SpiUtils;
 import org.apache.myfaces.spi.FacesConfigResourceProvider;
 import org.apache.myfaces.spi.FacesConfigResourceProviderFactory;
 
-import javax.faces.FacesException;
-import javax.faces.context.ExternalContext;
-import java.lang.reflect.InvocationTargetException;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
 /**
  * 
  * @since 2.0.2

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultWebConfigProvider.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultWebConfigProvider.java?rev=1031728&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultWebConfigProvider.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultWebConfigProvider.java Fri Nov  5 19:15:59 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.util.ArrayList;
+import java.util.List;
+
+import javax.faces.context.ExternalContext;
+
+import org.apache.myfaces.shared_impl.webapp.webxml.WebXml;
+import org.apache.myfaces.spi.ServletMapping;
+import org.apache.myfaces.spi.WebConfigProvider;
+
+/**
+ * The default WebXmlProvider implementation.
+ *
+ * This impl uses the WebXmlParser to create a new instance of WebXmlImpl.
+ *
+ * @author Jakob Korherr
+ */
+public class DefaultWebConfigProvider extends WebConfigProvider
+{
+
+    @Override
+    public List<ServletMapping> getFacesServletMappings(
+            ExternalContext externalContext)
+    {
+        WebXml webXml = WebXml.getWebXml(externalContext);
+       
+        List mapping = webXml.getFacesServletMappings();
+     
+        // In MyFaces 2.0, getFacesServletMappins is used only at startup
+        // time, so we don't need to cache this result.
+        List<ServletMapping> mappingList = new ArrayList<ServletMapping>(mapping.size());
+        
+        for (int i = 0; i < mapping.size(); i++)
+        {
+            org.apache.myfaces.shared_impl.webapp.webxml.ServletMapping delegateMapping = 
+                (org.apache.myfaces.shared_impl.webapp.webxml.ServletMapping) mapping.get(i);
+            
+            mappingList.add(new ServletMappingImpl(delegateMapping));
+        }
+        return mappingList;
+    }
+
+    @Override
+    public boolean isErrorPagePresent(ExternalContext externalContext)
+    {
+        return WebXml.getWebXml(externalContext).isErrorPagePresent();
+    }
+
+}

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultWebConfigProviderFactory.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultWebConfigProviderFactory.java?rev=1031728&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultWebConfigProviderFactory.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/DefaultWebConfigProviderFactory.java Fri Nov  5 19:15:59 2010
@@ -0,0 +1,131 @@
+/*
+ * 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.InvocationTargetException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.faces.FacesException;
+import javax.faces.context.ExternalContext;
+
+import org.apache.commons.discovery.ResourceNameIterator;
+import org.apache.commons.discovery.resource.ClassLoaders;
+import org.apache.commons.discovery.resource.names.DiscoverServiceNames;
+import org.apache.myfaces.spi.WebConfigProvider;
+import org.apache.myfaces.spi.WebConfigProviderFactory;
+
+/**
+ * The default implementation of WebXmlProviderFactory. Looks for META-INF/service
+ * entries of org.apache.myfaces.shared.spi.WebXmlProvider.
+ *
+ * Returns a new DefaultWebXmlProvider if no custom impl can be found.
+ *
+ * @author Jakob Korherr
+ * @since 2.0.3
+ */
+public class DefaultWebConfigProviderFactory extends WebConfigProviderFactory
+{
+
+    public static final String WEB_XML_PROVIDER = WebConfigProvider.class.getName();
+
+    private Logger getLogger()
+    {
+        return Logger.getLogger(DefaultWebConfigProviderFactory.class.getName());
+    }
+
+    @Override
+    public WebConfigProvider getWebXmlProvider(ExternalContext externalContext)
+    {
+        WebConfigProvider returnValue = null;
+        final ExternalContext extContext = externalContext;
+        try
+        {
+            if (System.getSecurityManager() != null)
+            {
+                returnValue = AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<WebConfigProvider>()
+                        {
+                            public WebConfigProvider run() throws ClassNotFoundException,
+                                    NoClassDefFoundError,
+                                    InstantiationException,
+                                    IllegalAccessException,
+                                    InvocationTargetException,
+                                    PrivilegedActionException
+                            {
+                                return resolveWebXmlProviderFromService(extContext);
+                            }
+                        });
+            }
+            else
+            {
+                returnValue = resolveWebXmlProviderFromService(extContext);
+            }
+        }
+        catch (ClassNotFoundException e)
+        {
+            // ignore
+        }
+        catch (NoClassDefFoundError e)
+        {
+            // ignore
+        }
+        catch (InstantiationException e)
+        {
+            getLogger().log(Level.SEVERE, "", e);
+        }
+        catch (IllegalAccessException e)
+        {
+            getLogger().log(Level.SEVERE, "", e);
+        }
+        catch (InvocationTargetException e)
+        {
+            getLogger().log(Level.SEVERE, "", e);
+        }
+        catch (PrivilegedActionException e)
+        {
+            throw new FacesException(e);
+        }
+
+        return returnValue;
+    }
+
+    private WebConfigProvider resolveWebXmlProviderFromService(
+            ExternalContext externalContext) throws ClassNotFoundException,
+            NoClassDefFoundError,
+            InstantiationException,
+            IllegalAccessException,
+            InvocationTargetException,
+            PrivilegedActionException
+    {
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        if (classLoader == null)
+        {
+            classLoader = this.getClass().getClassLoader();
+        }
+        ClassLoaders loaders = new ClassLoaders();
+        loaders.put(classLoader);
+        DiscoverServiceNames dsn = new DiscoverServiceNames(loaders);
+        ResourceNameIterator iter = dsn.findResourceNames(WEB_XML_PROVIDER);
+
+        return SpiUtils.buildApplicationObject(WebConfigProvider.class, iter, new DefaultWebConfigProvider());
+    }
+
+}
\ No newline at end of file

Added: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/ServletMappingImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/ServletMappingImpl.java?rev=1031728&view=auto
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/ServletMappingImpl.java (added)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/spi/impl/ServletMappingImpl.java Fri Nov  5 19:15:59 2010
@@ -0,0 +1,66 @@
+/*
+ * 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 org.apache.myfaces.spi.ServletMapping;
+
+public class ServletMappingImpl implements ServletMapping
+{
+
+    private org.apache.myfaces.shared_impl.webapp.webxml.ServletMapping _delegateMapping;
+
+    public ServletMappingImpl(
+            org.apache.myfaces.shared_impl.webapp.webxml.ServletMapping delegateMapping)
+    {
+        super();
+        this._delegateMapping = delegateMapping;
+    }
+    
+
+    public boolean isExtensionMapping()
+    {
+        return _delegateMapping.isExtensionMapping();
+    }
+
+    public String getExtension()
+    {
+        return _delegateMapping.getExtension();
+    }
+
+    public String getPrefix()
+    {
+        return _delegateMapping.getPrefix();
+    }
+
+    public String getServletName()
+    {
+        return _delegateMapping.getServletName();
+    }
+
+    public Class getServletClass()
+    {
+        return _delegateMapping.getServletClass();
+    }
+
+    public String getUrlPattern()
+    {
+        return _delegateMapping.getUrlPattern();
+    }
+
+}

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=1031728&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 Fri Nov  5 19:15:59 2010
@@ -0,0 +1,186 @@
+/*
+ * 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;
+
+/**
+ * Utils for SPI implementations.
+ *
+ * @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());
+    }
+}
\ No newline at end of file