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 2021/03/27 15:29:37 UTC

[myfaces] branch master updated: Faces 4.0: Add FacesContext#getLifecycle()

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 224d914  Faces 4.0: Add FacesContext#getLifecycle()
224d914 is described below

commit 224d9141af7b5a082c77b2e4eb3235adcf4c0106
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Sat Mar 27 16:29:30 2021 +0100

    Faces 4.0: Add FacesContext#getLifecycle()
---
 .../java/jakarta/faces/context/FacesContext.java   |   8 +
 .../jakarta/faces/context/FacesContextWrapper.java |  11 +
 .../myfaces/context/FacesContextFactoryImpl.java   |   2 +-
 .../myfaces/context/FacesContextWrapper.java       | 233 ---------------------
 .../myfaces/context/servlet/FacesContextImpl.java  |  15 +-
 .../context/servlet/StartupFacesContextImpl.java   |   7 +
 .../apache/myfaces/test/mock/MockFacesContext.java |   6 +
 7 files changed, 46 insertions(+), 236 deletions(-)

diff --git a/api/src/main/java/jakarta/faces/context/FacesContext.java b/api/src/main/java/jakarta/faces/context/FacesContext.java
index 3c19d6f..4ebb09a 100755
--- a/api/src/main/java/jakarta/faces/context/FacesContext.java
+++ b/api/src/main/java/jakarta/faces/context/FacesContext.java
@@ -30,6 +30,7 @@ import jakarta.faces.application.ProjectStage;
 import jakarta.faces.component.UINamingContainer;
 import jakarta.faces.component.UIViewRoot;
 import jakarta.faces.event.PhaseId;
+import jakarta.faces.lifecycle.Lifecycle;
 import jakarta.faces.render.RenderKit;
 
 /**
@@ -473,4 +474,11 @@ public abstract class FacesContext
         }
         return ctx.getNamingContainerSeparatorChar();
     }
+    
+    /**
+     * 
+     * @return the current Lifecycle
+     * @since 4.0
+     */
+    public abstract Lifecycle getLifecycle();
 }
diff --git a/api/src/main/java/jakarta/faces/context/FacesContextWrapper.java b/api/src/main/java/jakarta/faces/context/FacesContextWrapper.java
index 9cae031..6f7c968 100644
--- a/api/src/main/java/jakarta/faces/context/FacesContextWrapper.java
+++ b/api/src/main/java/jakarta/faces/context/FacesContextWrapper.java
@@ -30,6 +30,7 @@ import jakarta.faces.application.ProjectStage;
 import jakarta.faces.application.FacesMessage.Severity;
 import jakarta.faces.component.UIViewRoot;
 import jakarta.faces.event.PhaseId;
+import jakarta.faces.lifecycle.Lifecycle;
 import jakarta.faces.render.RenderKit;
 
 /**
@@ -283,4 +284,14 @@ public abstract class FacesContextWrapper extends FacesContext implements FacesW
         return getWrapped().getResourceLibraryContracts();
     }
 
+    /**
+     * 
+     * @return
+     * @since 4.0
+     */
+    @Override
+    public Lifecycle getLifecycle()
+    {
+        return getWrapped().getLifecycle();
+    }
 }
diff --git a/impl/src/main/java/org/apache/myfaces/context/FacesContextFactoryImpl.java b/impl/src/main/java/org/apache/myfaces/context/FacesContextFactoryImpl.java
index c2a6024..275c001 100755
--- a/impl/src/main/java/org/apache/myfaces/context/FacesContextFactoryImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/context/FacesContextFactoryImpl.java
@@ -154,7 +154,7 @@ public class FacesContextFactoryImpl extends FacesContextFactory implements Rele
         }
 
         FacesContext facesContext = new FacesContextImpl(externalContext, defaultExternalContext, this,
-            _applicationFactory, _renderKitFactory, _partialViewContextFactory);
+            _applicationFactory, _renderKitFactory, _partialViewContextFactory, lifecycle);
         facesContext.setExceptionHandler(_exceptionHandlerFactory.getExceptionHandler());
 
         return facesContext;
