deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject git commit: DELTASPIKE-626 unified handling of navigation-handlers
Date Thu, 05 Jun 2014 12:40:40 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 245afa94d -> aa23129f7


DELTASPIKE-626 unified handling of navigation-handlers


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

Branch: refs/heads/master
Commit: aa23129f7598b6a563f41f9636278dbb47744f41
Parents: 245afa9
Author: gpetracek <gpetracek@apache.org>
Authored: Thu Jun 5 14:39:00 2014 +0200
Committer: gpetracek <gpetracek@apache.org>
Committed: Thu Jun 5 14:39:17 2014 +0200

----------------------------------------------------------------------
 .../request/DeltaSpikeFacesContextWrapper.java  | 11 ++-
 .../NavigationHandlerAwareApplication.java      | 87 +++++++++++++++-----
 ...avigationHandlerAwareApplicationFactory.java | 57 -------------
 .../main/resources/META-INF/faces-config.xml    |  1 -
 4 files changed, 75 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/aa23129f/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java
index c7bd560..2e5d582 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/listener/request/DeltaSpikeFacesContextWrapper.java
@@ -41,6 +41,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
 import org.apache.deltaspike.core.util.metadata.AnnotationInstanceProvider;
 import org.apache.deltaspike.jsf.impl.exception.control.BridgeExceptionHandlerWrapper;
 
+import org.apache.deltaspike.jsf.impl.navigation.NavigationHandlerAwareApplication;
 import org.apache.deltaspike.jsf.impl.security.SecurityAwareViewHandler;
 import org.apache.deltaspike.jsf.spi.scope.window.ClientWindow;
 
@@ -62,6 +63,7 @@ class DeltaSpikeFacesContextWrapper extends FacesContextWrapper
     private JsfModuleConfig jsfModuleConfig;
 
     private volatile Boolean initialized;
+    private volatile Boolean isNavigationAwareApplicationWrapperActivated;
 
     private boolean preDestroyViewMapEventFilterMode;
 
@@ -162,6 +164,8 @@ class DeltaSpikeFacesContextWrapper extends FacesContextWrapper
             this.bridgeExceptionQualifier = AnnotationInstanceProvider.of(jsfModuleConfig.getExceptionQualifier());
 
             this.preDestroyViewMapEventFilterMode = ClassDeactivationUtils.isActivated(SecurityAwareViewHandler.class);
+            this.isNavigationAwareApplicationWrapperActivated =
+                ClassDeactivationUtils.isActivated(NavigationHandlerAwareApplication.class);
             this.initialized = true;
         }
     }
@@ -204,8 +208,13 @@ class DeltaSpikeFacesContextWrapper extends FacesContextWrapper
     {
         lazyInit();
 
+        Application wrappedApplication = this.wrappedFacesContext.getApplication();
+        if (this.isNavigationAwareApplicationWrapperActivated)
+        {
+            wrappedApplication = new NavigationHandlerAwareApplication(wrappedApplication);
+        }
         return new InjectionAwareApplicationWrapper(
-            this.wrappedFacesContext.getApplication(), this.jsfModuleConfig, this.preDestroyViewMapEventFilterMode);
+            wrappedApplication, this.jsfModuleConfig, this.preDestroyViewMapEventFilterMode);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/aa23129f/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplication.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplication.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplication.java
index b2ce07c..54783a8 100644
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplication.java
+++ b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplication.java
@@ -18,6 +18,7 @@
  */
 package org.apache.deltaspike.jsf.impl.navigation;
 
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
 import org.apache.deltaspike.core.util.ClassUtils;
 import org.apache.deltaspike.core.util.ExceptionUtils;
 
@@ -27,8 +28,10 @@ import javax.faces.application.ConfigurableNavigationHandler;
 import javax.faces.application.NavigationHandler;
 import java.lang.reflect.Constructor;
 
-public class NavigationHandlerAwareApplication extends ApplicationWrapper
+public class NavigationHandlerAwareApplication extends ApplicationWrapper implements Deactivatable
 {
+    private static Boolean manualNavigationHandlerWrapperMode;
+    private static Class navigationHandlerWrapperClass;
     private final Application wrapped;
 
     public NavigationHandlerAwareApplication(Application wrapped)
@@ -37,37 +40,77 @@ public class NavigationHandlerAwareApplication extends ApplicationWrapper
     }
 
     @Override
