deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-426 fallback for full state-saving
Date Wed, 12 Mar 2014 07:58:33 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 6f37b12f0 -> 5815ea366


DELTASPIKE-426 fallback for full state-saving


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/5815ea36
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/5815ea36
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/5815ea36

Branch: refs/heads/master
Commit: 5815ea3661d484d025e139055f7548e3fc55daac
Parents: 6f37b12
Author: gpetracek <gpetracek@apache.org>
Authored: Wed Mar 12 08:48:20 2014 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Wed Mar 12 08:48:20 2014 +0100

----------------------------------------------------------------------
 .../jsf/api/config/JsfModuleConfig.java         | 10 ++++++
 .../AbstractContextualReferenceWrapper.java     | 36 ++++++++++++++++++--
 .../jsf/impl/injection/ConverterWrapper.java    |  8 +++--
 .../InjectionAwareApplicationWrapper.java       |  6 ++--
 .../jsf/impl/injection/ValidatorWrapper.java    |  8 +++--
 5 files changed, 59 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5815ea36/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java
b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java
index dec847d..e8077d7 100644
--- a/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java
+++ b/deltaspike/modules/jsf/api/src/main/java/org/apache/deltaspike/jsf/api/config/JsfModuleConfig.java
@@ -91,6 +91,16 @@ public class JsfModuleConfig implements DeltaSpikeConfig
     }
 
     /**
+     * If #initialStateMarked (of the component) returns false, a fallback to full state-saving
is possible.
+     * Therefore it's required to save additional meta-data even with partial state-saving.
+     * @return false to restrict additional meta-data required for a possible fallback, true
otherwise
+     */
+    public boolean isFullStateSavingFallbackEnabled()
+    {
+        return true;
+    }
+
+    /**
      * If the window-handling of JSF 2.2+ is enabled,
      * {@link org.apache.deltaspike.jsf.spi.scope.window.ClientWindowConfig.ClientWindowRenderMode#DELEGATED}
      * will be returned. In all other cases <code>null</code> gets returned as
application wide default value.

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5815ea36/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/AbstractContextualReferenceWrapper.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/AbstractContextualReferenceWrapper.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/AbstractContextualReferenceWrapper.java
index 33e1258..49c8c0d 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/AbstractContextualReferenceWrapper.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/AbstractContextualReferenceWrapper.java
@@ -18,6 +18,10 @@
  */
 package org.apache.deltaspike.jsf.impl.injection;
 
+import org.apache.deltaspike.core.api.provider.BeanProvider;
+import org.apache.deltaspike.core.util.ClassUtils;
+import org.apache.deltaspike.jsf.api.config.JsfModuleConfig;
+
 import javax.faces.FacesWrapper;
 import javax.faces.component.PartialStateHolder;
 import javax.faces.component.StateHolder;
@@ -27,10 +31,16 @@ import javax.faces.context.FacesContext;
 abstract class AbstractContextualReferenceWrapper<T> implements PartialStateHolder,
