You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2019/06/05 05:21:09 UTC

[myfaces] branch master updated: remove flag and moved to auto-detect passivation capable

This is an automated email from the ASF dual-hosted git repository.

tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git


The following commit(s) were added to refs/heads/master by this push:
     new 1297baf  remove flag and moved to auto-detect passivation capable
1297baf is described below

commit 1297baf736f194cc5c22ecde84f562bb91410f15
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Wed Jun 5 07:21:00 2019 +0200

    remove flag and moved to auto-detect passivation capable
---
 .../org/apache/myfaces/cdi/util/AbstractContext.java | 12 ++++++++++--
 .../apache/myfaces/cdi/view/ViewScopeBeanHolder.java |  5 +----
 .../myfaces/cdi/view/ViewScopeContextImpl.java       | 15 +++++++++++++--
 .../myfaces/cdi/view/ViewScopeContextualStorage.java | 10 ++++------
 .../org/apache/myfaces/config/MyfacesConfig.java     | 20 +-------------------
 5 files changed, 29 insertions(+), 33 deletions(-)

diff --git a/impl/src/main/java/org/apache/myfaces/cdi/util/AbstractContext.java b/impl/src/main/java/org/apache/myfaces/cdi/util/AbstractContext.java
index de47a13..f1bcae4 100644
--- a/impl/src/main/java/org/apache/myfaces/cdi/util/AbstractContext.java
+++ b/impl/src/main/java/org/apache/myfaces/cdi/util/AbstractContext.java
@@ -39,11 +39,19 @@ public abstract class AbstractContext implements Context
     /**
      * Whether the Context is for a passivating scope.
      */
-    private final boolean passivatingScope;
+    private boolean passivatingScope;
 
     protected AbstractContext(BeanManager beanManager)
     {
-        passivatingScope = beanManager.isPassivatingScope(getScope());
+        try
+        {
+            passivatingScope = beanManager.isPassivatingScope(getScope());
+        }
+        catch (UnsupportedOperationException e)
+        {
+            // Quarkus throws a UnsupportedOperationException instead return false currently
+            passivatingScope = false;
+        }
     }
 
     /**
diff --git a/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java b/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java
index 1bf5dc8..1025433 100644
--- a/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java
+++ b/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeBeanHolder.java
@@ -32,7 +32,6 @@ import javax.faces.context.ExternalContext;
 import javax.faces.context.FacesContext;
 import javax.inject.Inject;
 import javax.servlet.ServletContext;
-import org.apache.myfaces.config.MyfacesConfig;
 import org.apache.myfaces.context.servlet.StartupFacesContextImpl;
 import org.apache.myfaces.context.servlet.StartupServletExternalContextImpl;
 import org.apache.myfaces.context.ExceptionHandlerImpl;
@@ -91,9 +90,7 @@ public class ViewScopeBeanHolder implements Serializable
                 contextualStorage = storageMap.get(viewScopeId);
                 if (contextualStorage == null)
                 {
-                    MyfacesConfig myfacesConfig = MyfacesConfig.getCurrentInstance();
-                    contextualStorage = new ViewScopeContextualStorage(beanManager,
-                            myfacesConfig.isCdiPassivationSupported());
+                    contextualStorage = new ViewScopeContextualStorage(beanManager);
                     storageMap.put(viewScopeId, contextualStorage);
                 }
             }
diff --git a/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextImpl.java b/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextImpl.java
index 2fb43d3..f3c12fa 100644
--- a/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextImpl.java
@@ -33,7 +33,6 @@ import javax.faces.view.ViewScoped;
 
 import org.apache.myfaces.cdi.util.BeanProvider;
 import org.apache.myfaces.cdi.util.ContextualInstanceInfo;
-import org.apache.myfaces.config.MyfacesConfig;
 import org.apache.myfaces.view.ViewScopeProxyMap;
 
 /**
@@ -49,10 +48,22 @@ public class ViewScopeContextImpl implements Context
      * needed for serialisation and passivationId
      */
     private BeanManager beanManager;
+    
+    private boolean passivatingScope;
 
     public ViewScopeContextImpl(BeanManager beanManager)
     {
         this.beanManager = beanManager;
+
+        try
+        {
+            passivatingScope = beanManager.isPassivatingScope(getScope());
+        }
+        catch (UnsupportedOperationException e)
+        {
+            // Quarkus throws a UnsupportedOperationException instead return false currently
+            passivatingScope = false;
+        }
     }
 
     // SPI