diff --git a/impl/src/main/java/org/apache/myfaces/context/FacesContextWrapper.java b/impl/src/main/java/org/apache/myfaces/context/FacesContextWrapper.java
deleted file mode 100755
index c48ab3b..0000000
--- a/impl/src/main/java/org/apache/myfaces/context/FacesContextWrapper.java
+++ /dev/null
@@ -1,233 +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.myfaces.context;
-
-import jakarta.el.ELContext;
-import jakarta.faces.application.Application;
-import jakarta.faces.application.FacesMessage;
-import jakarta.faces.application.FacesMessage.Severity;
-import jakarta.faces.component.UIViewRoot;
-import jakarta.faces.context.ExceptionHandler;
-import jakarta.faces.context.ExternalContext;
-import jakarta.faces.context.FacesContext;
-import jakarta.faces.context.PartialViewContext;
-import jakarta.faces.context.ResponseStream;
-import jakarta.faces.context.ResponseWriter;
-import jakarta.faces.event.PhaseId;
-import jakarta.faces.render.RenderKit;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Convenient class to wrap the current FacesContext.
- * 
- * @author Manfred Geiler (latest modification by $Author$)
- * @author Anton Koinov
- * @version $Revision$ $Date$
- */
-public class FacesContextWrapper extends FacesContext
-{
-    // ~ Instance fields ----------------------------------------------------------------------------
-
-    private FacesContext _facesContext;
-
-    // ~ Constructors -------------------------------------------------------------------------------
-
-    public FacesContextWrapper(FacesContext facesContext)
-    {
-        _facesContext = facesContext;
-    }
-
-    // ~ Methods ------------------------------------------------------------------------------------
-
-    @Override
-    public Application getApplication()
-    {
-        return _facesContext.getApplication();
-    }
-
-    @Override
-    public Map<Object,Object> getAttributes()
-    {
-        return _facesContext.getAttributes();
-    }
-
-    @Override
-    public Iterator<String> getClientIdsWithMessages()
-    {
-        return _facesContext.getClientIdsWithMessages();
-    }
-
-    @Override
-    public PhaseId getCurrentPhaseId()
-    {
-        return _facesContext.getCurrentPhaseId();
-    }
-    
-    @Override
-    public ExceptionHandler getExceptionHandler()
-    {
-        return _facesContext.getExceptionHandler();
-    }
-
-    @Override
-    public ExternalContext getExternalContext()
-    {
-        return _facesContext.getExternalContext();
-    }
-
-    @Override
-    public Severity getMaximumSeverity()
-    {
-        return _facesContext.getMaximumSeverity();
-    }
-
-    @Override
-    public List<FacesMessage> getMessageList()
-    {
-        return _facesContext.getMessageList();
-    }
-
-    @Override
-    public List<FacesMessage> getMessageList(String clientId)
-    {
-        return _facesContext.getMessageList(clientId);
-    }
-
-    @Override
-    public Iterator<FacesMessage> getMessages()
-    {
-        return _facesContext.getMessages();
-    }
-
-    @Override
-    public Iterator<FacesMessage> getMessages(String clientId)
-    {
-        return _facesContext.getMessages(clientId);
-    }
-
-    @Override
-    public PartialViewContext getPartialViewContext()
-    {
-        return _facesContext.getPartialViewContext();
-    }
-
-    @Override
-    public RenderKit getRenderKit()
-    {
-        return _facesContext.getRenderKit();
-    }
-
-    @Override
-    public boolean getRenderResponse()
-    {
-        return _facesContext.getRenderResponse();
-    }
-
-    @Override
-    public boolean getResponseComplete()
-    {
-        return _facesContext.getResponseComplete();
-    }
-
-    @Override
-    public void setExceptionHandler(ExceptionHandler exceptionHandler)
-    {
-        _facesContext.setExceptionHandler(exceptionHandler);
-    }
-
-    @Override
-    public void setResponseStream(ResponseStream responsestream)
-    {
-        _facesContext.setResponseStream(responsestream);
-    }
-
-    @Override
-    public ResponseStream getResponseStream()
-    {
-        return _facesContext.getResponseStream();
-    }
-
-    @Override
-    public void setResponseWriter(ResponseWriter responsewriter)
-    {
-        _facesContext.setResponseWriter(responsewriter);
-    }
-
-    @Override
-    public ResponseWriter getResponseWriter()
-    {
-        return _facesContext.getResponseWriter();
-    }
-
-    @Override
-    public void setViewRoot(UIViewRoot viewRoot)
-    {
-        _facesContext.setViewRoot(viewRoot);
-    }
-
-    @Override
-    public UIViewRoot getViewRoot()
-    {
-        return _facesContext.getViewRoot();
-    }
-    
-    @Override
-    public boolean isPostback()
-    {
-        return _facesContext.isPostback();
-    }
-
-    @Override
-    public void addMessage(String clientId, FacesMessage message)
-    {
-        _facesContext.addMessage(clientId, message);
-    }
-
-    @Override
-    public void release()
-    {
-        _facesContext.release();
-    }
-
-    @Override
-    public void renderResponse()
-    {
-        _facesContext.renderResponse();
-    }
-
-    @Override
-    public void responseComplete()
-    {
-        _facesContext.responseComplete();
-    }
-    
-    @Override
-    public ELContext getELContext()
-    {
-        return _facesContext.getELContext();
-    }
-    
-    @Override
-    public void setCurrentPhaseId(PhaseId currentPhaseId)
-    {
-        _facesContext.setCurrentPhaseId(currentPhaseId);
-    }
-}
diff --git a/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java b/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java
index 47a25e0..325aa8e 100755
--- a/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/context/servlet/FacesContextImpl.java
@@ -35,6 +35,7 @@ import jakarta.faces.context.PartialViewContextFactory;
 import jakarta.faces.context.ResponseStream;
 import jakarta.faces.context.ResponseWriter;
 import jakarta.faces.event.PhaseId;