FacesWrapper<T>
 {
     private T wrapped;
+    private transient Boolean fullStateSavingFallbackEnabled;
+
+    protected AbstractContextualReferenceWrapper()
+    {
+    }
 
-    protected AbstractContextualReferenceWrapper(T wrapped)
+    protected AbstractContextualReferenceWrapper(T wrapped, boolean fullStateSavingFallbackEnabled)
     {
         this.wrapped = wrapped;
+        this.fullStateSavingFallbackEnabled = fullStateSavingFallbackEnabled;
     }
 
     @Override
@@ -62,7 +72,19 @@ abstract class AbstractContextualReferenceWrapper<T> implements PartialStateHold
     {
         if (this.wrapped instanceof StateHolder)
         {
-            return ((StateHolder)wrapped).saveState(context);
+            Object[] result = new Object[2];
+
+            if (this.fullStateSavingFallbackEnabled == null)
+            {
+                this.fullStateSavingFallbackEnabled =
+                    BeanProvider.getContextualReference(JsfModuleConfig.class).isFullStateSavingFallbackEnabled();
+            }
+            if (this.fullStateSavingFallbackEnabled)
+            {
+                result[0] = this.getWrapped().getClass().getName();
+            }
+            result[1] = ((StateHolder)wrapped).saveState(context);
+            return result;
         }
 
         return null;
@@ -71,9 +93,17 @@ abstract class AbstractContextualReferenceWrapper<T> implements PartialStateHold
     @Override
     public void restoreState(FacesContext context, Object state)
     {
+        Object[] wrappedState = (Object[]) state;
+
+        if (this.wrapped == null) //fallback for full state-saving
+        {
+            //TODO check for @FacesConverter/@FacesValidator
+            //-> delegate to javax.faces.application.Application (+ unwrap it - since
it will be wrapped again)
+            this.wrapped = (T)ClassUtils.tryToInstantiateClassForName((String)wrappedState[0]);
+        }
         if (this.wrapped instanceof StateHolder)
         {
-            ((StateHolder)this.wrapped).restoreState(context, state);
+            ((StateHolder) this.wrapped).restoreState(context, wrappedState[1]);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5815ea36/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ConverterWrapper.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ConverterWrapper.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ConverterWrapper.java
index 0a362df..187f7a4 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ConverterWrapper.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ConverterWrapper.java
@@ -25,9 +25,13 @@ import javax.faces.convert.ConverterException;
 
 public class ConverterWrapper extends AbstractContextualReferenceWrapper<Converter>
implements Converter
 {
-    public ConverterWrapper(Converter wrapped)
+    public ConverterWrapper()
     {
-        super(wrapped);
+    }
+
+    public ConverterWrapper(Converter wrapped, boolean fullStateSavingFallbackEnabled)
+    {
+        super(wrapped, fullStateSavingFallbackEnabled);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5815ea36/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/InjectionAwareApplicationWrapper.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/InjectionAwareApplicationWrapper.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/InjectionAwareApplicationWrapper.java
index 2a76447..b18b36a 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/InjectionAwareApplicationWrapper.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/InjectionAwareApplicationWrapper.java
@@ -36,6 +36,7 @@ public class InjectionAwareApplicationWrapper extends ApplicationWrapper
     private final boolean containerManagedConvertersEnabled;
     private final boolean containerManagedValidatorsEnabled;
     private final boolean preDestroyViewMapEventFilterMode;
+    private final boolean fullStateSavingFallbackEnabled;
 
     public InjectionAwareApplicationWrapper(
         Application wrapped, JsfModuleConfig jsfModuleConfig, boolean preDestroyViewMapEventFilterMode)
@@ -43,6 +44,7 @@ public class InjectionAwareApplicationWrapper extends ApplicationWrapper
         this.wrapped = wrapped;
         this.containerManagedConvertersEnabled = jsfModuleConfig.isContainerManagedConvertersEnabled();
         this.containerManagedValidatorsEnabled = jsfModuleConfig.isContainerManagedValidatorsEnabled();
+        this.fullStateSavingFallbackEnabled = jsfModuleConfig.isFullStateSavingFallbackEnabled();
         this.preDestroyViewMapEventFilterMode = preDestroyViewMapEventFilterMode;
     }
 
@@ -77,7 +79,7 @@ public class InjectionAwareApplicationWrapper extends ApplicationWrapper
         }
         else
         {
-            return new ConverterWrapper(result);
+            return new ConverterWrapper(result, this.fullStateSavingFallbackEnabled);
         }
     }
 
@@ -106,7 +108,7 @@ public class InjectionAwareApplicationWrapper extends ApplicationWrapper
         }
         else
         {
-            return new ValidatorWrapper(result);
+            return new ValidatorWrapper(result, this.fullStateSavingFallbackEnabled);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/5815ea36/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ValidatorWrapper.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ValidatorWrapper.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ValidatorWrapper.java
index f306f8e..96bee8e 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ValidatorWrapper.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/injection/ValidatorWrapper.java
@@ -25,9 +25,13 @@ import javax.faces.validator.ValidatorException;
 
 public class ValidatorWrapper extends AbstractContextualReferenceWrapper<Validator>
implements Validator
 {
-    public ValidatorWrapper(Validator wrapped)
+    public ValidatorWrapper()
     {
-        super(wrapped);
+    }
+
+    public ValidatorWrapper(Validator wrapped, boolean fullStateSavingFallbackEnabled)
+    {
+        super(wrapped, fullStateSavingFallbackEnabled);
     }
 
     @Override


Mime
View raw message