-    public void setNavigationHandler(NavigationHandler handler)
+    public NavigationHandler getNavigationHandler()
     {
+        return wrapNavigationHandler(this.wrapped.getNavigationHandler());
+    }
+
+    private NavigationHandler wrapNavigationHandler(NavigationHandler handler)
+    {
+        NavigationHandler result = null;
+
+        if (manualNavigationHandlerWrapperMode == null)
+        {
+            lazyInit();
+        }
+
+        //jsf 2.2+
+        if (!manualNavigationHandlerWrapperMode)
+        {
+            result = wrapNavigationHandlerWithNewWrapper(handler);
+        }
+        if (result != null)
+        {
+            return result;
+        }
+
+        //jsf 2.0 and 2.1
+        return new DeltaSpikeNavigationHandler(handler);
+    }
+
+    private static synchronized void lazyInit()
+    {
+        if (manualNavigationHandlerWrapperMode != null)
+        {
+            return;
+        }
+
         Class wrapperClass = ClassUtils
             .tryToLoadClassForName("javax.faces.application.ConfigurableNavigationHandlerWrapper");
 
-        //jsf 2.2+
         if (wrapperClass != null)
         {
-            if (ConfigurableNavigationHandler.class.isAssignableFrom(handler.getClass()))
+            navigationHandlerWrapperClass =
+                ClassUtils.tryToLoadClassForName(
+                    "org.apache.deltaspike.jsf.impl.navigation.DeltaSpikeNavigationHandlerWrapper");
+            manualNavigationHandlerWrapperMode = false;
+        }
+        else
+        {
+            manualNavigationHandlerWrapperMode = true;
+        }
+    }
+
+    private NavigationHandler wrapNavigationHandlerWithNewWrapper(NavigationHandler handler)
+    {
+        if (ConfigurableNavigationHandler.class.isAssignableFrom(handler.getClass()))
+        {
+            try
             {
-                try
-                {
-                    Class deltaSpikeWrapperClass = ClassUtils.tryToLoadClassForName(
-                        "org.apache.deltaspike.jsf.impl.navigation.DeltaSpikeNavigationHandlerWrapper");
-                    Constructor deltaSpikeNavigationHandlerWrapperConstructor =
-                        deltaSpikeWrapperClass.getConstructor(ConfigurableNavigationHandler.class);
-
-                    NavigationHandler navigationHandlerWrapper =
-                            (NavigationHandler)deltaSpikeNavigationHandlerWrapperConstructor.newInstance(handler);
-                    this.wrapped.setNavigationHandler(navigationHandlerWrapper);
-                    return;
-                }
-                catch (Exception e)
-                {
-                    throw ExceptionUtils.throwAsRuntimeException(e);
-                }
+                Constructor deltaSpikeNavigationHandlerWrapperConstructor =
+                    this.navigationHandlerWrapperClass.getConstructor(ConfigurableNavigationHandler.class);
+
+                NavigationHandler navigationHandlerWrapper =
+                    (NavigationHandler)deltaSpikeNavigationHandlerWrapperConstructor.newInstance(handler);
+                return  navigationHandlerWrapper;
+            }
+            catch (Exception e)
+            {
+                throw ExceptionUtils.throwAsRuntimeException(e);
             }
         }
 
-        //jsf 2.0 and 2.1
-        this.wrapped.setNavigationHandler(new DeltaSpikeNavigationHandler(handler));
+        return null;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/aa23129f/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplicationFactory.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplicationFactory.java
b/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplicationFactory.java
deleted file mode 100644
index 59491f6..0000000
--- a/deltaspike/modules/jsf/impl/src/main/java/org/apache/deltaspike/jsf/impl/navigation/NavigationHandlerAwareApplicationFactory.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.deltaspike.jsf.impl.navigation;
-
-import org.apache.deltaspike.core.spi.activation.Deactivatable;
-import org.apache.deltaspike.core.util.ClassDeactivationUtils;
-
-import javax.faces.application.Application;
-import javax.faces.application.ApplicationFactory;
-
-public class NavigationHandlerAwareApplicationFactory extends ApplicationFactory implements
Deactivatable
-{
-    private final ApplicationFactory wrapped;
-
-    public NavigationHandlerAwareApplicationFactory(ApplicationFactory wrapped)
-    {
-        this.wrapped = wrapped;
-    }
-
-    @Override
-    public Application getApplication()
-    {
-        if (ClassDeactivationUtils.isActivated(getClass()))
-        {
-            return new NavigationHandlerAwareApplication(wrapped.getApplication());
-        }
-
-        return wrapped.getApplication();
-    }
-
-    @Override
-    public void setApplication(Application application)
-    {
-        wrapped.setApplication(application);
-    }
-
-    public ApplicationFactory getWrapped()
-    {
-        return wrapped;
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/aa23129f/deltaspike/modules/jsf/impl/src/main/resources/META-INF/faces-config.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jsf/impl/src/main/resources/META-INF/faces-config.xml b/deltaspike/modules/jsf/impl/src/main/resources/META-INF/faces-config.xml
index c4345dc..2767811 100644
--- a/deltaspike/modules/jsf/impl/src/main/resources/META-INF/faces-config.xml
+++ b/deltaspike/modules/jsf/impl/src/main/resources/META-INF/faces-config.xml
@@ -50,7 +50,6 @@
     <factory>
         <lifecycle-factory>org.apache.deltaspike.jsf.impl.listener.request.DeltaSpikeLifecycleFactoryWrapper</lifecycle-factory>
         <faces-context-factory>org.apache.deltaspike.jsf.impl.listener.request.DeltaSpikeFacesContextFactory</faces-context-factory>
-        <application-factory>org.apache.deltaspike.jsf.impl.navigation.NavigationHandlerAwareApplicationFactory</application-factory>
     </factory>
 
 </faces-config>


Mime
View raw message