You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mb...@apache.org on 2007/02/25 14:47:50 UTC

svn commit: r511514 [2/2] - in /myfaces/core/branches/jsf12/impl/src: main/java/org/apache/myfaces/application/ main/java/org/apache/myfaces/el/ main/java/org/apache/myfaces/el/convert/ main/java/org/apache/myfaces/el/unified/ main/java/org/apache/myfa...

Propchange: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/unified/ResolverFactoryForFaces.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/unified/ResolverFactoryForFaces.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/unified/resolver/FacesCompositeELResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/unified/resolver/FacesCompositeELResolver.java?view=auto&rev=511514
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/unified/resolver/FacesCompositeELResolver.java (added)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/unified/resolver/FacesCompositeELResolver.java Sun Feb 25 05:47:48 2007
@@ -0,0 +1,172 @@
+/*
+ * 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.el.unified.resolver;
+
+import org.apache.myfaces.el.VariableResolverImpl;
+
+import javax.el.CompositeELResolver;
+import javax.el.ELContext;
+import javax.faces.application.Application;
+import javax.faces.context.FacesContext;
+import javax.servlet.jsp.JspApplicationContext;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+
+/**
+ * <p>
+ * This composite el resolver will be used at the top level resolver for faces ({@link Application#getELResolver()})
+ * and jsp (the one we add with {@link JspApplicationContext#addELResolver(javax.el.ELResolver)}. It keeps track of its
+ * scope to let the variable resolver {@link VariableResolverImpl} know in which scope it is executed. This is
+ * necessarry to call either the faces or the jsp resolver head.
+ * </p>
+ * <p>
+ * This implementation does nothing if there is no actual faces context. This is necessarry since we registered our
+ * resolvers into the jsp engine. Therefore we have to make sure that jsp only pages where no faces context is available
+ * are still working
+ * </p>
+ * 
+ * @author Mathias Broekelmann (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class FacesCompositeELResolver extends CompositeELResolver
+{
+    private final Scope _scope;
+
+    public enum Scope
+    {
+        Faces, JSP
+    }
+
+    public FacesCompositeELResolver(Scope scope)
+    {
+        if (scope == null)
+        {
+            throw new IllegalArgumentException("scope must not be one of " + Scope.values());
+        }
+        _scope = scope;
+    }
+
+    @Override
+    public Class<?> getCommonPropertyType(final ELContext context, final Object base)
+    {
+        return invoke(new ResolverInvoker<Class<?>>()
+        {
+            public Class<?> invoke()
+            {
+                return FacesCompositeELResolver.super.getCommonPropertyType(context, base);
+            }
+        });
+    }
+
+    @Override
+    public Iterator<FeatureDescriptor> getFeatureDescriptors(final ELContext context, final Object base)
+    {
+        return invoke(new ResolverInvoker<Iterator<FeatureDescriptor>>()
+        {
+            public Iterator<FeatureDescriptor> invoke()
+            {
+                return FacesCompositeELResolver.super.getFeatureDescriptors(context, base);
+            }
+        });
+    }
+
+    @Override
+    public Class<?> getType(final ELContext context, final Object base, final Object property)
+    {
+        return invoke(new ResolverInvoker<Class<?>>()
+        {
+            public Class<?> invoke()
+            {
+                return FacesCompositeELResolver.super.getType(context, base, property);
+            }
+        });
+    }
+
+    @Override
+    public Object getValue(final ELContext context, final Object base, final Object property)
+    {
+        return invoke(new ResolverInvoker<Object>()
+        {
+            public Object invoke()
+            {
+                return FacesCompositeELResolver.super.getValue(context, base, property);
+            }
+        });
+    }
+
+    @Override
+    public boolean isReadOnly(final ELContext context, final Object base, final Object property)
+    {
+        return invoke(new ResolverInvoker<Boolean>()
+        {
+            public Boolean invoke()
+            {
+                return FacesCompositeELResolver.super.isReadOnly(context, base, property);
+            }
+        });
+    }
+
+    @Override
+    public void setValue(final ELContext context, final Object base, final Object property, final Object val)
+    {
+        invoke(new ResolverInvoker<Object>()
+        {
+            public Object invoke()
+            {
+                FacesCompositeELResolver.super.setValue(context, base, property, val);
+                return null;
+            }
+        });
+    }
+
+    <T> T invoke(ResolverInvoker<T> invoker)
+    {
+        FacesContext context = FacesContext.getCurrentInstance();
+        if (context == null)
+        {
+            return null;
+        }
+        try
+        {
+            setScope(context);
+            return invoker.invoke();
+        }
+        finally
+        {
+            unsetScope(context);
+        }
+    }
+
+    private void setScope(FacesContext context)
+    {
+        context.getExternalContext().getRequestMap().put(Scope.class.getName(), _scope);
+    }
+
+    private void unsetScope(FacesContext context)
+    {
+        context.getExternalContext().getRequestMap().remove(Scope.class.getName());
+    }
+
+    interface ResolverInvoker<T>
+    {
+        T invoke();
+    }
+
+}

Propchange: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/unified/resolver/FacesCompositeELResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/el/unified/resolver/FacesCompositeELResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/DefaultFacesInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/DefaultFacesInitializer.java?view=auto&rev=511514
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/DefaultFacesInitializer.java (added)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/DefaultFacesInitializer.java Sun Feb 25 05:47:48 2007
@@ -0,0 +1,158 @@
+/*
+ * 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.webapp;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.application.ApplicationImpl;
+import org.apache.myfaces.config.FacesConfigValidator;
+import org.apache.myfaces.config.FacesConfigurator;
+import org.apache.myfaces.config.RuntimeConfig;
+import org.apache.myfaces.context.servlet.ServletExternalContextImpl;
+import org.apache.myfaces.el.ResolverForJSPInitializer;
+import org.apache.myfaces.el.unified.ELResolverBuilder;
+import org.apache.myfaces.el.unified.ResolverBuilderForJSP;
+import org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver;
+import org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.Scope;
+import org.apache.myfaces.shared_impl.util.StateUtils;
+import org.apache.myfaces.shared_impl.webapp.webxml.WebXml;
+
+import javax.faces.FactoryFinder;
+import javax.faces.context.ExternalContext;
+import javax.faces.event.PhaseListener;
+import javax.faces.lifecycle.LifecycleFactory;
+import javax.servlet.ServletContext;
+import javax.servlet.jsp.JspApplicationContext;
+import javax.servlet.jsp.JspFactory;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author Mathias Broekelmann (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class DefaultFacesInitializer implements FacesInitializer
+{
+    private static final Log log = LogFactory.getLog(DefaultFacesInitializer.class);
+
+    protected ELResolverBuilder createResolverBuilderForJSP(RuntimeConfig runtimeConfig)
+    {
+        return new ResolverBuilderForJSP(runtimeConfig);
+    }
+
+    public void initFaces(ServletContext servletContext)
+    {
+        try
+        {
+            log.trace("Initializing MyFaces");
+
+            // Load the configuration
+            ExternalContext externalContext = new ServletExternalContextImpl(servletContext, null, null);
+
+            // TODO: this Class.forName will be removed when Tomcat fixes a bug
+            // also, we should then be able to remove jasper.jar from the deployment
+            try
+            {
+                Class.forName("org.apache.jasper.compiler.JspRuntimeContext");
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+            }
+
+            JspFactory jspFactory = JspFactory.getDefaultFactory();
+            if (log.isDebugEnabled())
+            {
+                log.debug("jspfactory = " + jspFactory);
+            }
+            JspApplicationContext appCtx = jspFactory.getJspApplicationContext(servletContext);
+
+            RuntimeConfig runtimeConfig = RuntimeConfig.getCurrentInstance(externalContext);
+            runtimeConfig.setExpressionFactory(appCtx.getExpressionFactory());
+
+            ApplicationImpl.setInitializingRuntimeConfig(runtimeConfig);
+
+            // And configure everything
+            new FacesConfigurator(externalContext).configure();
+
+            validateFacesConfigIfNecessary(servletContext, externalContext);
+
+            // configure the el resolver for jsp
+            configureResolverForJSP(appCtx, runtimeConfig);
+
+            // parse web.xml
+            WebXml.init(externalContext);
+
+            if (servletContext.getInitParameter(StateUtils.INIT_SECRET) != null
+                    || servletContext.getInitParameter(StateUtils.INIT_SECRET.toLowerCase()) != null)
+                StateUtils.initSecret(servletContext);
+
+            log.info("ServletContext '" + servletContext.getRealPath("/") + "' initialized.");
+        }
+        catch (Exception ex)
+        {
+            log.error("Error initializing MyFaces: " + ex.getMessage(), ex);
+        }
+    }
+
+    /**
+     * Register a phase listener to every lifecycle. This listener will lazy fill the el resolver for jsp as soon as the
+     * first lifecycle is executed. This is necessarry to allow a faces application further setup after MyFaces has been
+     * initialized. When the first request is processed no further configuation of the el resolvers is allowed.
+     * 
+     * @param appCtx
+     * @param runtimeConfig
+     */
+    private void configureResolverForJSP(JspApplicationContext appCtx, RuntimeConfig runtimeConfig)
+    {
+        FacesCompositeELResolver facesCompositeELResolver = new FacesCompositeELResolver(Scope.JSP);
+        appCtx.addELResolver(facesCompositeELResolver);
+        PhaseListener resolverForJSPInitializer = new ResolverForJSPInitializer(
+                createResolverBuilderForJSP(runtimeConfig), facesCompositeELResolver);
+
+        LifecycleFactory factory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+        for (Iterator<String> iter = factory.getLifecycleIds(); iter.hasNext();)
+        {
+            factory.getLifecycle(iter.next()).addPhaseListener(resolverForJSPInitializer);
+        }
+    }
+
+    protected void validateFacesConfigIfNecessary(ServletContext servletContext, ExternalContext externalContext)
+    {
+        if ("true".equals(servletContext.getInitParameter(FacesConfigValidator.VALIDATE_CONTEXT_PARAM))
+                || "true".equals(servletContext.getInitParameter(FacesConfigValidator.VALIDATE_CONTEXT_PARAM
+                        .toLowerCase())))
+        {
+            List<String> list = FacesConfigValidator.validate(externalContext, servletContext.getRealPath("/"));
+
+            Iterator<String> iterator = list.iterator();
+
+            while (iterator.hasNext())
+                log.warn(iterator.next());
+
+        }
+    }
+
+    public void destroyFaces(ServletContext servletContext)
+    {
+        // TODO is it possible to make a real cleanup?
+    }
+
+}

