001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements. See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership. The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied. See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019
020 package javax.servlet.http;
021
022 /**
023 * Events of this type are either sent to an object that implements
024 * {@link HttpSessionBindingListener} when it is bound or
025 * unbound from a session, or to a {@link HttpSessionAttributeListener}
026 * that has been configured in the deployment descriptor when any attribute is
027 * bound, unbound or replaced in a session.
028 * <p/>
029 * <p>The session binds the object by a call to
030 * <code>HttpSession.setAttribute</code> and unbinds the object
031 * by a call to <code>HttpSession.removeAttribute</code>.
032 *
033 * @version $Rev: 788194 $ $Date: 2009-06-24 18:05:48 -0400 (Wed, 24 Jun 2009) $
034 * @see HttpSessionAttributeListener
035 * @see HttpSession
036 * @see HttpSessionBindingListener
037 */
038 public class HttpSessionBindingEvent extends HttpSessionEvent {
039
040 /* The name to which the object is being bound or unbound */
041 private final String name;
042
043 /* The object is being bound or unbound */
044 private final Object value;
045
046 /**
047 * Constructs an event that notifies an object that it
048 * has been bound to or unbound from a session.
049 * To receive the event, the object must implement
050 * {@link HttpSessionBindingListener}.
051 *
052 * @param session the session to which the object is bound or unbound
053 * @param name the name with which the object is bound or unbound
054 * @see #getName
055 * @see #getSession
056 */
057 public HttpSessionBindingEvent(HttpSession session, String name) {
058 super(session);
059 this.name = name;
060 value = null;
061 }
062
063 /**
064 * Constructs an event that notifies an object that it
065 * has been bound to or unbound from a session.
066 * To receive the event, the object must implement
067 * {@link HttpSessionBindingListener}.
068 *
069 * @param session the session to which the object is bound or unbound
070 * @param name the name with which the object is bound or unbound
071 * @see #getName
072 * @see #getSession
073 */
074 public HttpSessionBindingEvent(HttpSession session, String name, Object value) {
075 super(session);
076 this.name = name;
077 this.value = value;
078 }
079
080 /**
081 * Return the session that changed.
082 */
083 public HttpSession getSession() {
084 return super.getSession();
085 }
086
087 /**
088 * Returns the name with which the attribute is bound to or
089 * unbound from the session.
090 *
091 * @return a string specifying the name with which
092 * the object is bound to or unbound from
093 * the session
094 */
095 public String getName() {
096 return name;
097 }
098
099 /**
100 * Returns the value of the attribute that has been added, removed or replaced.
101 * If the attribute was added (or bound), this is the value of the attribute. If the attribute was
102 * removed (or unbound), this is the value of the removed attribute. If the attribute was replaced, this
103 * is the old value of the attribute.
104 *
105 * @since 2.3
106 */
107 public Object getValue() {
108 return this.value;
109 }
110
111 }
112
113
114
115
116
117
118