@@ -165,7 +176,7 @@ public class ViewScopeContextImpl implements Context
     {
         checkActive();
 
-        if (!(bean instanceof PassivationCapable) && MyfacesConfig.getCurrentInstance().isCdiPassivationSupported())
+        if (passivatingScope && !(bean instanceof PassivationCapable))
         {
             throw new IllegalStateException(bean.toString() +
                     " doesn't implement " + PassivationCapable.class.getName());
diff --git a/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextualStorage.java b/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextualStorage.java
index 894e4da..384d849 100644
--- a/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextualStorage.java
+++ b/impl/src/main/java/org/apache/myfaces/cdi/view/ViewScopeContextualStorage.java
@@ -47,17 +47,15 @@ public class ViewScopeContextualStorage implements Serializable
     private final Map<String, Object> nameBeanKeyMap;
     
     private transient BeanManager beanManager;
-    private final boolean passivationCapable;
-    
+
     private transient volatile boolean deactivated;
 
-    public ViewScopeContextualStorage(BeanManager beanManager, boolean passivationCapable)
+    public ViewScopeContextualStorage(BeanManager beanManager)
     {
         this.beanManager = beanManager;
         this.contextualInstances = new HashMap<>();
         this.nameBeanKeyMap = new HashMap<>();
         this.deactivated = false;
-        this.passivationCapable = passivationCapable;
     }
 
     /**
@@ -110,7 +108,7 @@ public class ViewScopeContextualStorage implements Serializable
      */
     public <T> Object getBeanKey(Contextual<T> bean)
     {
-        if (passivationCapable)
+        if (bean instanceof PassivationCapable)
         {
             return ((PassivationCapable) bean).getId();
         }
@@ -123,7 +121,7 @@ public class ViewScopeContextualStorage implements Serializable
      */
     public Contextual<?> getBean(FacesContext context, Object beanKey)
     {
-        if (passivationCapable)
+        if (beanKey instanceof String) //if beanKey is a string it is a passivation capable bean id
         {
             if (beanManager == null)
             {
diff --git a/impl/src/main/java/org/apache/myfaces/config/MyfacesConfig.java b/impl/src/main/java/org/apache/myfaces/config/MyfacesConfig.java
index fe9fcae..99d54ad 100755
--- a/impl/src/main/java/org/apache/myfaces/config/MyfacesConfig.java
+++ b/impl/src/main/java/org/apache/myfaces/config/MyfacesConfig.java
@@ -768,16 +768,7 @@ public class MyfacesConfig
     public static final String WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE
             = "org.apache.myfaces.WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE";
     public static final boolean WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE_DEFAULT = true;
-    
-    /**
-     * Deactivates the passivation capables of MyFaces CDI scopes.
-     * This is e.g. required on Quarkus.
-     */
-    @JSFWebConfigParam(since="3.0.0" , defaultValue="true", expectedValues="true, false")
-    public static final String CDI_PASSIVATION_SUPPORTED
-            = "org.apache.myfaces.CDI_PASSIVATION_SUPPORTED";
-    public static final boolean CDI_PASSIVATION_SUPPORTED_DEFAULT = true;
-    
+
     // we need it, applicationImpl not ready probably
     private ProjectStage projectStage = ProjectStage.Production;
     private boolean strictJsf2AllowSlashLibraryName;
@@ -855,7 +846,6 @@ public class MyfacesConfig
     private String faceletsViewSuffix = ViewHandler.DEFAULT_FACELETS_SUFFIX;
     private ELExpressionCacheMode elExpressionCacheMode;
     private boolean wrapTagExceptionsAsContextAware = WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE_DEFAULT;
-    private boolean cdiPassivationSupported = CDI_PASSIVATION_SUPPORTED_DEFAULT;
     
     
     private static final boolean MYFACES_IMPL_AVAILABLE;
@@ -1251,9 +1241,6 @@ public class MyfacesConfig
         cfg.wrapTagExceptionsAsContextAware = getBoolean(extCtx, WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE,
                 WRAP_TAG_EXCEPTIONS_AS_CONTEXT_AWARE_DEFAULT);
         
-        cfg.cdiPassivationSupported = getBoolean(extCtx, CDI_PASSIVATION_SUPPORTED,
-                CDI_PASSIVATION_SUPPORTED_DEFAULT);
-        
         return cfg;
     }
 
@@ -1703,11 +1690,6 @@ public class MyfacesConfig
     {
         return wrapTagExceptionsAsContextAware;
     }
-
-    public boolean isCdiPassivationSupported()
-    {
-        return cdiPassivationSupported;
-    }
     
 }