Propchange: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/DefaultFacesInitializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/DefaultFacesInitializer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializer.java?view=auto&rev=511514
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializer.java (added)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializer.java Sun Feb 25 05:47:48 2007
@@ -0,0 +1,32 @@
+/*
+ * 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.webapp;
+
+import javax.servlet.ServletContext;
+
+/**
+ * @author Mathias Broekelmann (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public interface FacesInitializer
+{
+    void initFaces(ServletContext servletContext);
+    
+    void destroyFaces(ServletContext servletContext);
+}

Propchange: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/FacesInitializer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/MyFacesServlet.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/MyFacesServlet.java?view=diff&rev=511514&r1=511513&r2=511514
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/MyFacesServlet.java (original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/MyFacesServlet.java Sun Feb 25 05:47:48 2007
@@ -34,7 +34,23 @@
 {
     private static final Log log = LogFactory.getLog(MyFacesServlet.class);
 
-    private FacesServlet delegate = new FacesServlet();
+    private final FacesServlet delegate = new FacesServlet();
+    
+    private FacesInitializer _facesInitializer;
+    
+    protected FacesInitializer getFacesInitializer()
+    {
+        if (_facesInitializer == null)
+        {
+            _facesInitializer = new DefaultFacesInitializer();
+        }
+        return _facesInitializer;
+    }
+    
+    public void setFacesInitializer(FacesInitializer facesInitializer)
+    {
+        _facesInitializer = facesInitializer;
+    }
 
     public void destroy()
     {
@@ -56,11 +72,12 @@
     {
         //Check, if ServletContextListener already called
         ServletContext servletContext = servletConfig.getServletContext();
-        Boolean b = (Boolean)servletContext.getAttribute(org.apache.myfaces.webapp.StartupServletContextListener.FACES_INIT_DONE);
+        Boolean b = (Boolean)servletContext.getAttribute(StartupServletContextListener.FACES_INIT_DONE);
         if (b == null || b.booleanValue() == false)
         {
-            log.warn("ServletContextListener not yet called");
-            org.apache.myfaces.webapp.StartupServletContextListener.initFaces(servletConfig.getServletContext());
+            if(log.isWarnEnabled())
+                log.warn("ServletContextListener not yet called");
+            getFacesInitializer().initFaces(servletConfig.getServletContext());
         }
         delegate.init(servletConfig);
         log.info("MyFacesServlet for context '" + servletConfig.getServletContext().getRealPath("/") + "' initialized.");

Modified: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java?view=diff&rev=511514&r1=511513&r2=511514
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java (original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/webapp/StartupServletContextListener.java Sun Feb 25 05:47:48 2007
@@ -20,101 +20,79 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.myfaces.application.ApplicationImpl;
-import org.apache.myfaces.config.FacesConfigValidator;
-import org.apache.myfaces.config.FacesConfigurator;
-import org.apache.myfaces.context.servlet.ServletExternalContextImpl;
-import org.apache.myfaces.shared_impl.util.StateUtils;
-import org.apache.myfaces.shared_impl.webapp.webxml.WebXml;
 
 import javax.faces.FactoryFinder;
-import javax.faces.application.Application;
-import javax.faces.application.ApplicationFactory;
-import javax.faces.context.ExternalContext;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
-import java.util.Iterator;
-import java.util.List;
 
 /**
  * @author Manfred Geiler (latest modification by $Author$)
  * @version $Revision$ $Date$
  */
