Example usage for javax.servlet ServletContextAttributeListener attributeAdded

List of usage examples for javax.servlet ServletContextAttributeListener attributeAdded

Introduction

In this page you can find the example usage for javax.servlet ServletContextAttributeListener attributeAdded.

Prototype

default public void attributeAdded(ServletContextAttributeEvent event) 

Source Link

Document

Receives notification that an attribute has been added to the ServletContext.

Usage

From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.WebApplicationHandler.java

public synchronized void setContextAttribute(String name, Object value) {
    Object old = super.getContextAttribute(name);
    super.setContextAttribute(name, value);

    if (_contextAttributeListeners != null) {
        ServletContextAttributeEvent event = new ServletContextAttributeEvent(getServletContext(), name,
                old != null ? old : value);
        for (int i = 0; i < LazyList.size(_contextAttributeListeners); i++) {
            ServletContextAttributeListener l = (ServletContextAttributeListener) LazyList
                    .get(_contextAttributeListeners, i);
            if (old == null)
                l.attributeAdded(event);
            else if (value == null)
                l.attributeRemoved(event);
            else/*from ww w  .  j  ava  2 s . c  o  m*/
                l.attributeReplaced(event);
        }
    }
}

From source file:org.ireland.jnetty.webapp.ServletContextImpl.java

/**
 * Sets an application attribute.//from  w w w .  j  av  a 2  s.c  o m
 * 
 * @param name
 *            the name of the attribute
 * @param value
 *            the value of the attribute
 */
@Override
public void setAttribute(String name, Object value) {
    Object oldValue;

    synchronized (_attributes) {
        if (value != null)
            oldValue = _attributes.put(name, value);
        else
            oldValue = _attributes.remove(name);
    }

    // Call any listeners
    if (_applicationAttributeListeners != null) {
        ServletContextAttributeEvent event;

        if (oldValue != null)
            event = new ServletContextAttributeEvent(this, name, oldValue);
        else
            event = new ServletContextAttributeEvent(this, name, value);

        for (int i = 0; i < _applicationAttributeListeners.size(); i++) {
            ServletContextAttributeListener listener;

            Object objListener = _applicationAttributeListeners.get(i);
            listener = (ServletContextAttributeListener) objListener;

            try {
                if (oldValue != null)
                    listener.attributeReplaced(event);
                else
                    listener.attributeAdded(event);
            } catch (Exception e) {
                log(e.toString(), e);
            }
        }
    }
}