]> WPIA git - gigi.git/blob - lib/servlet-api/javax/servlet/http/HttpSessionBindingEvent.java
adding servlet api (from tomcat)
[gigi.git] / lib / servlet-api / javax / servlet / http / HttpSessionBindingEvent.java
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package javax.servlet.http;
19
20 /**
21  * Events of this type are either sent to an object that implements
22  * {@link HttpSessionBindingListener} when it is bound or unbound from a
23  * session, or to a {@link HttpSessionAttributeListener} that has been
24  * configured in the deployment descriptor when any attribute is bound, unbound
25  * or replaced in a session.
26  * <p>
27  * The session binds the object by a call to
28  * <code>HttpSession.setAttribute</code> and unbinds the object by a call to
29  * <code>HttpSession.removeAttribute</code>.
30  *
31  * @see HttpSession
32  * @see HttpSessionBindingListener
33  * @see HttpSessionAttributeListener
34  */
35 public class HttpSessionBindingEvent extends HttpSessionEvent {
36
37     private static final long serialVersionUID = 1L;
38
39     /* The name to which the object is being bound or unbound */
40     private final String name;
41
42     /* The object is being bound or unbound */
43     private final Object value;
44
45     /**
46      * Constructs an event that notifies an object that it has been bound to or
47      * unbound from a session. To receive the event, the object must implement
48      * {@link HttpSessionBindingListener}.
49      *
50      * @param session
51      *            the session to which the object is bound or unbound
52      * @param name
53      *            the name with which the object is bound or unbound
54      * @see #getName
55      * @see #getSession
56      */
57     public HttpSessionBindingEvent(HttpSession session, String name) {
58         super(session);
59         this.name = name;
60         this.value = null;
61     }
62
63     /**
64      * Constructs an event that notifies an object that it has been bound to or
65      * unbound from a session. To receive the event, the object must implement
66      * {@link HttpSessionBindingListener}.
67      *
68      * @param session
69      *            the session to which the object is bound or unbound
70      * @param name
71      *            the name with which the object is bound or unbound
72      * @see #getName
73      * @see #getSession
74      */
75     public HttpSessionBindingEvent(HttpSession session, String name,
76             Object value) {
77         super(session);
78         this.name = name;
79         this.value = value;
80     }
81
82     /** Return the session that changed. */
83     @Override
84     public HttpSession getSession() {
85         return super.getSession();
86     }
87
88     /**
89      * Returns the name with which the attribute is bound to or unbound from the
90      * session.
91      *
92      * @return a string specifying the name with which the object is bound to or
93      *         unbound from the session
94      */
95     public String getName() {
96         return name;
97     }
98
99     /**
100      * Returns the value of the attribute that has been added, removed or
101      * replaced. If the attribute was added (or bound), this is the value of the
102      * attribute. If the attribute was removed (or unbound), this is the value
103      * of the removed attribute. If the attribute was replaced, this is the old
104      * value of the attribute.
105      *
106      * @since 2.3
107      */
108     public Object getValue() {
109         return this.value;
110     }
111 }