-public class StartupServletContextListener
-        implements ServletContextListener
+public class StartupServletContextListener implements ServletContextListener
 {
-    private static final Log log = LogFactory.getLog(StartupServletContextListener.class);
+    static final String FACES_INIT_DONE = StartupServletContextListener.class.getName() + ".FACES_INIT_DONE";
 
-    static final String FACES_INIT_DONE
-            = StartupServletContextListener.class.getName() + ".FACES_INIT_DONE";
+    private static final Log log = LogFactory.getLog(DefaultFacesInitializer.class);
+
+    private FacesInitializer _facesInitializer;
+    private ServletContext _servletContext;
 
     public void contextInitialized(ServletContextEvent event)
     {
-        initFaces(event.getServletContext());
+        if (_servletContext != null)
+        {
+            throw new IllegalStateException("context is already initialized");
+        }
+        _servletContext = event.getServletContext();
+        Boolean b = (Boolean) _servletContext.getAttribute(FACES_INIT_DONE);
+
+        if (b == null || b.booleanValue() == false)
+        {
+            getFacesInitializer().initFaces(_servletContext);
+            _servletContext.setAttribute(FACES_INIT_DONE, Boolean.TRUE);
+        }
+        else
+        {
+            log.info("MyFaces already initialized");
+        }
     }
 
-    public static void initFaces(ServletContext servletContext)
+    protected FacesInitializer getFacesInitializer()
     {
-        try
+        if (_facesInitializer == null)
         {
-            Boolean b = (Boolean)servletContext.getAttribute(FACES_INIT_DONE);
-
-            if (b == null || b.booleanValue() == false)
-            {
-                log.trace("Initializing MyFaces");
-
-                //Load the configuration
-                ExternalContext externalContext = new ServletExternalContextImpl(servletContext, null, null);
-
-                //And configure everything
-                new FacesConfigurator(externalContext).configure();
-
-                if ("true".equals(servletContext
-                                .getInitParameter(FacesConfigValidator.VALIDATE_CONTEXT_PARAM)) || "true".equals(servletContext
-                                .getInitParameter(FacesConfigValidator.VALIDATE_CONTEXT_PARAM.toLowerCase())))
-                {
-                    List list = FacesConfigValidator.validate(externalContext,
-                            servletContext.getRealPath("/"));
-
-                    Iterator iterator = list.iterator();
-
-                    while (iterator.hasNext())
-                        log.warn(iterator.next());
-
-                }
-
-                // parse web.xml
-                WebXml.init(externalContext);
+            _facesInitializer = new DefaultFacesInitializer();
+        }
+        return _facesInitializer;
+    }
 
-                servletContext.setAttribute(FACES_INIT_DONE, Boolean.TRUE);
-                
-                Application application = ((ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY)).getApplication();
-                if(application instanceof ApplicationImpl)
-                {
-                    ((ApplicationImpl) application).setServletContext(servletContext);
-                }
-            }
-            else
-            {
-                log.info("MyFaces already initialized");
-            }
+    /**
+     * configure the faces initializer
+     * 
+     * @param facesInitializer
+     */
+    public void setFacesInitializer(FacesInitializer facesInitializer)
+    {
+        if (_facesInitializer != null && _facesInitializer != facesInitializer && _servletContext != null)
+        {
+            _facesInitializer.destroyFaces(_servletContext);
         }
-        catch (Exception ex)
+        _facesInitializer = facesInitializer;
+        if (_servletContext != null)
         {
-            log.error("Error initializing ServletContext", ex);
-            ex.printStackTrace();
+            facesInitializer.initFaces(_servletContext);
         }
-        log.info("ServletContext '" + servletContext.getRealPath("/") + "' initialized.");
-
-        if(servletContext.getInitParameter(StateUtils.INIT_SECRET) != null
-                || servletContext.getInitParameter(StateUtils.INIT_SECRET.toLowerCase()) != null)
-            StateUtils.initSecret(servletContext);
     }
 
-
     public void contextDestroyed(ServletContextEvent e)
     {
+        if (_facesInitializer != null && _servletContext != null)
+        {
+            _facesInitializer.destroyFaces(_servletContext);
+        }
         FactoryFinder.releaseFactories();
+        _servletContext = null;
     }
 }

