Example usage for javax.servlet.http HttpSessionBindingListener valueUnbound

List of usage examples for javax.servlet.http HttpSessionBindingListener valueUnbound

Introduction

In this page you can find the example usage for javax.servlet.http HttpSessionBindingListener valueUnbound.

Prototype

default public void valueUnbound(HttpSessionBindingEvent event) 

Source Link

Document

Notifies the object that it is being unbound from a session and identifies the session.

Usage

From source file:org.ireland.jnetty.server.session.HttpSessionImpl.java

/**
 * Sets a session attribute. If the value is a listener, notify it of the objectModified. If the value has changed
 * mark the session as changed for persistent sessions.
 * //from  w  w w.j  a v a2  s .co m
 * @param name
 *            the name of the attribute
 * @param value
 *            the value of the attribute
 */
@Override
public void setAttribute(String name, Object value) {
    if (!_isValid)
        throw new IllegalStateException(
                this + ": can't call setAttribute(String, Object) when session is no longer valid.");

    Object oldValue;

    if (value != null && !(value instanceof Serializable) && debug) {
        log.debug(this + " attribute '" + name + "' value is non-serializable type '"
                + value.getClass().getName() + "'");
    }

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

    if (oldValue instanceof HttpSessionBindingListener) {
        HttpSessionBindingListener listener;
        listener = (HttpSessionBindingListener) oldValue;

        listener.valueUnbound(new HttpSessionBindingEvent(HttpSessionImpl.this, name, oldValue));
    }

    if (value instanceof HttpSessionBindingListener) {
        HttpSessionBindingListener listener;
        listener = (HttpSessionBindingListener) value;

        listener.valueBound(new HttpSessionBindingEvent(HttpSessionImpl.this, name, value));
    }

    // Notify the attribute listeners
    ArrayList listeners = _manager.getAttributeListeners();

    if (listeners != null && listeners.size() > 0) {
        HttpSessionBindingEvent event;

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

        for (int i = 0; i < listeners.size(); i++) {
            HttpSessionAttributeListener listener;
            listener = (HttpSessionAttributeListener) listeners.get(i);

            if (oldValue != null)
                listener.attributeReplaced(event);
            else
                listener.attributeAdded(event);
        }
    }
}

From source file:org.ireland.jnetty.server.session.HttpSessionImpl.java

/**
 * Notify any Attribute unbound listeners.
 *///w ww . j a  va 2 s. c  o  m
private void notifyAttributeRemoved(String name, Object oldValue) {
    if (oldValue == null)
        return;

    if (oldValue instanceof HttpSessionBindingListener) {
        HttpSessionBindingListener listener;
        listener = (HttpSessionBindingListener) oldValue;

        listener.valueUnbound(new HttpSessionBindingEvent(this, name, oldValue));
    }

    // Notify the attributes listeners
    ArrayList listeners = _manager.getAttributeListeners();
    if (listeners != null) {
        HttpSessionBindingEvent event;

        event = new HttpSessionBindingEvent(this, name, oldValue);

        for (int i = 0; i < listeners.size(); i++) {
            HttpSessionAttributeListener listener;
            listener = (HttpSessionAttributeListener) listeners.get(i);

            listener.attributeRemoved(event);
        }
    }
}

From source file:org.ireland.jnetty.server.session.HttpSessionImpl.java

/**
 * Notify any value unbound listeners.// w ww. j  a va2 s . c o m
 */
private void notifyValueUnbound(String name, Object oldValue) {
    if (oldValue == null)
        return;

    if (oldValue instanceof HttpSessionBindingListener) {
        HttpSessionBindingListener listener;
        listener = (HttpSessionBindingListener) oldValue;

        listener.valueUnbound(new HttpSessionBindingEvent(this, name, oldValue));
    }

    // Notify the attributes listeners
    ArrayList listeners = _manager.getAttributeListeners();
    if (listeners != null) {
        HttpSessionBindingEvent event;

        event = new HttpSessionBindingEvent(this, name, oldValue);

        for (int i = 0; i < listeners.size(); i++) {
            HttpSessionAttributeListener listener;
            listener = (HttpSessionAttributeListener) listeners.get(i);

            listener.attributeRemoved(event);
        }
    }
}