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 2020/09/09 09:02:30 UTC

[myfaces] branch master updated: MYFACES-4358

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 834a79a  MYFACES-4358
834a79a is described below

commit 834a79ad3fac3fb73a28beeb05828bc2c743708e
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Wed Sep 9 11:02:21 2020 +0200

    MYFACES-4358
---
 .../java/org/apache/myfaces/el/FacesELContext.java | 68 ++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/impl/src/main/java/org/apache/myfaces/el/FacesELContext.java b/impl/src/main/java/org/apache/myfaces/el/FacesELContext.java
index bcb6c35..f7c7996 100644
--- a/impl/src/main/java/org/apache/myfaces/el/FacesELContext.java
+++ b/impl/src/main/java/org/apache/myfaces/el/FacesELContext.java
@@ -18,8 +18,12 @@
  */
 package org.apache.myfaces.el;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import javax.el.ELContext;
 import javax.el.ELResolver;
+import javax.el.EvaluationListener;
 import javax.el.FunctionMapper;
 import javax.el.VariableMapper;
 import javax.faces.context.FacesContext;
@@ -35,6 +39,9 @@ public class FacesELContext extends ELContext
     private FunctionMapper _functionMapper;
     private VariableMapper _variableMapper;
 
+    // overwrite to optimize access and reduce created objects
+    private List<EvaluationListener> listeners;
+
     public FacesELContext(ELResolver elResolver, FacesContext facesContext)
     {
         this._elResolver = elResolver;
@@ -69,4 +76,65 @@ public class FacesELContext extends ELContext
         return _elResolver;
     }
 
+    @Override
+    public void addEvaluationListener(EvaluationListener listener)
+    {
+        if (listeners == null)
+        {
+            listeners = new ArrayList<>();
+        }
+
+        listeners.add(listener);
+    }
+
+    @Override
+    public List<EvaluationListener> getEvaluationListeners()
+    {
+        return listeners == null ? Collections.emptyList() : listeners;
+    }
+
+    @Override
+    public void notifyBeforeEvaluation(String expression)
+    {
+        if (listeners == null)
+        {
+            return;
+        }
+
+        for (int i = 0; i < listeners.size(); i++)
+        {
+            EvaluationListener listener = listeners.get(i);
+            listener.beforeEvaluation(this, expression);
+        }
+    }
+
+    @Override
+    public void notifyAfterEvaluation(String expression)
+    {
+        if (listeners == null)
+        {
+            return;
+        }
+
+        for (int i = 0; i < listeners.size(); i++)
+        {
+            EvaluationListener listener = listeners.get(i);
+            listener.afterEvaluation(this, expression);
+        }
+    }
+
+    @Override
+    public void notifyPropertyResolved(Object base, Object property)
+    {
+        if (listeners == null)
+        {
+            return;
+        }
+
+        for (int i = 0; i < listeners.size(); i++)
+        {
+            EvaluationListener listener = listeners.get(i);
+            listener.propertyResolved(this, base, property);
+        }
+    }
 }