Added: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/NoOpElResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/NoOpElResolver.java?view=auto&rev=511514
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/NoOpElResolver.java (added)
+++ myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/NoOpElResolver.java Sun Feb 25 05:47:48 2007
@@ -0,0 +1,69 @@
+/*
+ * 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.el.unified;
+
+import javax.el.ELContext;
+import javax.el.ELResolver;
+
+import java.beans.FeatureDescriptor;
+import java.util.Iterator;
+
+/**
+ * @author Mathias Broekelmann (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class NoOpElResolver extends ELResolver
+{
+
+    @Override
+    public Class<?> getCommonPropertyType(ELContext context, Object base)
+    {
+        return null;
+    }
+
+    @Override
+    public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base)
+    {
+        return null;
+    }
+
+    @Override
+    public Class<?> getType(ELContext context, Object base, Object property)
+    {
+        return null;
+    }
+
+    @Override
+    public Object getValue(ELContext context, Object base, Object property)
+    {
+        return null;
+    }
+
+    @Override
+    public boolean isReadOnly(ELContext context, Object base, Object property)
+    {
+        return false;
+    }
+
+    @Override
+    public void setValue(ELContext context, Object base, Object property, Object value)
+    {
+    }
+
+}

Propchange: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/NoOpElResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/NoOpElResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/NoOpPropertyResolver.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/NoOpPropertyResolver.java?view=auto&rev=511514
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/NoOpPropertyResolver.java (added)
+++ myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/NoOpPropertyResolver.java Sun Feb 25 05:47:48 2007
@@ -0,0 +1,80 @@
+/*
+ * 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.el.unified;
+
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.PropertyResolver;
+
+/**
+ * @author Mathias Broekelmann (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+@SuppressWarnings("deprecation")
+public class NoOpPropertyResolver extends PropertyResolver
+{
+
+    @Override
+    public Class getType(Object base, int index) throws EvaluationException, PropertyNotFoundException
+    {
+        return null;
+    }
+
+    @Override
+    public Class getType(Object base, Object property) throws EvaluationException, PropertyNotFoundException
+    {
+        return null;
+    }
+
+    @Override
+    public Object getValue(Object base, int index) throws EvaluationException, PropertyNotFoundException
+    {
+        return null;
+    }
+
+    @Override
+    public Object getValue(Object base, Object property) throws EvaluationException, PropertyNotFoundException
+    {
+        return null;
+    }
+
+    @Override
+    public boolean isReadOnly(Object base, int index) throws EvaluationException, PropertyNotFoundException
+    {
+        return false;
+    }
+
+    @Override
+    public boolean isReadOnly(Object base, Object property) throws EvaluationException, PropertyNotFoundException
+    {
+        return false;
+    }
+
+    @Override
+    public void setValue(Object base, int index, Object value) throws EvaluationException, PropertyNotFoundException
+    {
+    }
+
+    @Override
+    public void setValue(Object base, Object property, Object value) throws EvaluationException,
+            PropertyNotFoundException
+    {
+    }
+
+}

Propchange: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/NoOpPropertyResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/NoOpPropertyResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java?view=auto&rev=511514
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java (added)
+++ myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java Sun Feb 25 05:47:48 2007
@@ -0,0 +1,202 @@
+/*
+ * 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.el.unified;
+
+import org.apache.myfaces.config.RuntimeConfig;
+
+import javax.el.CompositeELResolver;
+import javax.el.ELContext;
+import javax.el.ELResolver;
+import javax.faces.context.FacesContext;
+import javax.faces.context.MockFacesContext;
+import javax.faces.el.EvaluationException;
+import javax.faces.el.PropertyNotFoundException;
+import javax.faces.el.PropertyResolver;
+import javax.faces.el.VariableResolver;
+
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Mathias Broekelmann (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+@SuppressWarnings("deprecation")
+public class ResolverBuilderBaseTest extends TestCase
+{
+    private ResolverBuilderBase builder;
+    private ELContext expectedContext;
+    private String expectedProperty;
+    private MockFacesContext expectedFacesContext;
+    private NoOpElResolver configResolver;
+    private VariableResolver varResolver;
+    private PropertyResolver propResolver;
+    private ELResolver appResolver;
+    private ArrayList<String> calledResolvers;
+    private RuntimeConfig runtimeConfig;
+
+    protected void setUp(final Object expectedBase)
+    {
+        runtimeConfig = new RuntimeConfig();
+        builder = new ResolverBuilderBase(runtimeConfig);
+
+        expectedProperty = "xxx";
+        expectedFacesContext = new MockFacesContext();
+        expectedContext = new FacesELContext(null, expectedFacesContext);
+        expectedFacesContext.setELContext(expectedContext);
+
+        calledResolvers = new ArrayList<String>();
+        configResolver = new NoOpElResolver()
+        {
+            @Override
+            public Object getValue(ELContext context, Object base, Object property)
+            {
+                assertSame(expectedContext, context);
+                assertSame(expectedBase, base);
+                assertSame(expectedProperty, property);
+                calledResolvers.add("config");
+                return null;
+            }
+        };
+        varResolver = new VariableResolver()
+        {
+            @Override
+            public Object resolveVariable(FacesContext facesContext, String name) throws EvaluationException
+            {
+                assertSame(expectedFacesContext, facesContext);
+                assertSame(expectedProperty, name);
+                calledResolvers.add("variable");
+                return null;
+            }
+
+        };
+        propResolver = new NoOpPropertyResolver()
+        {
+            @Override
+            public Object getValue(Object base, Object property) throws EvaluationException, PropertyNotFoundException
+            {
+                assertSame(expectedBase, base);
+                assertSame(expectedProperty, property);
+                calledResolvers.add("property");
+                return super.getValue(base, property);
+            }
+        };
+        appResolver = new NoOpElResolver()
+        {
+            @Override
+            public Object getValue(ELContext context, Object base, Object property)
+            {
+                assertSame(expectedContext, context);
+                assertSame(expectedBase, base);
+                assertSame(expectedProperty, property);
+                calledResolvers.add("app");
+                return super.getValue(context, base, property);
+            }
+        };
+    }
+
+    /**
+     * Test method for
+     * {@link org.apache.myfaces.el.unified.ResolverBuilderBase#addFromRuntimeConfig(CompositeELResolver)}.
+     * 
+     * @throws
+     */
+    public void testCreateCompositeElResolverWithNoResolver()
+    {
+        setUp(null);
+        CompositeELResolver resolver = new CompositeELResolver();
+        builder.addFromRuntimeConfig(resolver);
+        Object value = resolver.getValue(expectedContext, null, expectedProperty);
+        assertNull(value);
+        assertEquals(0, calledResolvers.size());
+    }
+
+    /**
+     * Test method for
+     * {@link org.apache.myfaces.el.unified.ResolverBuilderBase#addFromRuntimeConfig(CompositeELResolver)}.
+     */
+    public void testCreateCompositeElResolverWithBase()
+    {
+        Object expectedBase = "base";
+        setUp(expectedBase);
+        runtimeConfig.addFacesConfigElResolver(configResolver);
+        runtimeConfig.setVariableResolver(varResolver);
+        runtimeConfig.setPropertyResolver(propResolver);
+        runtimeConfig.addApplicationElResolver(appResolver);
+
+        CompositeELResolver resolver = new CompositeELResolver();
+        builder.addFromRuntimeConfig(resolver);
+
+        Object value = resolver.getValue(expectedContext, expectedBase, expectedProperty);
+        assertNull(value);
+        assertTrue(expectedContext.isPropertyResolved());
+        assertEquals(2, calledResolvers.size());
+        assertEquals("config", calledResolvers.get(0));
+        assertEquals("property", calledResolvers.get(1));
+
+        runtimeConfig.setPropertyResolver(null);
+        resolver = new CompositeELResolver();
+        calledResolvers.clear();
+        builder.addFromRuntimeConfig(resolver);
+
+        value = resolver.getValue(expectedContext, expectedBase, expectedProperty);
+        assertNull(value);
+        assertFalse(expectedContext.isPropertyResolved());
+        assertEquals(2, calledResolvers.size());
+        assertEquals("config", calledResolvers.get(0));
+        assertEquals("app", calledResolvers.get(1));
+    }
+
+    /**
+     * Test method for
+     * {@link org.apache.myfaces.el.unified.ResolverBuilderBase#addFromRuntimeConfig(CompositeELResolver)}.
+     */
+    public void testCreateCompositeElResolverWithNullBase()
+    {
+        Object expectedBase = null;
+        setUp(expectedBase);
+        runtimeConfig.addFacesConfigElResolver(configResolver);
+        runtimeConfig.setVariableResolver(varResolver);
+        runtimeConfig.setPropertyResolver(propResolver);
+        runtimeConfig.addApplicationElResolver(appResolver);
+
+        CompositeELResolver resolver = new CompositeELResolver();
+        builder.addFromRuntimeConfig(resolver);
+
+        Object value = resolver.getValue(expectedContext, expectedBase, expectedProperty);
+        assertNull(value);
+        assertTrue(expectedContext.isPropertyResolved());
+        assertEquals(2, calledResolvers.size());
+        assertEquals("config", calledResolvers.get(0));
+        assertEquals("variable", calledResolvers.get(1));
+
+        runtimeConfig.setVariableResolver(null);
+        resolver = new CompositeELResolver();
+        calledResolvers.clear();
+        builder.addFromRuntimeConfig(resolver);
+
+        value = resolver.getValue(expectedContext, expectedBase, expectedProperty);
+        assertNull(value);
+        assertFalse(expectedContext.isPropertyResolved());
+        assertEquals(2, calledResolvers.size());
+        assertEquals("config", calledResolvers.get(0));
+        assertEquals("app", calledResolvers.get(1));
+    }
+}

Propchange: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/el/unified/ResolverBuilderBaseTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL