Skip to main content
Last updated September 30, 2011 19:40, by Kin-man Chung
Feedicon  

Expression Evaluation Listener

According to the CDI spec, there is a need for the users to be notified when an EL expression evaluation starts and ends. My tentative proposal:

EvaluationEvent.java ==


 package javax.el;

 /**
  * An event associated with the evaluation of EL expressions.
  *
  * @since EL 3.0
  */

 public class EvaluationEvent extends java.util.EventObject {

    private String expression;

    /**
     * Constructor
     *
     * @param context The <code>ELContext</code> used in the evaluation of the
     *     expression.
     * @param expression The original expression String
     */
    public EvaluationEvent(ELContext context, String expression) {
        super(context);
        this.expression = expression;
    }

    /**
     * Retruns the <code>ELContext</code> used in the evaluation of the
     * expression.
     *
     * @return The ELContext
     */
    public ELContext getELContext() {
        return (ELContext) getSource();
    }

    /**
     * Returns the original expression String
     *
     * @return The original expression String
     */
    public String getExpressionString() {
        return expression;
    }
 }

EvaluationListener.java

 package javax.el;

 interface EvaluationListener extends java.util.EventListener {

    /**
     * Receives notification before an EL expression is evaluated
     */
    void beforeEvaluation(EvaluationEvent ee);

    /**
     * Receives notification before an EL expression is evaluated
     */
    void afterEvaluation(EvaluationEvent ee);

 }

ELManager.java


    ...
    /**
     * Register a listener.
     *
     * @param listener The listener to be added.
     */
    public <T extends java.util.EventListener> void addListener(T listener) {
        getELContext().addListener(listener);
    }

ELContext.java


    ...
    /**
     * Registers a listener to the ELContext.
     *
     * @param listener The listener to be added.
     */
    public <T extends EventListener> void addListener(T listener) {
        listeners.add(listener);
    }

    /**
     * Returns the list of registered listeners.
     * @return The list of registered listeners.
     */
    public List<EventListener> getlisteners() {
        return listeners;
    }

    private transient List<EventListener> listeners =
        new ArrayList<EventListener>();

 
 
Close
loading
Please Confirm
Close