+import jakarta.faces.lifecycle.Lifecycle;
 import jakarta.faces.render.RenderKit;
 import jakarta.faces.render.RenderKitFactory;
 import jakarta.servlet.ServletContext;
@@ -71,6 +72,7 @@ public class FacesContextImpl extends FacesContextImplBase
     
     private PartialViewContextFactory _partialViewContextFactory = null;
     private RenderKitFactory _renderKitFactory = null;
+    private Lifecycle _lifecycle = null;
 
     // ~ Constructors -------------------------------------------------------------------------------
     
@@ -114,7 +116,8 @@ public class FacesContextImpl extends FacesContextImplBase
             final ReleasableFacesContextFactory facesContextFactory,
             final ApplicationFactory applicationFactory,
             final RenderKitFactory renderKitFactory,
-            final PartialViewContextFactory partialViewContextFactory)
+            final PartialViewContextFactory partialViewContextFactory,
+            final Lifecycle lifecycle)
     {
         // setCurrentInstance is called in constructor of super class
         super(externalContext, defaultExternalContext, applicationFactory, 
@@ -123,6 +126,7 @@ public class FacesContextImpl extends FacesContextImplBase
         _facesContextFactory = facesContextFactory;
         _renderKitFactory = renderKitFactory;
         _partialViewContextFactory = partialViewContextFactory;
+        _lifecycle = lifecycle;
     }
 
     // ~ Methods ------------------------------------------------------------------------------------
@@ -145,6 +149,7 @@ public class FacesContextImpl extends FacesContextImplBase
         _partialViewContext = null;
         _renderKitFactory = null;
         _partialViewContextFactory = null;
+        _lifecycle = null;
 
         if (_facesContextFactory != null)
         {
@@ -416,5 +421,11 @@ public class FacesContextImpl extends FacesContextImplBase
         
         return _validationFailed;
     }
-    
+
+    @Override
+    public Lifecycle getLifecycle()
+    {
+        assertNotReleased();
+        return _lifecycle;
+    }
 }
diff --git a/impl/src/main/java/org/apache/myfaces/context/servlet/StartupFacesContextImpl.java b/impl/src/main/java/org/apache/myfaces/context/servlet/StartupFacesContextImpl.java
index a1c84e8..a182fea 100644
--- a/impl/src/main/java/org/apache/myfaces/context/servlet/StartupFacesContextImpl.java
+++ b/impl/src/main/java/org/apache/myfaces/context/servlet/StartupFacesContextImpl.java
@@ -28,6 +28,7 @@ import jakarta.faces.context.PartialViewContext;
 import jakarta.faces.context.ResponseStream;
 import jakarta.faces.context.ResponseWriter;
 import jakarta.faces.event.PhaseId;
+import jakarta.faces.lifecycle.Lifecycle;
 
 /**
  * A FacesContext implementation which will be set as the current instance
@@ -230,5 +231,11 @@ public class StartupFacesContextImpl extends FacesContextImplBase
     {
         return _startup ? "startup" : "shutdown";
     }
+
+    @Override
+    public Lifecycle getLifecycle()
+    {
+        return null;
+    }
     
 }
diff --git a/test/src/main/java/org/apache/myfaces/test/mock/MockFacesContext.java b/test/src/main/java/org/apache/myfaces/test/mock/MockFacesContext.java
index b594e88..fc2da94 100644
--- a/test/src/main/java/org/apache/myfaces/test/mock/MockFacesContext.java
+++ b/test/src/main/java/org/apache/myfaces/test/mock/MockFacesContext.java
@@ -118,4 +118,10 @@ public class MockFacesContext extends MockFacesContext20
         super.release();
         _released = true;
     }
+
+    @Override
+    public Lifecycle getLifecycle()
+    {
+        return null;
+    }
 }