myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r1795576 - in /myfaces/core/branches/2.3.x/impl/src/main: java/org/apache/myfaces/application/ java/org/apache/myfaces/cdi/config/ java/org/apache/myfaces/el/ java/org/apache/myfaces/el/unified/ resources/META-INF/services/
Date Fri, 19 May 2017 00:32:41 GMT
Author: lu4242
Date: Fri May 19 00:32:41 2017
New Revision: 1795576

URL: http://svn.apache.org/viewvc?rev=1795576&view=rev
Log:
MYFACES-4097 Implement CDI changes for @FacesConfig

Added:
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/cdi/config/
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/cdi/config/FacesConfigBeanHolder.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/cdi/config/FacesConfigExtension.java
Modified:
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/ResolverForJSPInitializer.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ELResolverBuilder.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java
    myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java
    myfaces/core/branches/2.3.x/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java?rev=1795576&r1=1795575&r2=1795576&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
(original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
Fri May 19 00:32:41 2017
@@ -411,8 +411,9 @@ public class ApplicationImpl extends App
 
     private ELResolver createFacesResolver()
     {
+        FacesContext facesContext = getFaceContext();
         boolean supportJSPAndFacesEL = MyfacesConfig.getCurrentInstance(
-                                getFaceContext().getExternalContext()).isSupportJSPAndFacesEL();
+                                facesContext.getExternalContext()).isSupportJSPAndFacesEL();
         CompositeELResolver resolver;
         if (supportJSPAndFacesEL)
         {
@@ -422,7 +423,7 @@ public class ApplicationImpl extends App
         {
             resolver = new CompositeELResolver();
         }
-        getResolverBuilderForFaces().build(resolver);
+        getResolverBuilderForFaces().build(facesContext, resolver);
         return resolver;
     }
 

Added: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/cdi/config/FacesConfigBeanHolder.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/cdi/config/FacesConfigBeanHolder.java?rev=1795576&view=auto
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/cdi/config/FacesConfigBeanHolder.java
(added)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/cdi/config/FacesConfigBeanHolder.java
Fri May 19 00:32:41 2017
@@ -0,0 +1,50 @@
+/*
+ * 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.cdi.config;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.faces.annotation.FacesConfig;
+
+/**
+ *
+ */
+@ApplicationScoped
+public class FacesConfigBeanHolder
+{
+    
+    private FacesConfig.Version facesConfigVersion = null;
+
+    /**
+     * @return the facesConfigVersion
+     */
+    public FacesConfig.Version getFacesConfigVersion()
+    {
+        return facesConfigVersion;
+    }
+
+    /**
+     * @param facesConfigVersion the facesConfigVersion to set
+     */
+    public void setFacesConfigVersion(FacesConfig.Version facesConfigVersion)
+    {
+        this.facesConfigVersion = facesConfigVersion;
+    }
+    
+}

Added: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/cdi/config/FacesConfigExtension.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/cdi/config/FacesConfigExtension.java?rev=1795576&view=auto
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/cdi/config/FacesConfigExtension.java
(added)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/cdi/config/FacesConfigExtension.java
Fri May 19 00:32:41 2017
@@ -0,0 +1,74 @@
+/*
+ * 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.cdi.config;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterDeploymentValidation;
+import javax.enterprise.inject.spi.Annotated;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessManagedBean;
+import javax.faces.annotation.FacesConfig;
+import org.apache.myfaces.cdi.util.CDIUtils;
+
+/**
+ *
+ */
+public class FacesConfigExtension implements Extension
+{
+    private FacesConfig.Version facesConfigVersion;
+    
+    void beforeBeanDiscovery(
+        @Observes final BeforeBeanDiscovery event, BeanManager beanManager)
+    {
+        AnnotatedType beanHolder = beanManager.createAnnotatedType(FacesConfigBeanHolder.class);
+        event.addAnnotatedType(beanHolder);
+    }
+    
+    public <T> void collect(@Observes ProcessManagedBean<T> event)
+    {
+        if (event.getAnnotatedBeanClass().isAnnotationPresent(FacesConfig.class))
+        {
+            Annotated annotated = event.getAnnotatedBeanClass();
+            
+            FacesConfig config = (FacesConfig) annotated.getAnnotation(FacesConfig.class);
+
+            if (facesConfigVersion != null)
+            {
+                facesConfigVersion = facesConfigVersion.ordinal() < config.version().ordinal()
? 
+                        config.version() : facesConfigVersion;
+            }
+            else
+            {
+                facesConfigVersion = config.version();
+            }
+        }
+    }
+    
+    public void afterDeploymentValidation(@Observes AfterDeploymentValidation adv, BeanManager
beanManager)
+    {
+        FacesConfigBeanHolder holder = CDIUtils.lookup(beanManager, FacesConfigBeanHolder.class);
+        
+        holder.setFacesConfigVersion(facesConfigVersion);
+    }
+
+}

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/ResolverForJSPInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/ResolverForJSPInitializer.java?rev=1795576&r1=1795575&r2=1795576&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/ResolverForJSPInitializer.java
(original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/ResolverForJSPInitializer.java
Fri May 19 00:32:41 2017
@@ -21,6 +21,7 @@ package org.apache.myfaces.el;
 import java.util.Iterator;
 
 import javax.faces.FactoryFinder;
+import javax.faces.context.FacesContext;
 import javax.faces.event.PhaseEvent;
 import javax.faces.event.PhaseId;
 import javax.faces.event.PhaseListener;
@@ -55,7 +56,9 @@ public final class ResolverForJSPInitial
             {
                 if (!initialized)
                 {
-                    _resolverBuilder.build(_resolverForJSP);
+                    FacesContext facesContext = event.getFacesContext();
+                    facesContext = (facesContext == null) ? FacesContext.getCurrentInstance()
: facesContext;
+                    _resolverBuilder.build(facesContext, _resolverForJSP);
 
                     LifecycleFactory factory = (LifecycleFactory) 
                             FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ELResolverBuilder.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ELResolverBuilder.java?rev=1795576&r1=1795575&r2=1795576&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ELResolverBuilder.java
(original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ELResolverBuilder.java
Fri May 19 00:32:41 2017
@@ -19,6 +19,7 @@
 package org.apache.myfaces.el.unified;
 
 import javax.el.CompositeELResolver;
+import javax.faces.context.FacesContext;
 
 /**
  * The ELResolverBuilder is responsible to build the el resolver which is used by the application
through
@@ -32,4 +33,6 @@ import javax.el.CompositeELResolver;
 public interface ELResolverBuilder
 {
     void build(CompositeELResolver elResolver);
+    
+    void build(FacesContext facesContext, CompositeELResolver elResolver);
 }

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java?rev=1795576&r1=1795575&r2=1795576&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java
(original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderBase.java
Fri May 19 00:32:41 2017
@@ -24,6 +24,8 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.el.ELResolver;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.faces.annotation.FacesConfig;
 import javax.faces.context.FacesContext;
 import javax.faces.el.PropertyResolver;
 import javax.faces.el.VariableResolver;
@@ -31,6 +33,8 @@ import javax.faces.el.VariableResolver;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.Predicate;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFWebConfigParam;
+import org.apache.myfaces.cdi.config.FacesConfigBeanHolder;
+import org.apache.myfaces.cdi.util.CDIUtils;
 import org.apache.myfaces.config.RuntimeConfig;
 import org.apache.myfaces.el.convert.PropertyResolverToELResolver;
 import org.apache.myfaces.el.convert.VariableResolverToELResolver;
@@ -220,4 +224,30 @@ public class ResolverBuilderBase
     {
         return _config;
     }
+    
+    protected boolean isReplaceImplicitObjectResolverWithCDIResolver(FacesContext facesContext)
+    {
+        BeanManager beanManager = CDIUtils.getBeanManager(facesContext.getExternalContext());
+        if (beanManager != null)
+        {
+            FacesConfigBeanHolder holder = CDIUtils.lookup(beanManager, FacesConfigBeanHolder.class);
+            if (holder != null)
+            {
+                FacesConfig.Version version = holder.getFacesConfigVersion();
+                if (version == null)
+                {
+                    return false;
+                }
+                else if (FacesConfig.Version.JSF_2_2.ordinal() < version.ordinal())
+                {
+                    return true;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+        }
+        return false;
+    }
 }

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java?rev=1795576&r1=1795575&r2=1795576&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java
(original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForFaces.java
Fri May 19 00:32:41 2017
@@ -31,7 +31,9 @@ import javax.el.ExpressionFactory;
 import javax.el.ListELResolver;
 import javax.el.MapELResolver;
 import javax.el.ResourceBundleELResolver;
+import javax.enterprise.inject.spi.BeanManager;
 import javax.faces.context.FacesContext;
+import org.apache.myfaces.cdi.util.CDIUtils;
 
 import org.apache.myfaces.config.RuntimeConfig;
 import org.apache.myfaces.el.FlashELResolver;
@@ -90,10 +92,27 @@ public class ResolverBuilderForFaces ext
 
     public void build(CompositeELResolver compositeElResolver)
     {
+        build(FacesContext.getCurrentInstance(), compositeElResolver);
+    }
+    
+    public void build(FacesContext facesContext, CompositeELResolver compositeElResolver)
+    {
         // add the ELResolvers to a List first to be able to sort them
         List<ELResolver> list = new ArrayList<ELResolver>();
         
-        list.add(ImplicitObjectResolver.makeResolverForFaces());
+        if (isReplaceImplicitObjectResolverWithCDIResolver(facesContext))
+        {
+            //Add CDI ELResolver instead.
+            //Add CDI ELResolver instead.
+            BeanManager beanManager = CDIUtils.getBeanManager(
+                    FacesContext.getCurrentInstance().getExternalContext());
+            list.add(beanManager.getELResolver());
+        }
+        else
+        {
+            list.add(ImplicitObjectResolver.makeResolverForFaces());
+        }
+            
         list.add(new CompositeComponentELResolver());
 
         addFromRuntimeConfig(list);
@@ -164,5 +183,5 @@ public class ResolverBuilderForFaces ext
         // case, because it always sets propertyResolved to true (per the spec)
         compositeElResolver.add(new ScopedAttributeResolver());
     }
-
+    
 }

Modified: myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java?rev=1795576&r1=1795575&r2=1795576&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java
(original)
+++ myfaces/core/branches/2.3.x/impl/src/main/java/org/apache/myfaces/el/unified/ResolverBuilderForJSP.java
Fri May 19 00:32:41 2017
@@ -23,6 +23,9 @@ import java.util.List;
 
 import javax.el.CompositeELResolver;
 import javax.el.ELResolver;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.faces.context.FacesContext;
+import org.apache.myfaces.cdi.util.CDIUtils;
 
 import org.apache.myfaces.config.RuntimeConfig;
 import org.apache.myfaces.el.FlashELResolver;
@@ -44,13 +47,29 @@ public class ResolverBuilderForJSP exten
     {
         super(config);
     }
-
+    
     public void build(CompositeELResolver compositeElResolver)
     {
+        build(FacesContext.getCurrentInstance(), compositeElResolver);
+    }
+
+    public void build(FacesContext facesContext, CompositeELResolver compositeElResolver)
+    {
         // add the ELResolvers to a List first to be able to sort them
         List<ELResolver> list = new ArrayList<ELResolver>();
         
-        list.add(ImplicitObjectResolver.makeResolverForJSP());
+        if (isReplaceImplicitObjectResolverWithCDIResolver(facesContext))
+        {
+            //Add CDI ELResolver instead.
+            BeanManager beanManager = CDIUtils.getBeanManager(
+                    FacesContext.getCurrentInstance().getExternalContext());
+            list.add(beanManager.getELResolver());
+        }
+        else
+        {        
+            list.add(ImplicitObjectResolver.makeResolverForJSP());
+        }
+        
         //Flash object is instanceof Map, so it is necessary to resolve
         //before MapELResolver. Better to put this one before
         list.add(new FlashELResolver());        

Modified: myfaces/core/branches/2.3.x/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
URL: http://svn.apache.org/viewvc/myfaces/core/branches/2.3.x/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension?rev=1795576&r1=1795575&r2=1795576&view=diff
==============================================================================
--- myfaces/core/branches/2.3.x/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
(original)
+++ myfaces/core/branches/2.3.x/impl/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
Fri May 19 00:32:41 2017
@@ -11,4 +11,5 @@ org.apache.myfaces.cdi.bean.ManagedPrope
 org.apache.myfaces.cdi.converter.FacesConverterExtension
 org.apache.myfaces.cdi.validator.FacesValidatorExtension
 org.apache.myfaces.cdi.behavior.FacesBehaviorExtension
-org.apache.myfaces.cdi.model.FacesDataModelExtension
\ No newline at end of file
+org.apache.myfaces.cdi.model.FacesDataModelExtension
+org.apache.myfaces.cdi.config.FacesConfigExtension
\ No newline at end of file



Mime
View raw message